]> Gentwo Git Trees - linux/.git/commitdiff
rtla: Fix -C/--cgroup interface
authorIvan Pravdin <ipravdin.official@gmail.com>
Mon, 3 Nov 2025 16:19:06 +0000 (11:19 -0500)
committerTomas Glozar <tglozar@redhat.com>
Fri, 21 Nov 2025 09:30:27 +0000 (10:30 +0100)
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]`.

Refactor identical logic between -t/--trace and -C/--cgroup into a
common function.

Change documentation to reflect this user interface change.

Fixes: a957cbc02531 ("rtla: Add -C cgroup support")
Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com>
Reviewed-by: Tomas Glozar <tglozar@redhat.com>
Link: https://lore.kernel.org/r/16132f1565cf5142b5fbd179975be370b529ced7.1762186418.git.ipravdin.official@gmail.com
[ use capital letter in subject, as required by tracing subsystem ]
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Documentation/tools/rtla/common_options.rst
tools/tracing/rtla/src/osnoise_hist.c
tools/tracing/rtla/src/osnoise_top.c
tools/tracing/rtla/src/timerlat_hist.c
tools/tracing/rtla/src/timerlat_top.c
tools/tracing/rtla/src/utils.c
tools/tracing/rtla/src/utils.h

index 77ef35d3f831716b51034ce24c9ea4d23a1469ab..edc8e850f5d019b07a7ac7de1568fddbbc76b7a0 100644 (file)
@@ -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.
 
index 1d841a3056bc9ed788281f4af3fd5f991e351873..1d06ea47b663c5b9d9c7aaaea7215dd63293477b 100644 (file)
@@ -414,9 +414,9 @@ static void osnoise_hist_usage(void)
        static const char * const msg[] = {
                "",
                "  usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
-               "         [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
+               "         [-T us] [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
                "         [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\",
-               "         [--no-index] [--with-zeros] [-C[=cgroup_name]] [--warm-up]",
+               "         [--no-index] [--with-zeros] [-C [cgroup_name]] [--warm-up]",
                "",
                "         -h/--help: print this menu",
                "         -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -427,10 +427,10 @@ static void osnoise_hist_usage(void)
                "         -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]",
+               "         -t/--trace [file]: save the stopped trace to [file|osnoise_trace.txt]",
                "         -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
                "            --filter <filter>: enable a trace event filter to the previous -e event",
                "            --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -551,13 +551,7 @@ static struct common_params
                        break;
                case 'C':
                        params->common.cgroup = 1;
-                       if (!optarg) {
-                               /* will inherit this cgroup */
-                               params->common.cgroup_name = NULL;
-                       } else if (*optarg == '=') {
-                               /* skip the = */
-                               params->common.cgroup_name = ++optarg;
-                       }
+                       params->common.cgroup_name = parse_optional_arg(argc, argv);
                        break;
                case 'D':
                        config_debug = 1;
@@ -619,14 +613,8 @@ static struct common_params
                        params->threshold = get_llong_from_str(optarg);
                        break;
                case 't':
-                       if (optarg) {
-                               if (optarg[0] == '=')
-                                       trace_output = &optarg[1];
-                               else
-                                       trace_output = &optarg[0];
-                       } else if (optind < argc && argv[optind][0] != '0')
-                               trace_output = argv[optind];
-                       else
+                       trace_output = parse_optional_arg(argc, argv);
+                       if (!trace_output)
                                trace_output = "osnoise_trace.txt";
                        break;
                case '0': /* no header */
index de8e26d7c68be743edacd44a81e7c8b2611f2773..cac60e4c267e80b211c517beadb8e946e7263027 100644 (file)
@@ -261,8 +261,8 @@ static void osnoise_top_usage(struct osnoise_params *params)
 
        static const char * const msg[] = {
                " [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
-               "         [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
-               "         [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]] [--warm-up s]",
+               "         [-T us] [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
+               "         [-c cpu-list] [-H cpu-list] [-P priority] [-C [cgroup_name]] [--warm-up s]",
                "",
                "         -h/--help: print this menu",
                "         -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -273,10 +273,10 @@ static void osnoise_top_usage(struct osnoise_params *params)
                "         -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]",
+               "         -t/--trace [file]: save the stopped trace to [file|osnoise_trace.txt]",
                "         -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
                "            --filter <filter>: enable a trace event filter to the previous -e event",
                "            --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -397,13 +397,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
                        break;
                case 'C':
                        params->common.cgroup = 1;
-                       if (!optarg) {
-                               /* will inherit this cgroup */
-                               params->common.cgroup_name = NULL;
-                       } else if (*optarg == '=') {
-                               /* skip the = */
-                               params->common.cgroup_name = ++optarg;
-                       }
+                       params->common.cgroup_name = parse_optional_arg(argc, argv);
                        break;
                case 'D':
                        config_debug = 1;
@@ -459,14 +453,8 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
                        params->common.stop_total_us = get_llong_from_str(optarg);
                        break;
                case 't':
-                       if (optarg) {
-                               if (optarg[0] == '=')
-                                       trace_output = &optarg[1];
-                               else
-                                       trace_output = &optarg[0];
-                       } else if (optind < argc && argv[optind][0] != '-')
-                               trace_output = argv[optind];
-                       else
+                       trace_output = parse_optional_arg(argc, argv);
+                       if (!trace_output)
                                trace_output = "osnoise_trace.txt";
                        break;
                case 'T':
index 1b505531ad3bf877ea239f7cce1f681b91ac864d..961aa969c003524f041bb23a1a4a30e7fae649bd 100644 (file)
@@ -701,9 +701,9 @@ static void timerlat_hist_usage(void)
        char *msg[] = {
                "",
                "  usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
-               "         [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
+               "         [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
                "         [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
-               "         [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
+               "         [--no-index] [--with-zeros] [--dma-latency us] [-C [cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
                "         [--warm-up s] [--deepest-idle-state n]",
                "",
                "         -h/--help: print this menu",
@@ -714,11 +714,11 @@ static void timerlat_hist_usage(void)
                "         -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",
-               "         -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
+               "         -t/--trace [file]: save the stopped trace to [file|timerlat_trace.txt]",
                "         -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
                "            --filter <filter>: enable a trace event filter to the previous -e event",
                "            --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -864,13 +864,7 @@ static struct common_params
                        break;
                case 'C':
                        params->common.cgroup = 1;
-                       if (!optarg) {
-                               /* will inherit this cgroup */
-                               params->common.cgroup_name = NULL;
-                       } else if (*optarg == '=') {
-                               /* skip the = */
-                               params->common.cgroup_name = ++optarg;
-                       }
+                       params->common.cgroup_name = parse_optional_arg(argc, argv);
                        break;
                case 'b':
                        params->common.hist.bucket_size = get_llong_from_str(optarg);
@@ -939,14 +933,8 @@ static struct common_params
                        params->common.stop_total_us = get_llong_from_str(optarg);
                        break;
                case 't':
-                       if (optarg) {
-                               if (optarg[0] == '=')
-                                       trace_output = &optarg[1];
-                               else
-                                       trace_output = &optarg[0];
-                       } else if (optind < argc && argv[optind][0] != '-')
-                               trace_output = argv[optind];
-                       else
+                       trace_output = parse_optional_arg(argc, argv);
+                       if (!trace_output)
                                trace_output = "timerlat_trace.txt";
                        break;
                case 'u':
index 67a5b6ab78a6f220a0f692e882ea76f113661467..213356a5be522c22e6f04969d2823c09e6633cd3 100644 (file)
@@ -481,8 +481,8 @@ static void timerlat_top_usage(void)
        static const char *const msg[] = {
                "",
                "  usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
-               "         [[-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
-               "         [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s] [--deepest-idle-state n]",
+               "         [[-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
+               "         [-P priority] [--dma-latency us] [--aa-only us] [-C [cgroup_name]] [-u|-k] [--warm-up s] [--deepest-idle-state n]",
                "",
                "         -h/--help: print this menu",
                "         -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -493,11 +493,11 @@ static void timerlat_top_usage(void)
                "         -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)",
-               "         -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
+               "         -t/--trace [file]: save the stopped trace to [file|timerlat_trace.txt]",
                "         -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
                "            --filter <command>: enable a trace event filter to the previous -e event",
                "            --trigger <command>: enable a trace event trigger to the previous -e event",
@@ -642,13 +642,7 @@ static struct common_params
                        break;
                case 'C':
                        params->common.cgroup = 1;
-                       if (!optarg) {
-                               /* will inherit this cgroup */
-                               params->common.cgroup_name = NULL;
-                       } else if (*optarg == '=') {
-                               /* skip the = */
-                               params->common.cgroup_name = ++optarg;
-                       }
+                       params->common.cgroup_name = optarg;
                        break;
                case 'D':
                        config_debug = 1;
@@ -707,14 +701,8 @@ static struct common_params
                        params->common.stop_total_us = get_llong_from_str(optarg);
                        break;
                case 't':
-                       if (optarg) {
-                               if (optarg[0] == '=')
-                                       trace_output = &optarg[1];
-                               else
-                                       trace_output = &optarg[0];
-                       } else if (optind < argc && argv[optind][0] != '-')
-                               trace_output = argv[optind];
-                       else
+                       trace_output = parse_optional_arg(argc, argv);
+                       if (!trace_output)
                                trace_output = "timerlat_trace.txt";
                        break;
                case 'u':
index 54334c676a2290788dc552f0ca19c64b3a7f470b..9cf5a0098e9aa9278cb620ce963dc7338a5bd22f 100644 (file)
@@ -974,3 +974,29 @@ int auto_house_keeping(cpu_set_t *monitored_cpus)
 
        return 1;
 }
+
+/**
+ * parse_optional_arg - Parse optional argument value
+ *
+ * Parse optional argument value, which can be in the form of:
+ * -sarg, -s/--long=arg, -s/--long arg
+ *
+ * Returns arg value if found, NULL otherwise.
+ */
+char *parse_optional_arg(int argc, char **argv)
+{
+       if (optarg) {
+               if (optarg[0] == '=') {
+                       /* skip the = */
+                       return &optarg[1];
+               } else {
+                       return optarg;
+               }
+       /* parse argument of form -s [arg] and --long [arg]*/
+       } else if (optind < argc && argv[optind][0] != '-') {
+               /* consume optind */
+               return argv[optind++];
+       } else {
+               return NULL;
+       }
+}
index 1be095f9a7e6287f057403607707f9e1bb8e9c31..091df4ba45877313ac3ea7bf76a25fc8ba8f3b33 100644 (file)
@@ -25,6 +25,7 @@ long parse_seconds_duration(char *val);
 void get_duration(time_t start_time, char *output, int output_size);
 
 int parse_cpu_list(char *cpu_list, char **monitored_cpus);
+char *parse_optional_arg(int argc, char **argv);
 long long get_llong_from_str(char *start);
 
 static inline void