From: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
To: util-linux@vger.kernel.org, Karel Zak <kzak@redhat.com>,
Benno Schulenberg <bensberg@telfort.nl>
Cc: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Subject: [PATCH v4 2/3] chrt: Only display current settings when no policy is specified
Date: Sun, 22 Jun 2025 01:20:47 +0530 [thread overview]
Message-ID: <20250621195048.24900-3-vineethr@linux.ibm.com> (raw)
In-Reply-To: <20250621195048.24900-1-vineethr@linux.ibm.com>
Previously, running "chrt --pid <pid>" with no policy options
would display the process’s current scheduling attributes, but
specifying a policy without a priority (e.g. chrt --rr --pid <pid>)
would silently fallback to displaying the same info. This was
confusing, since a policy option normally implies an intent to
change something.
This patch changes the behavior so that
chrt --pid <pid> continues to show the current settings:
chrt --pid 10862
pid 10862's current scheduling policy: SCHED_OTHER
pid 10862's current scheduling priority: 0
pid 10862's current runtime parameter: 2800000
If a policy is specified but no priority follows, chrt now
errors out:
chrt --rr --pid 10862
chrt: policy SCHED_RR requires a priority argument
Verbose output (-v) still prints the current settings when a
valid policy+priority is provided.
Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
---
schedutils/chrt.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 8fe748f43..d694845ac 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -64,7 +64,7 @@ static void __attribute__((__noreturn__)) usage(void)
" chrt [options] --pid <priority> <pid>\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(_("Get policy:\n"
- " chrt [options] --pid <pid>\n"), out);
+ " chrt --pid <pid>\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(_("Policy options:\n"), out);
@@ -399,6 +399,7 @@ int main(int argc, char **argv)
{
struct chrt_ctl _ctl = { .pid = -1, .policy = SCHED_RR }, *ctl = &_ctl;
int c;
+ bool policy_given = false;
static const struct option longopts[] = {
{ "all-tasks", no_argument, NULL, 'a' },
@@ -435,21 +436,25 @@ int main(int argc, char **argv)
case 'b':
#ifdef SCHED_BATCH
ctl->policy = SCHED_BATCH;
+ policy_given = true;
#endif
break;
case 'd':
#ifdef SCHED_DEADLINE
ctl->policy = SCHED_DEADLINE;
+ policy_given = true;
#endif
break;
case 'e':
#ifdef SCHED_EXT
ctl->policy = SCHED_EXT;
+ policy_given = true;
#endif
break;
case 'f':
ctl->policy = SCHED_FIFO;
+ policy_given = true;
break;
case 'R':
ctl->reset_on_fork = 1;
@@ -457,6 +462,7 @@ int main(int argc, char **argv)
case 'i':
#ifdef SCHED_IDLE
ctl->policy = SCHED_IDLE;
+ policy_given = true;
#endif
break;
case 'm':
@@ -464,6 +470,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
case 'o':
ctl->policy = SCHED_OTHER;
+ policy_given = true;
break;
case 'p':
errno = 0;
@@ -472,6 +479,7 @@ int main(int argc, char **argv)
break;
case 'r':
ctl->policy = SCHED_RR;
+ policy_given = true;
break;
case 'v':
ctl->verbose = 1;
@@ -501,12 +509,21 @@ int main(int argc, char **argv)
errtryhelp(EXIT_FAILURE);
}
- if ((ctl->pid > -1) && (ctl->verbose || argc - optind == 1)) {
+ /* pid exists but priority not given */
+ if (ctl->pid > -1 && argc - optind == 1) {
+ /* Error if a policy was specified but no priority given */
+ if (policy_given)
+ errx(EXIT_FAILURE, ("policy %s requires a priority argument"),
+ get_policy_name(ctl->policy));
+
+ /* If no policy specified, show current settings */
show_sched_info(ctl);
- if (argc - optind == 1)
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
+ if (ctl->verbose)
+ show_sched_info(ctl);
+
errno = 0;
ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
--
2.49.0
next prev parent reply other threads:[~2025-06-21 19:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-21 19:50 [PATCH v4 0/3] chrt: Improve argument handling and allow optional priority Madadi Vineeth Reddy
2025-06-21 19:50 ` [PATCH v4 1/3] chrt: Make minor cleanups in chrt Madadi Vineeth Reddy
2025-06-21 19:50 ` Madadi Vineeth Reddy [this message]
2025-06-21 19:50 ` [PATCH v4 3/3] chrt: Make priority optional for policies that don't use it Madadi Vineeth Reddy
2025-06-24 9:21 ` [PATCH v4 0/3] chrt: Improve argument handling and allow optional priority Karel Zak
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=20250621195048.24900-3-vineethr@linux.ibm.com \
--to=vineethr@linux.ibm.com \
--cc=bensberg@telfort.nl \
--cc=kzak@redhat.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).