From f86f2f4e9a20d235b24ea86e4dddd0485165306f Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 21 May 2017 13:11:42 -0500 Subject: Cleaup chrt --- toys/pending/chrt.c | 91 +++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 51 deletions(-) (limited to 'toys/pending') diff --git a/toys/pending/chrt.c b/toys/pending/chrt.c index d2b73a42..01076b93 100644 --- a/toys/pending/chrt.c +++ b/toys/pending/chrt.c @@ -1,92 +1,81 @@ /* chrt.c - Get/set real-time (scheduling) attributes * * Copyright 2016 The Android Open Source Project + * + * Note: -ibrfo flags sorted to match SCHED positions for highest_bit() -USE_CHRT(NEWTOY(chrt, "mp#bfiorR[!bfior]", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_CHRT(NEWTOY(chrt, "^mp#<0iRbrfo[!ibrfo]", TOYFLAG_USR|TOYFLAG_SBIN)) config CHRT bool "chrt" default n help - usage: chrt [-m] [-p PID] [POLICY PRIO] [COMMAND [ARGS...]] + usage: chrt [-Rmofrbi] {-p PID [PRIORITY] | [PRIORITY COMMAND...]} - Get/set a process' real-time (scheduling) attributes. + Get/set a process' real-time scheduling policy and priority. - -p Apply to given pid + -p Set/query given pid (instead of running COMMAND) -R Set SCHED_RESET_ON_FORK -m Show min/max priorities available - Policies: - -b SCHED_BATCH -f SCHED_FIFO -i SCHED_IDLE - -o SCHED_OTHER -r SCHED_RR + Set policy (default -r): + + -o SCHED_OTHER -f SCHED_FIFO -r SCHED_RR + -b SCHED_BATCH -i SCHED_IDLE */ #define FOR_chrt #include "toys.h" -#include - GLOBALS( long pid; ) -static char *policy_name(int policy) { - char *policy_names[] = { "SCHED_OTHER", "SCHED_FIFO", "SCHED_RR", - "SCHED_BATCH", "4", "SCHED_IDLE", "SCHED_DEADLINE" }; - - return policy < ARRAY_LEN(policy_names) ? policy_names[policy] : "???"; -} +char *polnames[] = { + "SCHED_OTHER", "SCHED_FIFO", "SCHED_RR", "SCHED_BATCH", 0, "SCHED_IDLE", + "SCHED_DEADLINE" +}; void chrt_main(void) { - int policy = SCHED_RR; - struct sched_param p; + int pol, pri; // Show min/maxes? if (toys.optflags&FLAG_m) { - for (policy = SCHED_OTHER; policy <= SCHED_IDLE; ++policy) - if (policy != 4) // There's an unused hole in the priorities. - printf("%s min/max priority\t: %d/%d\n", policy_name(policy), - sched_get_priority_min(policy), sched_get_priority_max(policy)); + for (pol = 0; pol