From cdfb1e88228c10c28f8bfe0f4b0ff1b3b06d1ed4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 2 Feb 2010 21:24:52 +0100 Subject: [PATCH] chrt: add --reset-on-fork This new option allows to set SCHED_RESET_ON_FORK flag for FIFO and RR policies. Example: $ chrt --fifo --reset-on-fork 1 /bin/bash $ schedutils/chrt --pid $$ pid 31579's current scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK pid 31579's current scheduling priority: 1 Signed-off-by: Karel Zak --- schedutils/chrt.1 | 14 ++++++++++++++ schedutils/chrt.c | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/schedutils/chrt.1 b/schedutils/chrt.1 index 06c58b47..9016cfef 100644 --- a/schedutils/chrt.1 +++ b/schedutils/chrt.1 @@ -55,6 +55,11 @@ The policy is supported since Linux 2.6.16. The .BR SCHED_IDLE policy is supported since Linux 2.6.23. +.PP +The +.BR SCHED_RESET_ON_FORK +flag for policies SCHED_RR and SCHED_FIFO is supported +since Linux 2.6.31. .SH OPTIONS .TP .B -p, --pid @@ -69,6 +74,15 @@ set scheduling policy to set scheduling policy to .BR SCHED_FIFO .TP +.B -R, --reset-on-fork +add +.B SCHED_RESET_ON_FORK +flag to the +.B SCHED_FIFO +or +.B SCHED_RR +scheduling policy (Linux specific) +.TP .B -i, --idle set schedulng policy to .BR SCHED_IDLE diff --git a/schedutils/chrt.c b/schedutils/chrt.c index 6629c2e8..0ff9b9bb 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -66,6 +66,8 @@ static void show_usage(int rc) " -i | --idle set policy to SCHED_IDLE\n" " -o | --other set policy to SCHED_OTHER\n" " -r | --rr set policy to SCHED_RR (default)\n" + "\nScheduling flags:\n" + " -R | --reset-on-fork set SCHED_RESET_ON_FORK for FIFO or RR\n" "\nOptions:\n" " -h | --help display this help\n" " -p | --pid operate on existing given pid\n" @@ -161,7 +163,7 @@ static void show_min_max(void) int main(int argc, char *argv[]) { - int i, policy = SCHED_RR, priority = 0, verbose = 0; + int i, policy = SCHED_RR, priority = 0, verbose = 0, policy_flag = 0; struct sched_param sp; pid_t pid = -1; @@ -174,6 +176,7 @@ int main(int argc, char *argv[]) { "max", 0, NULL, 'm' }, { "other", 0, NULL, 'o' }, { "rr", 0, NULL, 'r' }, + { "reset-on-fork", 0, NULL, 'R' }, { "verbose", 0, NULL, 'v' }, { "version", 0, NULL, 'V' }, { NULL, 0, NULL, 0 } @@ -183,7 +186,7 @@ int main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - while((i = getopt_long(argc, argv, "+bfiphmorvV", longopts, NULL)) != -1) + while((i = getopt_long(argc, argv, "+bfiphmoRrvV", longopts, NULL)) != -1) { int ret = EXIT_FAILURE; @@ -196,6 +199,9 @@ int main(int argc, char *argv[]) case 'f': policy = SCHED_FIFO; break; + case 'R': + policy_flag |= SCHED_RESET_ON_FORK; + break; case 'i': #ifdef SCHED_IDLE policy = SCHED_IDLE; @@ -243,6 +249,14 @@ int main(int argc, char *argv[]) if (errno) err(EXIT_FAILURE, _("failed to parse priority")); + /* sanity check */ + if ((policy_flag & SCHED_RESET_ON_FORK) && + !(policy == SCHED_FIFO || policy == SCHED_RR)) + errx(EXIT_FAILURE, _("SCHED_RESET_ON_FORK flag is suppoted for " + "SCHED_FIFO and SCHED_RR policies only")); + + policy |= policy_flag; + if (pid == -1) pid = 0; sp.sched_priority = priority; -- 2.39.5