]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: Add support for (GRUB) bandwidth reclaim
authorFurkan Caliskan <frn1furkan10@gmail.com>
Mon, 11 May 2026 14:10:30 +0000 (17:10 +0300)
committerKarel Zak <kzak@redhat.com>
Wed, 13 May 2026 08:32:23 +0000 (10:32 +0200)
The SCHED_DEADLINE policy supports the (GRUB) Greedy Reclamation
of Unused Bandwidth algorithm. This allows tasks to reclaim
bandwidth that are left over by other deadline tasks that finish
their work early, or voluntarily yield the cpu.

Currently, chrt has no way to set the SCHED_FLAG_RECLAIM bit in
the sched_flags field of the sched_attr structure.

Add -G/--reclaim-grub option to allow users to toggle this feature
using the deadline scheduling class.

[kzak@redhat.com: - add missing #ifdef SCHED_FLAG_RECLAIM guards
                  - add comments to #else/#endif for SCHED_DEADLINE block]
Signed-off-by: Furkan Caliskan <frn1furkan10@gmail.com>
bash-completion/chrt
schedutils/chrt.1.adoc
schedutils/chrt.c

index 3ca13fc05711a7b7b0c713e9fe535dbcdfd1d31a..363efdfa1fb9e025fcfd3a8d7539edc10977520f 100644 (file)
@@ -26,6 +26,7 @@ _chrt_module()
                                --max
                                --other
                                --pid
+                               --reclaim-grub
                                --reset-on-fork
                                --rr
                                --sched-deadline
index 4c6dbde1cde26ed93b6150c746e1ab024135fd4b..7c2ceab866f21f133de457b1da31f0ecea18c6b4 100644 (file)
@@ -82,6 +82,9 @@ Specifies period parameter for *SCHED_DEADLINE* policy (Linux-specific). Note th
 *-D*, *--sched-deadline* _nanoseconds_::
 Specifies deadline parameter for *SCHED_DEADLINE* policy (Linux-specific).
 
+*-G*, *--reclaim-grub*::
+Enables GRUB (Greedy Reclamation of Unused Bandwidth) algorithm. Linux-specific, supported since 4.13.
+
 *-R*, *--reset-on-fork*::
 Use *SCHED_RESET_ON_FORK* or *SCHED_FLAG_RESET_ON_FORK* flag. Linux-specific, supported since 2.6.31.
 +
index c5bef5478d5c58354d8946d97d943843c976fb47..c1895d1177fc39f9b9bd0285c7e8ed0caaeb8f66 100644 (file)
@@ -49,6 +49,7 @@ struct chrt_ctl {
        uint64_t runtime;                       /* --sched-* options */
        uint64_t deadline;
        uint64_t period;
+       uint64_t sched_flags;                   /* For sched_attr->sched_flags member */
 
        unsigned int all_tasks : 1,             /* all threads of the PID */
                     reset_on_fork : 1,         /* SCHED_RESET_ON_FORK or SCHED_FLAG_RESET_ON_FORK */
@@ -91,6 +92,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(USAGE_SEPARATOR, out);
        fputs(_("Scheduling options:\n"), out);
        fputs(_(" -R, --reset-on-fork       set reset-on-fork flag\n"), out);
+       fputs(_(" -G, --reclaim-grub        set SCHED_FLAG_RECLAIM\n"), out);
        fputs(_(" -T, --sched-runtime <ns>  runtime parameter for DEADLINE\n"), out);
        fputs(_(" -P, --sched-period <ns>   period parameter for DEADLINE\n"), out);
        fputs(_(" -D, --sched-deadline <ns> deadline parameter for DEADLINE\n"), out);
@@ -386,6 +388,7 @@ static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
        sa.sched_runtime  = ctl->runtime;
        sa.sched_period   = ctl->period;
        sa.sched_deadline = ctl->deadline;
+       sa.sched_flags    = ctl->sched_flags;
 
 # ifdef SCHED_FLAG_RESET_ON_FORK
        /* Don't use SCHED_RESET_ON_FORK for sched_setattr()! */
@@ -447,6 +450,7 @@ int main(int argc, char **argv)
                { "sched-period",   required_argument, NULL, 'P' },
                { "sched-deadline", required_argument, NULL, 'D' },
                { "reset-on-fork",  no_argument,       NULL, 'R' },
+               { "reclaim-grub",   no_argument,       NULL, 'G' },
                { "verbose",    no_argument, NULL, 'v' },
                { "version",    no_argument, NULL, 'V' },
                { NULL,         no_argument, NULL, 0 }
@@ -457,7 +461,7 @@ int main(int argc, char **argv)
        textdomain(PACKAGE);
        close_stdout_atexit();
 
-       while((c = getopt_long(argc, argv, "+abdD:efiphmoP:T:rRvV", longopts, NULL)) != -1)
+       while((c = getopt_long(argc, argv, "+abdD:efiphmoP:T:rRGvV", longopts, NULL)) != -1)
        {
                switch (c) {
                case 'a':
@@ -490,6 +494,11 @@ int main(int argc, char **argv)
                case 'R':
                        ctl->reset_on_fork = 1;
                        break;
+               case 'G':
+#ifdef SCHED_FLAG_RECLAIM
+                       ctl->sched_flags |= SCHED_FLAG_RECLAIM;
+#endif
+                       break;
                case 'i':
 #ifdef SCHED_IDLE
                        ctl->policy = SCHED_IDLE;
@@ -578,6 +587,14 @@ int main(int argc, char **argv)
        if ((ctl->deadline || ctl->period) && ctl->policy != SCHED_DEADLINE)
                errx(EXIT_FAILURE, _("--sched-{deadline,period} options are "
                                     "supported for SCHED_DEADLINE only"));
+# ifdef SCHED_FLAG_RECLAIM
+#  ifndef HAVE_SCHED_SETATTR
+       if (ctl->sched_flags & SCHED_FLAG_RECLAIM)
+               errx(EXIT_FAILURE, _("SCHED_FLAG_RECLAIM is unsupported"));
+#  endif
+       if ((ctl->sched_flags & SCHED_FLAG_RECLAIM) && ctl->policy != SCHED_DEADLINE)
+               errx(EXIT_FAILURE, _("--reclaim-grub is only supported for SCHED_DEADLINE"));
+# endif
        if (ctl->policy == SCHED_DEADLINE) {
                /* The basic rule is runtime <= deadline <= period, so we can
                 * make deadline and runtime optional on command line. Note we
@@ -589,10 +606,10 @@ int main(int argc, char **argv)
                if (ctl->runtime == 0)
                        ctl->runtime = ctl->deadline;
        }
-#else
+#else /* !SCHED_DEADLINE */
        if (ctl->deadline || ctl->period)
                errx(EXIT_FAILURE, _("SCHED_DEADLINE is unsupported"));
-#endif
+#endif /* SCHED_DEADLINE */
        if (ctl->priority < sched_get_priority_min(ctl->policy) ||
                        sched_get_priority_max(ctl->policy) < ctl->priority)
                errx(EXIT_FAILURE,