From: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
To: util-linux@vger.kernel.org
Cc: vineethr@linux.ibm.com
Subject: [PATCH] chrt: Make priority optional for policies that don't use it
Date: Mon, 16 Jun 2025 00:52:18 +0530 [thread overview]
Message-ID: <20250615192218.70289-1-vineethr@linux.ibm.com> (raw)
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
next reply other threads:[~2025-06-15 19:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-15 19:22 Madadi Vineeth Reddy [this message]
2025-06-17 12:05 ` [PATCH] chrt: Make priority optional for policies that don't use it Karel Zak
2025-06-17 17:04 ` Madadi Vineeth Reddy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250615192218.70289-1-vineethr@linux.ibm.com \
--to=vineethr@linux.ibm.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).