Re: [PATCH] chrt: Add support for (GRUB) bandwidth reclaim

Karel Zak <[email protected]> Mon, 11 May 2026 13:10:48 +0200
Newsgroups org.kernel.vger.util-linux
Message-ID <qa5c2sqdvxiclkfszc7wdfdd3naa7e2w42mip3abj4auisqw6r@o2jtcbaibyep>
Hi Furkan,

Sorry for the delay in reviewing.

On Thu, Apr 23, 2026 at 01:14:07PM +0300, Furkan Caliskan wrote:
> --- a/schedutils/chrt.1.adoc
> +++ b/schedutils/chrt.1.adoc
> @@ -83,6 +83,9 @@ Specifies deadline parameter for *SCHED_DEADLINE* policy (Linux-specific).
>  
>  *-R*, *--reset-on-fork*::
>  Use *SCHED_RESET_ON_FORK* or *SCHED_FLAG_RESET_ON_FORK* flag. Linux-specific, supported since 2.6.31.
> +
> +*-G*, *--reclaim-grub*::
> +Enables GRUB (Greedy Reclamation of Unused Bandwidth) algorithm. 
>  +
>  Each thread has a _reset-on-fork_ scheduling flag. When this flag is set, children created by *fork*(2) do not inherit privileged scheduling policies. After the _reset-on-fork_ flag has been enabled, it can be reset only if the thread has the *CAP_SYS_NICE* capability. This flag is disabled in child processes created by *fork*(2).
>  +

You have added *--reclaim-grub* to the reset-on-fork description block.

Please, also add "Linux-specific, supported since 4.13".

> diff --git a/schedutils/chrt.c b/schedutils/chrt.c
> index 273905e5d..1a081e566 100644
> --- a/schedutils/chrt.c
> +++ b/schedutils/chrt.c
> @@ -46,6 +46,7 @@ struct chrt_ctl {
>  	uint64_t runtime;			/* --sched-* options */
>  	uint64_t deadline;
>  	uint64_t period;
> +        uint64_t flag;                         /* For sched_attr->sched_flags member */ 

 What about to use sched_flags rather than generic 

>  
>  	unsigned int all_tasks : 1,		/* all threads of the PID */
>  		     reset_on_fork : 1,		/* SCHED_RESET_ON_FORK or SCHED_FLAG_RESET_ON_FORK */
> @@ -79,6 +80,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);
> @@ -349,7 +351,7 @@ static int set_sched_one(struct chrt_ctl *ctl, pid_t pid)
>  	/* old API is good enough for non-deadline */
>  	if (!supports_runtime_param(ctl->policy))
>  		return set_sched_one_by_setscheduler(ctl, pid);
> -
> +	
>  	/* not changed by chrt, follow the current setting */
>  	sa.sched_nice = getpriority(PRIO_PROCESS, pid);
>  
> @@ -359,6 +361,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->flag;

Please be careful and consistently use tabs. Use an editor that
follows .editorconfig.

>  
>  # ifdef SCHED_FLAG_RESET_ON_FORK
>  	/* Don't use SCHED_RESET_ON_FORK for sched_setattr()! */
> @@ -417,6 +420,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 }


You need to add 'G' to the getopt_long() call as well; currently, only
--reclaim-grub works.

You also need to add --reclaim-grub to bash-completion/chrt.

> @@ -460,6 +464,11 @@ int main(int argc, char **argv)
>  		case 'R':
>  			ctl->reset_on_fork = 1;
>  			break;
> +		case 'G':
> +#ifdef SCHED_DEADLINE

 #ifdef SCHED_FLAG_RECLAIM

> +			ctl->flag |= SCHED_FLAG_RECLAIM;
> +#endif
> +			break;
>  		case 'i':
>  #ifdef SCHED_IDLE
>  			ctl->policy = SCHED_IDLE;
> @@ -546,6 +555,8 @@ 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"));
> +	if ((ctl->flag & SCHED_FLAG_RECLAIM) && ctl->policy != SCHED_DEADLINE)
> +	        errx(EXIT_FAILURE, _("--reclaim-grub is only supported for SCHED_DEADLINE"));

chrt is possible compile without sched_setattr. The ideal would be to
add there also

#indef HAVE_SCHED_SETATTR
  if (ctl->flag & SCHED_FLAG_RECLAIM)
    errx(EXIT_FAILURE, _("SCHED_FLAG_RECLAIM is unsupported"));
#endif

Thanks!
    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com