Currently, user can only specify cgroup to the tracer's thread the
following ways:
`-C[cgroup]`
`-C[=cgroup]`
`--cgroup[=cgroup]`
If user tries to specify cgroup as `-C [cgroup]` or `--cgroup [cgroup]`,
the parser silently fails and rtla's cgroup is used for the tracer
threads.
To make interface more user-friendly, allow user to specify cgroup in
the aforementioned way, i.e. `-C [cgroup]` and `--cgroup [cgroup]`
Change documentation to reflect this user interface change.
Fixes: a957cbc02531 ("rtla: Add -C cgroup support")
Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
---
Documentation/tools/rtla/common_options.rst | 2 +-
tools/tracing/rtla/src/osnoise_hist.c | 17 +++++++++++------
tools/tracing/rtla/src/osnoise_top.c | 17 +++++++++++------
tools/tracing/rtla/src/timerlat_hist.c | 17 +++++++++++------
tools/tracing/rtla/src/timerlat_top.c | 17 +++++++++++------
5 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst
index 2dc1575210aa..3f292a12b7af 100644
--- a/Documentation/tools/rtla/common_options.rst
+++ b/Documentation/tools/rtla/common_options.rst
@@ -42,7 +42,7 @@
- *f:prio* - use SCHED_FIFO with *prio*;
- *d:runtime[us|ms|s]:period[us|ms|s]* - use SCHED_DEADLINE with *runtime* and *period* in nanoseconds.
-**-C**, **--cgroup**\[*=cgroup*]
+**-C**, **--cgroup** \[*cgroup*]
Set a *cgroup* to the tracer's threads. If the **-C** option is passed without arguments, the tracer's thread will inherit **rtla**'s *cgroup*. Otherwise, the threads will be placed on the *cgroup* passed to the option.
diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c
index 8d579bcee709..298640d92434 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -435,7 +435,7 @@ static void osnoise_hist_usage(char *usage)
" -T/--threshold us: the minimum delta to be considered a noise",
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
- " -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
+ " -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
" -d/--duration time[s|m|h|d]: duration of the session",
" -D/--debug: print debug info",
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
@@ -559,12 +559,17 @@ static struct osnoise_params
break;
case 'C':
params->cgroup = 1;
- if (!optarg) {
- /* will inherit this cgroup */
+ if (optarg) {
+ if (optarg[0] == '=') {
+ /* skip the = */
+ params->cgroup_name = &optarg[1];
+ } else {
+ params->cgroup_name = optarg;
+ }
+ } else if (optind < argc && argv[optind][0] != '-') {
+ params->cgroup_name = argv[optind];
+ } else {
params->cgroup_name = NULL;
- } else if (*optarg == '=') {
- /* skip the = */
- params->cgroup_name = ++optarg;
}
break;
case 'D':
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 2c12780c8aa9..70924242bcdd 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -269,7 +269,7 @@ static void osnoise_top_usage(struct osnoise_params *params, char *usage)
" -T/--threshold us: the minimum delta to be considered a noise",
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
- " -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
+ " -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
" -d/--duration time[s|m|h|d]: duration of the session",
" -D/--debug: print debug info",
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
@@ -394,12 +394,17 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv)
break;
case 'C':
params->cgroup = 1;
- if (!optarg) {
- /* will inherit this cgroup */
+ if (optarg) {
+ if (optarg[0] == '=') {
+ /* skip the = */
+ params->cgroup_name = &optarg[1];
+ } else {
+ params->cgroup_name = optarg;
+ }
+ } else if (optind < argc && argv[optind][0] != '-') {
+ params->cgroup_name = argv[optind];
+ } else {
params->cgroup_name = NULL;
- } else if (*optarg == '=') {
- /* skip the = */
- params->cgroup_name = ++optarg;
}
break;
case 'D':
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 9baea1b251ed..2a48a076d941 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -726,7 +726,7 @@ static void timerlat_hist_usage(char *usage)
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
" -c/--cpus cpus: run the tracer only on the given cpus",
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
- " -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
+ " -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
" -d/--duration time[m|h|d]: duration of the session in seconds",
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
" -D/--debug: print debug info",
@@ -885,12 +885,17 @@ static struct timerlat_params
break;
case 'C':
params->cgroup = 1;
- if (!optarg) {
- /* will inherit this cgroup */
+ if (optarg) {
+ if (optarg[0] == '=') {
+ /* skip the = */
+ params->cgroup_name = &optarg[1];
+ } else {
+ params->cgroup_name = optarg;
+ }
+ } else if (optind < argc && argv[optind][0] != '-') {
+ params->cgroup_name = argv[optind];
+ } else {
params->cgroup_name = NULL;
- } else if (*optarg == '=') {
- /* skip the = */
- params->cgroup_name = ++optarg;
}
break;
case 'b':
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index c80b81c0b4da..e45d9978744c 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -492,7 +492,7 @@ static void timerlat_top_usage(char *usage)
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
" -c/--cpus cpus: run the tracer only on the given cpus",
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
- " -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
+ " -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
" -d/--duration time[s|m|h|d]: duration of the session",
" -D/--debug: print debug info",
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
@@ -650,12 +650,17 @@ static struct timerlat_params
break;
case 'C':
params->cgroup = 1;
- if (!optarg) {
- /* will inherit this cgroup */
+ if (optarg) {
+ if (optarg[0] == '=') {
+ /* skip the = */
+ params->cgroup_name = &optarg[1];
+ } else {
+ params->cgroup_name = optarg;
+ }
+ } else if (optind < argc && argv[optind][0] != '-') {
+ params->cgroup_name = argv[optind];
+ } else {
params->cgroup_name = NULL;
- } else if (*optarg == '=') {
- /* skip the = */
- params->cgroup_name = ++optarg;
}
break;
case 'D':
--
2.48.1
On Tue, 2025-08-12 at 13:21 -0400, Ivan Pravdin wrote: > Currently, user can only specify cgroup to the tracer's thread the > following ways: > > `-C[cgroup]` > `-C[=cgroup]` > `--cgroup[=cgroup]` > > If user tries to specify cgroup as `-C [cgroup]` or `--cgroup [cgroup]`, > the parser silently fails and rtla's cgroup is used for the tracer > threads. > > To make interface more user-friendly, allow user to specify cgroup in > the aforementioned way, i.e. `-C [cgroup]` and `--cgroup [cgroup]` > > Change documentation to reflect this user interface change. I know these are the semantics that --trace implements, but they're rather atypical... especially -C=group. > @@ -559,12 +559,17 @@ static struct osnoise_params > break; > case 'C': > params->cgroup = 1; > - if (!optarg) { > - /* will inherit this cgroup */ > + if (optarg) { > + if (optarg[0] == '=') { > + /* skip the = */ > + params->cgroup_name = &optarg[1]; > + } else { > + params->cgroup_name = optarg; > + } > + } else if (optind < argc && argv[optind][0] != '-') { > + params->cgroup_name = argv[optind]; > + } else { > params->cgroup_name = NULL; > - } else if (*optarg == '=') { > - /* skip the = */ > - params->cgroup_name = ++optarg; If we're going to be consistently using these semantics, we should move this logic into a utility function rather than open-coding it everywhere. Also, theoretically, shouldn't we be advancing optind for the case where that's consumed? Not that it matters much if we don't have positional arguments once the options begin, and if we did, then allowing "--arg optional-thing" would be ambiguous... -Crystal
On Fri, Aug 29, 2025 at 02:12:28PM -0500, Crystal Wood wrote: > On Tue, 2025-08-12 at 13:21 -0400, Ivan Pravdin wrote: > > Currently, user can only specify cgroup to the tracer's thread the > > following ways: > > > > `-C[cgroup]` > > `-C[=cgroup]` > > `--cgroup[=cgroup]` > > > > If user tries to specify cgroup as `-C [cgroup]` or `--cgroup [cgroup]`, > > the parser silently fails and rtla's cgroup is used for the tracer > > threads. > > > > To make interface more user-friendly, allow user to specify cgroup in > > the aforementioned way, i.e. `-C [cgroup]` and `--cgroup [cgroup]` > > > > Change documentation to reflect this user interface change. > > I know these are the semantics that --trace implements, but they're > rather atypical... especially -C=group. The new semantics allow for -C [group] which is the same as -t [filename] that has been fixed for -t/--trace. > > > @@ -559,12 +559,17 @@ static struct osnoise_params > > break; > > case 'C': > > params->cgroup = 1; > > - if (!optarg) { > > - /* will inherit this cgroup */ > > + if (optarg) { > > + if (optarg[0] == '=') { > > + /* skip the = */ > > + params->cgroup_name = &optarg[1]; > > + } else { > > + params->cgroup_name = optarg; > > + } > > + } else if (optind < argc && argv[optind][0] != '-') { > > + params->cgroup_name = argv[optind]; > > + } else { > > params->cgroup_name = NULL; > > - } else if (*optarg == '=') { > > - /* skip the = */ > > - params->cgroup_name = ++optarg; > > If we're going to be consistently using these semantics, we should move > this logic into a utility function rather than open-coding it > everywhere. Sure, I will move it into a utility function in the next version. > Also, theoretically, shouldn't we be advancing optind for the case where > that's consumed? Not that it matters much if we don't have positional > arguments once the options begin, and if we did, then allowing > "--arg optional-thing" would be ambiguous... It does seem that we should advance optind when optional argument is provided. Good catch. I will fix it in the next version. > -Crystal > Ivan Pravdin
© 2016 - 2025 Red Hat, Inc.