aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-04-17 12:02:10 +0100
committerRon Yorston <rmy@pobox.com>2019-04-17 12:02:10 +0100
commite4bc2cb29c5465cbec2dec1ba3b325139007d03a (patch)
tree3556d0a31ca4f75807345aef3f8a377bebf725f7 /util-linux
parent9752b1d082e6bdb51f8fbec5e751087a687c0062 (diff)
parent1d37186fe2361f80c821e334cc61f41e2f4eeb72 (diff)
downloadbusybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.tar.gz
busybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.tar.bz2
busybox-w32-e4bc2cb29c5465cbec2dec1ba3b325139007d03a.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/chrt.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/util-linux/chrt.c b/util-linux/chrt.c
index 28e65457c..4dd78dabf 100644
--- a/util-linux/chrt.c
+++ b/util-linux/chrt.c
@@ -17,16 +17,16 @@
17//kbuild:lib-$(CONFIG_CHRT) += chrt.o 17//kbuild:lib-$(CONFIG_CHRT) += chrt.o
18 18
19//usage:#define chrt_trivial_usage 19//usage:#define chrt_trivial_usage
20//usage: "[-prfombi] [PRIO] [PID | PROG ARGS]" 20//usage: "-m | -p [PRIO] PID | [-rfobi] PRIO PROG [ARGS]"
21//usage:#define chrt_full_usage "\n\n" 21//usage:#define chrt_full_usage "\n\n"
22//usage: "Change scheduling priority and class for a process\n" 22//usage: "Change scheduling priority and class for a process\n"
23//usage: "\n -m Show min/max priorities"
23//usage: "\n -p Operate on PID" 24//usage: "\n -p Operate on PID"
24//usage: "\n -r Set SCHED_RR class" 25//usage: "\n -r Set SCHED_RR class"
25//usage: "\n -f Set SCHED_FIFO class" 26//usage: "\n -f Set SCHED_FIFO class"
26//usage: "\n -o Set SCHED_OTHER class" 27//usage: "\n -o Set SCHED_OTHER class"
27//usage: "\n -b Set SCHED_BATCH class" 28//usage: "\n -b Set SCHED_BATCH class"
28//usage: "\n -i Set SCHED_IDLE class" 29//usage: "\n -i Set SCHED_IDLE class"
29//usage: "\n -m Show min/max priorities"
30//usage: 30//usage:
31//usage:#define chrt_example_usage 31//usage:#define chrt_example_usage
32//usage: "$ chrt -r 4 sleep 900; x=$!\n" 32//usage: "$ chrt -r 4 sleep 900; x=$!\n"
@@ -39,28 +39,32 @@
39# define SCHED_IDLE 5 39# define SCHED_IDLE 5
40#endif 40#endif
41 41
42static const struct { 42static const char *policy_name(int pol)
43 char name[sizeof("SCHED_OTHER")]; 43{
44} policies[] = { 44 if (pol > 6)
45 { "SCHED_OTHER" }, /* 0:SCHED_OTHER */ 45 return utoa(pol);
46 { "SCHED_FIFO" }, /* 1:SCHED_FIFO */ 46 return nth_string(
47 { "SCHED_RR" }, /* 2:SCHED_RR */ 47 "OTHER" "\0" /* 0:SCHED_OTHER */
48 { "SCHED_BATCH" }, /* 3:SCHED_BATCH */ 48 "FIFO" "\0" /* 1:SCHED_FIFO */
49 { "" }, /* 4:SCHED_ISO */ 49 "RR" "\0" /* 2:SCHED_RR */
50 { "SCHED_IDLE" }, /* 5:SCHED_IDLE */ 50 "BATCH" "\0" /* 3:SCHED_BATCH */
51 /* 6:SCHED_DEADLINE */ 51 "ISO" "\0" /* 4:SCHED_ISO */
52}; 52 "IDLE" "\0" /* 5:SCHED_IDLE */
53 "DEADLINE", /* 6:SCHED_DEADLINE */
54 pol
55 );
56}
53 57
54static void show_min_max(int pol) 58static void show_min_max(int pol)
55{ 59{
56 const char *fmt = "%s min/max priority\t: %u/%u\n"; 60 const char *fmt = "SCHED_%s min/max priority\t: %u/%u\n";
57 int max, min; 61 int max, min;
58 62
59 max = sched_get_priority_max(pol); 63 max = sched_get_priority_max(pol);
60 min = sched_get_priority_min(pol); 64 min = sched_get_priority_min(pol);
61 if ((max|min) < 0) 65 if ((max|min) < 0)
62 fmt = "%s not supported\n"; 66 fmt = "SCHED_%s not supported\n";
63 printf(fmt, policies[pol].name, min, max); 67 printf(fmt, policy_name(pol), min, max);
64} 68}
65 69
66#define OPT_m (1<<0) 70#define OPT_m (1<<0)
@@ -112,11 +116,11 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
112 bb_show_usage(); 116 bb_show_usage();
113 if (opt & OPT_p) { 117 if (opt & OPT_p) {
114 pid_str = *argv++; 118 pid_str = *argv++;
115 if (*argv) { /* "-p <priority> <pid> [...]" */ 119 if (*argv) { /* "-p PRIO PID [...]" */
116 priority = pid_str; 120 priority = pid_str;
117 pid_str = *argv; 121 pid_str = *argv;
118 } 122 }
119 /* else "-p <pid>", and *argv == NULL */ 123 /* else "-p PID", and *argv == NULL */
120 pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); 124 pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1);
121 } else { 125 } else {
122 priority = *argv++; 126 priority = *argv++;
@@ -130,16 +134,29 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
130 print_rt_info: 134 print_rt_info:
131 pol = sched_getscheduler(pid); 135 pol = sched_getscheduler(pid);
132 if (pol < 0) 136 if (pol < 0)
133 bb_perror_msg_and_die("can't %cet pid %d's policy", 'g', (int)pid); 137 bb_perror_msg_and_die("can't %cet pid %u's policy", 'g', (int)pid);
134 printf("pid %d's %s scheduling policy: %s\n", 138#ifdef SCHED_RESET_ON_FORK
135 pid, current_new, policies[pol].name); 139 /* "Since Linux 2.6.32, the SCHED_RESET_ON_FORK flag
140 * can be ORed in policy when calling sched_setscheduler().
141 * As a result of including this flag, children created by
142 * fork(2) do not inherit privileged scheduling policies"
143 *
144 * This bit is also returned by sched_getscheduler()!
145 * (TODO: do we want to show it?)
146 */
147 pol &= ~SCHED_RESET_ON_FORK;
148#endif
149 printf("pid %u's %s scheduling policy: SCHED_%s\n",
150 pid, current_new, policy_name(pol)
151 );
136 if (sched_getparam(pid, &sp)) 152 if (sched_getparam(pid, &sp))
137 bb_perror_msg_and_die("can't get pid %d's attributes", (int)pid); 153 bb_perror_msg_and_die("can't get pid %u's attributes", (int)pid);
138 printf("pid %d's %s scheduling priority: %d\n", 154 printf("pid %u's %s scheduling priority: %d\n",
139 (int)pid, current_new, sp.sched_priority); 155 (int)pid, current_new, sp.sched_priority
156 );
140 if (!*argv) { 157 if (!*argv) {
141 /* Either it was just "-p <pid>", 158 /* Either it was just "-p PID",
142 * or it was "-p <priority> <pid>" and we came here 159 * or it was "-p PRIO PID" and we came here
143 * for the second time (see goto below) */ 160 * for the second time (see goto below) */
144 return EXIT_SUCCESS; 161 return EXIT_SUCCESS;
145 } 162 }
@@ -152,9 +169,9 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
152 ); 169 );
153 170
154 if (sched_setscheduler(pid, policy, &sp) < 0) 171 if (sched_setscheduler(pid, policy, &sp) < 0)
155 bb_perror_msg_and_die("can't %cet pid %d's policy", 's', (int)pid); 172 bb_perror_msg_and_die("can't %cet pid %u's policy", 's', (int)pid);
156 173
157 if (!argv[0]) /* "-p <priority> <pid> [...]" */ 174 if (!argv[0]) /* "-p PRIO PID [...]" */
158 goto print_rt_info; 175 goto print_rt_info;
159 176
160 BB_EXECVP_or_die(argv); 177 BB_EXECVP_or_die(argv);