* [PATCH] chrt: Make priority optional for policies that don't use it
@ 2025-06-15 19:22 Madadi Vineeth Reddy
2025-06-17 12:05 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Madadi Vineeth Reddy @ 2025-06-15 19:22 UTC (permalink / raw)
To: util-linux; +Cc: vineethr
Currently, chrt requires a priority argument even for scheduling
policies like SCHED_OTHER and SCHED_BATCH, which ignore it.
This change relaxes that requirement. Now, priority is only expected
for SCHED_FIFO and SCHED_RR. For other policies, a default value of 0
is set internally and no argument is required on the command line.
This simplifies usage when modifying runtime parameters like
--sched-runtime for non-realtime tasks.
For example, to change the EEVDF tunable base_slice, one currently
needs to run:
chrt -v -o -T 1000000 -p 0 $PID
Passing '0' after -p is not intutive and not required as priority is
not applicable to SCHED_OTHER tasks. Now with this patch, one can do:
chrt -v -o -T 1000000 -p $PID
Passing '0' still works ensuring ABI doesn't break.
Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
---
schedutils/chrt.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index cf99935dc..339f3e318 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -495,20 +495,26 @@ int main(int argc, char **argv)
}
}
- if (((ctl->pid > -1) && argc - optind < 1) ||
- ((ctl->pid == -1) && argc - optind < 2)) {
+ bool policy_needs_priority = (ctl->policy == SCHED_FIFO || ctl->policy == SCHED_RR);
+
+ if (((ctl->pid > -1) && argc - optind < (policy_needs_priority ? 1 : 0)) ||
+ ((ctl->pid == -1) && argc - optind < (policy_needs_priority ? 2 : 1))) {
warnx(_("bad usage"));
errtryhelp(EXIT_FAILURE);
}
- if ((ctl->pid > -1) && (ctl->verbose || argc - optind == 1)) {
+ if ((ctl->pid > -1) && (ctl->verbose || argc - optind == (policy_needs_priority ? 1 : 0))) {
show_sched_info(ctl);
- if (argc - optind == 1)
+ if (argc - optind == (policy_needs_priority ? 1 : 0))
return EXIT_SUCCESS;
}
errno = 0;
- ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
+
+ if (policy_needs_priority || argc - optind == 2)
+ ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
+ else
+ ctl->priority = 0;
if (ctl->runtime && !supports_runtime_param(ctl->policy))
errx(EXIT_FAILURE, _("--sched-runtime option is supported for %s"),
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] chrt: Make priority optional for policies that don't use it
2025-06-15 19:22 [PATCH] chrt: Make priority optional for policies that don't use it Madadi Vineeth Reddy
@ 2025-06-17 12:05 ` Karel Zak
2025-06-17 17:04 ` Madadi Vineeth Reddy
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2025-06-17 12:05 UTC (permalink / raw)
To: Madadi Vineeth Reddy; +Cc: util-linux
On Mon, Jun 16, 2025 at 12:52:18AM +0530, Madadi Vineeth Reddy wrote:
> Currently, chrt requires a priority argument even for scheduling
> policies like SCHED_OTHER and SCHED_BATCH, which ignore it.
>
> This change relaxes that requirement. Now, priority is only expected
> for SCHED_FIFO and SCHED_RR. For other policies, a default value of 0
> is set internally and no argument is required on the command line.
>
> This simplifies usage when modifying runtime parameters like
> --sched-runtime for non-realtime tasks.
>
> For example, to change the EEVDF tunable base_slice, one currently
> needs to run:
> chrt -v -o -T 1000000 -p 0 $PID
>
> Passing '0' after -p is not intutive and not required as priority is
> not applicable to SCHED_OTHER tasks. Now with this patch, one can do:
> chrt -v -o -T 1000000 -p $PID
>
> Passing '0' still works ensuring ABI doesn't break.
Looks good. It would be nice to update the man page and add a note
that -p is not required since util-linux v2.42.
> + bool policy_needs_priority = (ctl->policy == SCHED_FIFO || ctl->policy == SCHED_RR);
Nitpicking... can't we use a shorter name, for example "need_prio"? ;-)
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] chrt: Make priority optional for policies that don't use it
2025-06-17 12:05 ` Karel Zak
@ 2025-06-17 17:04 ` Madadi Vineeth Reddy
0 siblings, 0 replies; 3+ messages in thread
From: Madadi Vineeth Reddy @ 2025-06-17 17:04 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
Hi Karel,
On 17/06/25 17:35, Karel Zak wrote:
> On Mon, Jun 16, 2025 at 12:52:18AM +0530, Madadi Vineeth Reddy wrote:
>> Currently, chrt requires a priority argument even for scheduling
>> policies like SCHED_OTHER and SCHED_BATCH, which ignore it.
>>
>> This change relaxes that requirement. Now, priority is only expected
>> for SCHED_FIFO and SCHED_RR. For other policies, a default value of 0
>> is set internally and no argument is required on the command line.
>>
>> This simplifies usage when modifying runtime parameters like
>> --sched-runtime for non-realtime tasks.
>>
>> For example, to change the EEVDF tunable base_slice, one currently
>> needs to run:
>> chrt -v -o -T 1000000 -p 0 $PID
>>
>> Passing '0' after -p is not intutive and not required as priority is
>> not applicable to SCHED_OTHER tasks. Now with this patch, one can do:
>> chrt -v -o -T 1000000 -p $PID
>>
>> Passing '0' still works ensuring ABI doesn't break.
>
> Looks good. It would be nice to update the man page and add a note
> that -p is not required since util-linux v2.42.
>
I believe you meant that the priority argument is not required for some
scheduling policies. The -p / --pid option is still required.
I’ll update the man page accordingly.
>> + bool policy_needs_priority = (ctl->policy == SCHED_FIFO || ctl->policy == SCHED_RR);
>
> Nitpicking... can't we use a shorter name, for example "need_prio"? ;-)
Sure, will update it in v2. Thanks for taking a look.
Thanks,
Madadi Vineeth Reddy
>
> Karel
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-17 17:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-15 19:22 [PATCH] chrt: Make priority optional for policies that don't use it Madadi Vineeth Reddy
2025-06-17 12:05 ` Karel Zak
2025-06-17 17:04 ` Madadi Vineeth Reddy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).