|
|
df3f53 |
From c4caa5b973f9cdb4c43edea3c32cda62cdf15b3b Mon Sep 17 00:00:00 2001
|
|
|
df3f53 |
From: Karel Zak <kzak@redhat.com>
|
|
|
df3f53 |
Date: Thu, 1 Oct 2020 11:20:01 +0200
|
|
|
df3f53 |
Subject: [PATCH 44/55] chrt: don't restrict --reset-on-fork, add more info to
|
|
|
df3f53 |
man page
|
|
|
df3f53 |
|
|
|
df3f53 |
The flag works (= kernel accepts it) for all scheduling policies
|
|
|
df3f53 |
and sched_getattr() returns the flag for all policies.
|
|
|
df3f53 |
|
|
|
df3f53 |
There is no reason for userspace to be more smart than kernel or hide
|
|
|
df3f53 |
the flag when it prints sched_getattr()/sched_getscheduler() results.
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --batch 0 /bin/true
|
|
|
df3f53 |
pid 1315019's new scheduling policy: SCHED_BATCH|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --fifo 1 /bin/true
|
|
|
df3f53 |
pid 1315055's new scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --deadline --sched-period 10000 0 /bin/true
|
|
|
df3f53 |
pid 1315182's new scheduling policy: SCHED_DEADLINE|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --idle 0 /bin/true
|
|
|
df3f53 |
pid 1315247's new scheduling policy: SCHED_IDLE|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --rr 1 /bin/true
|
|
|
df3f53 |
pid 1315275's new scheduling policy: SCHED_RR|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
# chrt -v --reset-on-fork --other 0 /bin/true
|
|
|
df3f53 |
pid 1315311's new scheduling policy: SCHED_OTHER|SCHED_RESET_ON_FORK
|
|
|
df3f53 |
|
|
|
df3f53 |
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1884194
|
|
|
df3f53 |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
df3f53 |
---
|
|
|
df3f53 |
schedutils/chrt.1 | 32 ++++++++++++++++++++++++++++----
|
|
|
df3f53 |
schedutils/chrt.c | 18 +++++-------------
|
|
|
df3f53 |
2 files changed, 33 insertions(+), 17 deletions(-)
|
|
|
df3f53 |
|
|
|
df3f53 |
diff --git a/schedutils/chrt.1 b/schedutils/chrt.1
|
|
|
df3f53 |
index 4b8b1e9da..a9adfb316 100644
|
|
|
df3f53 |
--- a/schedutils/chrt.1
|
|
|
df3f53 |
+++ b/schedutils/chrt.1
|
|
|
df3f53 |
@@ -92,13 +92,37 @@ Specifies period parameter for SCHED_DEADLINE policy (Linux-specific).
|
|
|
df3f53 |
Specifies deadline parameter for SCHED_DEADLINE policy (Linux-specific).
|
|
|
df3f53 |
.TP
|
|
|
df3f53 |
\fB\-R\fR, \fB\-\-reset-on-fork\fR
|
|
|
df3f53 |
-Add
|
|
|
df3f53 |
+Use
|
|
|
df3f53 |
.B SCHED_RESET_ON_FORK
|
|
|
df3f53 |
-flag to the
|
|
|
df3f53 |
+or
|
|
|
df3f53 |
+.B SCHED_FLAG_RESET_ON_FORK
|
|
|
df3f53 |
+flag. Linux-specific, supported since 2.6.31.
|
|
|
df3f53 |
+
|
|
|
df3f53 |
+Each thread has a reset-on-fork scheduling flag. When this flag is set, children created by
|
|
|
df3f53 |
+.BR fork (2)
|
|
|
df3f53 |
+do not inherit privileged scheduling policies. After the reset-on-fork flag has been enabled,
|
|
|
df3f53 |
+it can be reset only if the thread has the
|
|
|
df3f53 |
+.BR CAP_SYS_NICE
|
|
|
df3f53 |
+capability. This flag is disabled in child processes created by
|
|
|
df3f53 |
+.BR fork (2).
|
|
|
df3f53 |
+
|
|
|
df3f53 |
+More precisely, if the reset-on-fork flag is set,
|
|
|
df3f53 |
+the following rules apply for subsequently created children:
|
|
|
df3f53 |
+.RS
|
|
|
df3f53 |
+.IP * 3
|
|
|
df3f53 |
+If the calling thread has a scheduling policy of
|
|
|
df3f53 |
.B SCHED_FIFO
|
|
|
df3f53 |
or
|
|
|
df3f53 |
-.B SCHED_RR
|
|
|
df3f53 |
-scheduling policy (Linux-specific, supported since 2.6.31).
|
|
|
df3f53 |
+.BR SCHED_RR ,
|
|
|
df3f53 |
+the policy is reset to
|
|
|
df3f53 |
+.BR SCHED_OTHER
|
|
|
df3f53 |
+in child processes.
|
|
|
df3f53 |
+.IP *
|
|
|
df3f53 |
+If the calling process has a negative nice value,
|
|
|
df3f53 |
+the nice value is reset to zero in child processes.
|
|
|
df3f53 |
+.RE
|
|
|
df3f53 |
+
|
|
|
df3f53 |
+
|
|
|
df3f53 |
|
|
|
df3f53 |
.SH OPTIONS
|
|
|
df3f53 |
.TP
|
|
|
df3f53 |
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
|
|
|
df3f53 |
index 15556bbad..2a6f1e151 100644
|
|
|
df3f53 |
--- a/schedutils/chrt.c
|
|
|
df3f53 |
+++ b/schedutils/chrt.c
|
|
|
df3f53 |
@@ -152,7 +152,7 @@ static void __attribute__((__noreturn__)) usage(void)
|
|
|
df3f53 |
|
|
|
df3f53 |
fputs(USAGE_SEPARATOR, out);
|
|
|
df3f53 |
fputs(_("Scheduling options:\n"), out);
|
|
|
df3f53 |
- fputs(_(" -R, --reset-on-fork set SCHED_RESET_ON_FORK for FIFO or RR\n"), out);
|
|
|
df3f53 |
+ fputs(_(" -R, --reset-on-fork set reset-on-fork flag\n"), out);
|
|
|
df3f53 |
fputs(_(" -T, --sched-runtime <ns> runtime parameter for DEADLINE\n"), out);
|
|
|
df3f53 |
fputs(_(" -P, --sched-period <ns> period parameter for DEADLINE\n"), out);
|
|
|
df3f53 |
fputs(_(" -D, --sched-deadline <ns> deadline parameter for DEADLINE\n"), out);
|
|
|
df3f53 |
@@ -173,22 +173,19 @@ static void __attribute__((__noreturn__)) usage(void)
|
|
|
df3f53 |
|
|
|
df3f53 |
static const char *get_policy_name(int policy)
|
|
|
df3f53 |
{
|
|
|
df3f53 |
+#ifdef SCHED_RESET_ON_FORK
|
|
|
df3f53 |
+ policy &= ~SCHED_RESET_ON_FORK;
|
|
|
df3f53 |
+#endif
|
|
|
df3f53 |
switch (policy) {
|
|
|
df3f53 |
case SCHED_OTHER:
|
|
|
df3f53 |
return "SCHED_OTHER";
|
|
|
df3f53 |
case SCHED_FIFO:
|
|
|
df3f53 |
-#ifdef SCHED_RESET_ON_FORK
|
|
|
df3f53 |
- case SCHED_FIFO | SCHED_RESET_ON_FORK:
|
|
|
df3f53 |
-#endif
|
|
|
df3f53 |
return "SCHED_FIFO";
|
|
|
df3f53 |
#ifdef SCHED_IDLE
|
|
|
df3f53 |
case SCHED_IDLE:
|
|
|
df3f53 |
return "SCHED_IDLE";
|
|
|
df3f53 |
#endif
|
|
|
df3f53 |
case SCHED_RR:
|
|
|
df3f53 |
-#ifdef SCHED_RESET_ON_FORK
|
|
|
df3f53 |
- case SCHED_RR | SCHED_RESET_ON_FORK:
|
|
|
df3f53 |
-#endif
|
|
|
df3f53 |
return "SCHED_RR";
|
|
|
df3f53 |
#ifdef SCHED_BATCH
|
|
|
df3f53 |
case SCHED_BATCH:
|
|
|
df3f53 |
@@ -257,7 +254,7 @@ fallback:
|
|
|
df3f53 |
else
|
|
|
df3f53 |
prio = sp.sched_priority;
|
|
|
df3f53 |
# ifdef SCHED_RESET_ON_FORK
|
|
|
df3f53 |
- if (policy == (SCHED_FIFO|SCHED_RESET_ON_FORK) || policy == (SCHED_BATCH|SCHED_RESET_ON_FORK))
|
|
|
df3f53 |
+ if (policy & SCHED_RESET_ON_FORK)
|
|
|
df3f53 |
reset_on_fork = 1;
|
|
|
df3f53 |
# endif
|
|
|
df3f53 |
}
|
|
|
df3f53 |
@@ -515,11 +512,6 @@ int main(int argc, char **argv)
|
|
|
df3f53 |
errno = 0;
|
|
|
df3f53 |
ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
|
|
|
df3f53 |
|
|
|
df3f53 |
-#ifdef SCHED_RESET_ON_FORK
|
|
|
df3f53 |
- if (ctl->reset_on_fork && ctl->policy != SCHED_FIFO && ctl->policy != SCHED_RR)
|
|
|
df3f53 |
- errx(EXIT_FAILURE, _("--reset-on-fork option is supported for "
|
|
|
df3f53 |
- "SCHED_FIFO and SCHED_RR policies only"));
|
|
|
df3f53 |
-#endif
|
|
|
df3f53 |
#ifdef SCHED_DEADLINE
|
|
|
df3f53 |
if ((ctl->runtime || ctl->deadline || ctl->period) && ctl->policy != SCHED_DEADLINE)
|
|
|
df3f53 |
errx(EXIT_FAILURE, _("--sched-{runtime,deadline,period} options "
|
|
|
df3f53 |
--
|
|
|
df3f53 |
2.29.2
|
|
|
df3f53 |
|