aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-23 16:01:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-23 16:04:48 +0100
commit66ad9be6031a3c5c0491b0040270b3f9ff591cdf (patch)
tree3225b99c853d2fdd9f41c4b2f10f8bf1ca592a44
parent0f6e4350b3c36b3b4533d0ea910481e28d5f81ab (diff)
downloadbusybox-w32-66ad9be6031a3c5c0491b0040270b3f9ff591cdf.tar.gz
busybox-w32-66ad9be6031a3c5c0491b0040270b3f9ff591cdf.tar.bz2
busybox-w32-66ad9be6031a3c5c0491b0040270b3f9ff591cdf.zip
chrt: use correct min/max priorities
function old new delta chrt_main 369 432 +63 policies 48 96 +48 packed_usage 32239 32249 +10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 121/0) Total: 121 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/chrt.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/util-linux/chrt.c b/util-linux/chrt.c
index bbd6e2deb..27c8f43cc 100644
--- a/util-linux/chrt.c
+++ b/util-linux/chrt.c
@@ -35,6 +35,9 @@
35 35
36#include <sched.h> 36#include <sched.h>
37#include "libbb.h" 37#include "libbb.h"
38#ifndef SCHED_IDLE
39# define SCHED_IDLE 5
40#endif
38 41
39static const struct { 42static const struct {
40 int policy; 43 int policy;
@@ -79,18 +82,22 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
79 const char *current_new; 82 const char *current_new;
80 int policy = SCHED_RR; 83 int policy = SCHED_RR;
81 84
82 /* only one policy accepted */ 85 opt = getopt32(argv, "^"
83 opt = getopt32(argv, "^+" "mprfobi" "\0" "r--fobi:f--robi:o--rfbi:b--rfoi:i--rfob"); 86 "+" "mprfobi"
87 "\0"
88 /* only one policy accepted: */
89 "r--fobi:f--robi:o--rfbi:b--rfoi:i--rfob"
90 );
84 if (opt & OPT_m) { /* print min/max and exit */ 91 if (opt & OPT_m) { /* print min/max and exit */
92 show_min_max(SCHED_OTHER);
85 show_min_max(SCHED_FIFO); 93 show_min_max(SCHED_FIFO);
86 show_min_max(SCHED_RR); 94 show_min_max(SCHED_RR);
87 show_min_max(SCHED_OTHER);
88 show_min_max(SCHED_BATCH); 95 show_min_max(SCHED_BATCH);
89 show_min_max(SCHED_IDLE); 96 show_min_max(SCHED_IDLE);
90 fflush_stdout_and_exit(EXIT_SUCCESS); 97 fflush_stdout_and_exit(EXIT_SUCCESS);
91 } 98 }
92 if (opt & OPT_r) 99 //if (opt & OPT_r)
93 policy = SCHED_RR; 100 // policy = SCHED_RR; - default, already set
94 if (opt & OPT_f) 101 if (opt & OPT_f)
95 policy = SCHED_FIFO; 102 policy = SCHED_FIFO;
96 if (opt & OPT_o) 103 if (opt & OPT_o)
@@ -140,14 +147,9 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
140 current_new += 8; 147 current_new += 8;
141 } 148 }
142 149
143 /* from the manpage of sched_getscheduler:
144 [...] sched_priority can have a value in the range 0 to 99.
145 [...] SCHED_OTHER, SCHED_BATCH or SCHED_IDLE must be assigned static
146 priority 0.
147 [...] SCHED_FIFO or SCHED_RR can have static priority in 1..99 range.
148 */
149 sp.sched_priority = xstrtou_range(priority, 0, 150 sp.sched_priority = xstrtou_range(priority, 0,
150 (policy != SCHED_OTHER && policy != SCHED_BATCH && policy != SCHED_IDLE) ? 1 : 0, 99); 151 sched_get_priority_min(policy), sched_get_priority_max(policy)
152 );
151 153
152 if (sched_setscheduler(pid, policy, &sp) < 0) 154 if (sched_setscheduler(pid, policy, &sp) < 0)
153 bb_perror_msg_and_die("can't %cet pid %d's policy", 's', (int)pid); 155 bb_perror_msg_and_die("can't %cet pid %d's policy", 's', (int)pid);