diff options
author | Christian Eggers <ceggers@arri.de> | 2020-11-15 20:25:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-11-15 20:26:46 +0100 |
commit | 89f063b900edf8b38c9dc05953887cf09b121378 (patch) | |
tree | cac0a171637204bafcb92939de84c94221b2fd51 | |
parent | 64981b4c8e88812c322bee3832f1d421ff670ed5 (diff) | |
download | busybox-w32-89f063b900edf8b38c9dc05953887cf09b121378.tar.gz busybox-w32-89f063b900edf8b38c9dc05953887cf09b121378.tar.bz2 busybox-w32-89f063b900edf8b38c9dc05953887cf09b121378.zip |
chrt: support for musl C library
musl "implements" several sched_xxx() functions by returning ENOSYS. As
an alternative, either pthread_(g|s)etschedparam() or direct syscalls
can be used.
References: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/schedutils/chrt.c?id=fcc3078754291d2f5121797eb91b364f8e24b2f1
References: http://git.musl-libc.org/cgit/musl/commit/src/sched/sched_setscheduler.c?id=1e21e78bf7a5c24c217446d8760be7b7188711c2
Signed-off-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/chrt.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/util-linux/chrt.c b/util-linux/chrt.c index 4dd78dabf..6e8f66741 100644 --- a/util-linux/chrt.c +++ b/util-linux/chrt.c | |||
@@ -39,6 +39,17 @@ | |||
39 | # define SCHED_IDLE 5 | 39 | # define SCHED_IDLE 5 |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | //musl has no __MUSL__ or similar define to check for, | ||
43 | //but its <sys/types.h> has these lines: | ||
44 | // #define __NEED_fsblkcnt_t | ||
45 | // #define __NEED_fsfilcnt_t | ||
46 | #if defined(__linux__) && defined(__NEED_fsblkcnt_t) && defined(__NEED_fsfilcnt_t) | ||
47 | # define LIBC_IS_MUSL 1 | ||
48 | # include <sys/syscall.h> | ||
49 | #else | ||
50 | # define LIBC_IS_MUSL 0 | ||
51 | #endif | ||
52 | |||
42 | static const char *policy_name(int pol) | 53 | static const char *policy_name(int pol) |
43 | { | 54 | { |
44 | if (pol > 6) | 55 | if (pol > 6) |
@@ -85,6 +96,7 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) | |||
85 | char *priority = priority; /* for compiler */ | 96 | char *priority = priority; /* for compiler */ |
86 | const char *current_new; | 97 | const char *current_new; |
87 | int policy = SCHED_RR; | 98 | int policy = SCHED_RR; |
99 | int ret; | ||
88 | 100 | ||
89 | opt = getopt32(argv, "^" | 101 | opt = getopt32(argv, "^" |
90 | "+" "mprfobi" | 102 | "+" "mprfobi" |
@@ -132,7 +144,15 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) | |||
132 | if (opt & OPT_p) { | 144 | if (opt & OPT_p) { |
133 | int pol; | 145 | int pol; |
134 | print_rt_info: | 146 | print_rt_info: |
147 | #if LIBC_IS_MUSL | ||
148 | /* musl libc returns ENOSYS for its sched_getscheduler library | ||
149 | * function, because the sched_getscheduler Linux kernel system call | ||
150 | * does not conform to Posix; so we use the system call directly | ||
151 | */ | ||
152 | pol = syscall(SYS_sched_getscheduler, pid); | ||
153 | #else | ||
135 | pol = sched_getscheduler(pid); | 154 | pol = sched_getscheduler(pid); |
155 | #endif | ||
136 | if (pol < 0) | 156 | if (pol < 0) |
137 | bb_perror_msg_and_die("can't %cet pid %u's policy", 'g', (int)pid); | 157 | bb_perror_msg_and_die("can't %cet pid %u's policy", 'g', (int)pid); |
138 | #ifdef SCHED_RESET_ON_FORK | 158 | #ifdef SCHED_RESET_ON_FORK |
@@ -149,7 +169,12 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) | |||
149 | printf("pid %u's %s scheduling policy: SCHED_%s\n", | 169 | printf("pid %u's %s scheduling policy: SCHED_%s\n", |
150 | pid, current_new, policy_name(pol) | 170 | pid, current_new, policy_name(pol) |
151 | ); | 171 | ); |
152 | if (sched_getparam(pid, &sp)) | 172 | #if LIBC_IS_MUSL |
173 | ret = syscall(SYS_sched_getparam, pid, &sp); | ||
174 | #else | ||
175 | ret = sched_getparam(pid, &sp); | ||
176 | #endif | ||
177 | if (ret) | ||
153 | bb_perror_msg_and_die("can't get pid %u's attributes", (int)pid); | 178 | bb_perror_msg_and_die("can't get pid %u's attributes", (int)pid); |
154 | printf("pid %u's %s scheduling priority: %d\n", | 179 | printf("pid %u's %s scheduling priority: %d\n", |
155 | (int)pid, current_new, sp.sched_priority | 180 | (int)pid, current_new, sp.sched_priority |
@@ -168,7 +193,12 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) | |||
168 | sched_get_priority_min(policy), sched_get_priority_max(policy) | 193 | sched_get_priority_min(policy), sched_get_priority_max(policy) |
169 | ); | 194 | ); |
170 | 195 | ||
171 | if (sched_setscheduler(pid, policy, &sp) < 0) | 196 | #if LIBC_IS_MUSL |
197 | ret = syscall(SYS_sched_setscheduler, pid, policy, &sp); | ||
198 | #else | ||
199 | ret = sched_setscheduler(pid, policy, &sp); | ||
200 | #endif | ||
201 | if (ret) | ||
172 | bb_perror_msg_and_die("can't %cet pid %u's policy", 's', (int)pid); | 202 | bb_perror_msg_and_die("can't %cet pid %u's policy", 's', (int)pid); |
173 | 203 | ||
174 | if (!argv[0]) /* "-p PRIO PID [...]" */ | 204 | if (!argv[0]) /* "-p PRIO PID [...]" */ |