From nobody Tue Dec 2 02:05:05 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3ECB30FC3A for ; Thu, 20 Nov 2025 23:26:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681196; cv=none; b=XJtJU9GDUXXZTAEUVJwHYBtar87/ReIOcqpnTCKuB1FEXRToFS1FTQYmURRoOU4kmseImDV6K7E4QyWrKAjY1ghCLn+zHVTBuVgC3pDGroFRYPIg33rx7kg9ape3v13+Qyen30OBQQU8NR22cBSEfe5g6T4UMxCMpcFhNF6YAgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763681196; c=relaxed/simple; bh=5NpVl0L0hQCXyMFazN7nywqgD6DiVGnr6UgljlU/hcM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=C/h9U5vRzLgkaIWU0VzlseEnx/MjCd4cxPxdZcLnw6r3+IRcyXYxCOFsnbHabGYLC5jUCY9snDc7V21+XTDk5p/JXIRTPMS8WTBHTXSwCyNSIfRVLg1mwRXOFOP2a0sSCFQqRC1O5dijU39Q+NXsicVQx/2MUx4bprYwtFvCuqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X2osEocB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X2osEocB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8108FC4CEF1; Thu, 20 Nov 2025 23:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763681196; bh=5NpVl0L0hQCXyMFazN7nywqgD6DiVGnr6UgljlU/hcM=; h=Date:From:To:Cc:Subject:References:From; b=X2osEocB4Sjl+gfaln82+NVvqlRhmwwZU7Kbaq3X/wa7oA0i0xShsEj9CV86T6ycT WXNjZj19xce3FD+Emc9u4kNKzafA3iEV7FRBioIwZUPpz7USGOce8UjUqzuCSRlG3R lPpCK6t+VPTd125nqqn+TPm7fQOr6Q9lG7O8doueOTJuROeb8LLtq/pko4qClZNLrL gvcf2uBcZrbrvda/dogRuEvuGCgstycszNOqHQp4Pnf0Kk8VOIbdb+tVzMWm7duOOF SZkZt7gxFMF+lQY0EtHseL5VMjgDamfoT84EpfFoDqgMY6WFB2tkzL/0ifQl4CjHay /8HDn1s3188Jg== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1vME3R-000000041wh-2WXB; Thu, 20 Nov 2025 18:27:09 -0500 Message-ID: <20251120232709.461382606@kernel.org> User-Agent: quilt/0.68 Date: Thu, 20 Nov 2025 18:23:36 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , Ivan Pravdin Subject: [for-next][PATCH 13/16] rtla: Fix -C/--cgroup interface References: <20251120232323.271532418@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ivan Pravdin Currently, user can only specify cgroup to the tracer's thread the following ways: `-C[cgroup]` `-C[=3Dcgroup]` `--cgroup[=3Dcgroup]` 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 Reviewed-by: Tomas Glozar Link: https://lore.kernel.org/r/16132f1565cf5142b5fbd179975be370b529ced7.17= 62186418.git.ipravdin.official@gmail.com [ use capital letter in subject, as required by tracing subsystem ] Signed-off-by: Tomas Glozar --- Documentation/tools/rtla/common_options.rst | 2 +- tools/tracing/rtla/src/osnoise_hist.c | 26 ++++++--------------- tools/tracing/rtla/src/osnoise_top.c | 26 ++++++--------------- tools/tracing/rtla/src/timerlat_hist.c | 26 ++++++--------------- tools/tracing/rtla/src/timerlat_top.c | 26 ++++++--------------- tools/tracing/rtla/src/utils.c | 26 +++++++++++++++++++++ tools/tracing/rtla/src/utils.h | 1 + 7 files changed, 56 insertions(+), 77 deletions(-) diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/to= ols/rtla/common_options.rst index 77ef35d3f831..edc8e850f5d0 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. =20 -**-C**, **--cgroup**\[*=3Dcgroup*] +**-C**, **--cgroup** \[*cgroup*] =20 Set a *cgroup* to the tracer's threads. If the **-C** option is pa= ssed without arguments, the tracer's thread will inherit **rtla**'s *cgroup= *. Otherwise, the threads will be placed on the *cgroup* passed to the opti= on. =20 diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src= /osnoise_hist.c index 1d841a3056bc..1d06ea47b663 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -414,9 +414,9 @@ static void osnoise_hist_usage(void) static const char * const msg[] =3D { "", " 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 ] [--trigger <= trigger>] \\", + " [-T us] [-t [file]] [-e sys[:event]] [--filter ] [--trigger = ] \\", " [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header= ] [--no-summary] \\", - " [--no-index] [--with-zeros] [-C[=3Dcgroup_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 argumen= t 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[=3Dcgroup_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 : enable the in the trace instance= , multiple -e are allowed", " --filter : enable a trace event filter to the previous -e= event", " --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 =3D 1; - if (!optarg) { - /* will inherit this cgroup */ - params->common.cgroup_name =3D NULL; - } else if (*optarg =3D=3D '=3D') { - /* skip the =3D */ - params->common.cgroup_name =3D ++optarg; - } + params->common.cgroup_name =3D parse_optional_arg(argc, argv); break; case 'D': config_debug =3D 1; @@ -619,14 +613,8 @@ static struct common_params params->threshold =3D get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] =3D=3D '=3D') - trace_output =3D &optarg[1]; - else - trace_output =3D &optarg[0]; - } else if (optind < argc && argv[optind][0] !=3D '0') - trace_output =3D argv[optind]; - else + trace_output =3D parse_optional_arg(argc, argv); + if (!trace_output) trace_output =3D "osnoise_trace.txt"; break; case '0': /* no header */ diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/= osnoise_top.c index de8e26d7c68b..cac60e4c267e 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -261,8 +261,8 @@ static void osnoise_top_usage(struct osnoise_params *pa= rams) =20 static const char * const msg[] =3D { " [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", - " [-T us] [-t[file]] [-e sys[:event]] [--filter ] [--trigger <= trigger>] \\", - " [-c cpu-list] [-H cpu-list] [-P priority] [-C[=3Dcgroup_name]] [--wa= rm-up s]", + " [-T us] [-t [file]] [-e sys[:event]] [--filter ] [--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 argumen= t 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[=3Dcgroup_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 : enable the in the trace instance= , multiple -e are allowed", " --filter : enable a trace event filter to the previous -e= event", " --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 =3D 1; - if (!optarg) { - /* will inherit this cgroup */ - params->common.cgroup_name =3D NULL; - } else if (*optarg =3D=3D '=3D') { - /* skip the =3D */ - params->common.cgroup_name =3D ++optarg; - } + params->common.cgroup_name =3D parse_optional_arg(argc, argv); break; case 'D': config_debug =3D 1; @@ -459,14 +453,8 @@ struct common_params *osnoise_top_parse_args(int argc,= char **argv) params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] =3D=3D '=3D') - trace_output =3D &optarg[1]; - else - trace_output =3D &optarg[0]; - } else if (optind < argc && argv[optind][0] !=3D '-') - trace_output =3D argv[optind]; - else + trace_output =3D parse_optional_arg(argc, argv); + if (!trace_output) trace_output =3D "osnoise_trace.txt"; break; case 'T': diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/sr= c/timerlat_hist.c index 1b505531ad3b..961aa969c003 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -701,9 +701,9 @@ static void timerlat_hist_usage(void) char *msg[] =3D { "", " 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 ] [--trigger ] [-c cpu-list] [-H cpu-list]\\", + " [-t [file]] [-e sys[:event]] [--filter ] [--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[=3Dcgroup_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 i= s 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[=3Dcgroup_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 conditi= ons 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.tx= t]", " -e/--event : enable the in the trace instance= , multiple -e are allowed", " --filter : enable a trace event filter to the previous -e= event", " --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 =3D 1; - if (!optarg) { - /* will inherit this cgroup */ - params->common.cgroup_name =3D NULL; - } else if (*optarg =3D=3D '=3D') { - /* skip the =3D */ - params->common.cgroup_name =3D ++optarg; - } + params->common.cgroup_name =3D parse_optional_arg(argc, argv); break; case 'b': params->common.hist.bucket_size =3D get_llong_from_str(optarg); @@ -939,14 +933,8 @@ static struct common_params params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] =3D=3D '=3D') - trace_output =3D &optarg[1]; - else - trace_output =3D &optarg[0]; - } else if (optind < argc && argv[optind][0] !=3D '-') - trace_output =3D argv[optind]; - else + trace_output =3D parse_optional_arg(argc, argv); + if (!trace_output) trace_output =3D "timerlat_trace.txt"; break; case 'u': diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src= /timerlat_top.c index 67a5b6ab78a6..213356a5be52 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -481,8 +481,8 @@ static void timerlat_top_usage(void) static const char *const msg[] =3D { "", " 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 ] [--trigger ] [-c cpu-list] [-H cpu-list]\\", - " [-P priority] [--dma-latency us] [--aa-only us] [-C[=3Dcgroup_name]]= [-u|-k] [--warm-up s] [--deepest-idle-state n]", + " [[-t [file]] [-e sys[:event]] [--filter ] [--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 argumen= t 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 i= s 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[=3Dcgroup_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 conditi= ons 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.tx= t]", " -e/--event : enable the in the trace instance= , multiple -e are allowed", " --filter : enable a trace event filter to the previous -= e event", " --trigger : enable a trace event trigger to the previous= -e event", @@ -642,13 +642,7 @@ static struct common_params break; case 'C': params->common.cgroup =3D 1; - if (!optarg) { - /* will inherit this cgroup */ - params->common.cgroup_name =3D NULL; - } else if (*optarg =3D=3D '=3D') { - /* skip the =3D */ - params->common.cgroup_name =3D ++optarg; - } + params->common.cgroup_name =3D optarg; break; case 'D': config_debug =3D 1; @@ -707,14 +701,8 @@ static struct common_params params->common.stop_total_us =3D get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] =3D=3D '=3D') - trace_output =3D &optarg[1]; - else - trace_output =3D &optarg[0]; - } else if (optind < argc && argv[optind][0] !=3D '-') - trace_output =3D argv[optind]; - else + trace_output =3D parse_optional_arg(argc, argv); + if (!trace_output) trace_output =3D "timerlat_trace.txt"; break; case 'u': diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index 54334c676a22..9cf5a0098e9a 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -974,3 +974,29 @@ int auto_house_keeping(cpu_set_t *monitored_cpus) =20 return 1; } + +/** + * parse_optional_arg - Parse optional argument value + * + * Parse optional argument value, which can be in the form of: + * -sarg, -s/--long=3Darg, -s/--long arg + * + * Returns arg value if found, NULL otherwise. + */ +char *parse_optional_arg(int argc, char **argv) +{ + if (optarg) { + if (optarg[0] =3D=3D '=3D') { + /* skip the =3D */ + return &optarg[1]; + } else { + return optarg; + } + /* parse argument of form -s [arg] and --long [arg]*/ + } else if (optind < argc && argv[optind][0] !=3D '-') { + /* consume optind */ + return argv[optind++]; + } else { + return NULL; + } +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 1be095f9a7e6..091df4ba4587 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -25,6 +25,7 @@ long parse_seconds_duration(char *val); void get_duration(time_t start_time, char *output, int output_size); =20 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); =20 static inline void --=20 2.51.0