* [PATCH v3 0/3] rtla: fix cgroup and trace options parsing
@ 2025-09-08 2:05 Ivan Pravdin
2025-09-08 2:05 ` [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse Ivan Pravdin
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Ivan Pravdin @ 2025-09-08 2:05 UTC (permalink / raw)
To: rostedt, tglozar, linux-trace-kernel, linux-kernel; +Cc: Ivan Pravdin
This series fixes 3 issue in rtla timerlat and osnoise parsing.
1. Fix buffer overflow when using --on-threshold option. Currently
passing `--on-threshold trace` causes rtla timerlat to segfault.
First patch addresses this issue.
2. Make -C/--cgroup option more user-friendly. Currently rtla timerlat
and osnoise parses does not allow to specify tracer's threads cgroup
name as `-C [cgroup]` or `--cgroup [cgroup]`. Second patch fixes this
by allowing users to specify cgroup in the aforementioned manner.
3. When specifying `-t/--trace` before `-a/--auto`, trace filename is
override to default <osnoise|timerlat>_trace.txt. For example, when
running rtla as
`rtla timerlat top -t custom_file.txt -a 100`
when the threshold is reached, timerlat_trace.txt file is created
instead of specified custom_file.txt. Third patch addresses this
issue.
changes v2 -> v3:
- Combined common logic into a utility function to parse optional
argument value
- Removed change that removed `clear_terminal`
changes v1 -> v2:
- Moved removing clear_terminal from `fix -C/--cgroup interface`
patch to `fix -a overriding -t argument` patch
- Added clarification why to remove clear_terminal
- Added `Fixes:` tag to the `fix -C/--cgroup interface` patch
v2: https://lore.kernel.org/all/cover.1755018581.git.ipravdin.official@gmail.com/
v1: https://lore.kernel.org/all/cover.1755014784.git.ipravdin.official@gmail.com/
Ivan Pravdin (3):
rtla: fix buffer overflow in actions_parse
rtla: fix -C/--cgroup interface
rtla: fix -a overriding -t argument
Documentation/tools/rtla/common_options.rst | 2 +-
tools/tracing/rtla/src/actions.c | 2 +-
tools/tracing/rtla/src/osnoise_hist.c | 29 +++++++--------------
tools/tracing/rtla/src/osnoise_top.c | 29 +++++++--------------
tools/tracing/rtla/src/timerlat_hist.c | 29 +++++++--------------
tools/tracing/rtla/src/timerlat_top.c | 29 +++++++--------------
tools/tracing/rtla/src/utils.c | 26 ++++++++++++++++++
tools/tracing/rtla/src/utils.h | 1 +
8 files changed, 65 insertions(+), 82 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse 2025-09-08 2:05 [PATCH v3 0/3] rtla: fix cgroup and trace options parsing Ivan Pravdin @ 2025-09-08 2:05 ` Ivan Pravdin 2025-09-26 14:32 ` Tomas Glozar 2025-09-08 2:05 ` [PATCH v3 2/3] rtla: fix -C/--cgroup interface Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 3/3] rtla: fix -a overriding -t argument Ivan Pravdin 2 siblings, 1 reply; 9+ messages in thread From: Ivan Pravdin @ 2025-09-08 2:05 UTC (permalink / raw) To: rostedt, tglozar, linux-trace-kernel, linux-kernel; +Cc: Ivan Pravdin Currently, tests 3 and 13-22 in tests/timerlat.t fail with error: *** buffer overflow detected ***: terminated timeout: the monitored command dumped core The result of running `sudo make check` is tests/timerlat.t (Wstat: 0 Tests: 22 Failed: 11) Failed tests: 3, 13-22 Files=3, Tests=34, 140 wallclock secs ( 0.07 usr 0.01 sys + 27.63 cusr 27.96 csys = 55.67 CPU) Result: FAIL Fix buffer overflow in actions_parse to avoid this error. After this change, the tests results are tests/hwnoise.t ... ok tests/osnoise.t ... ok tests/timerlat.t .. ok All tests successful. Files=3, Tests=34, 186 wallclock secs ( 0.06 usr 0.01 sys + 41.10 cusr 44.38 csys = 85.55 CPU) Result: PASS Fixes: 6ea082b171e0 ("rtla/timerlat: Add action on threshold feature") Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> Reviewed-by: Tomas Glozar <tglozar@redhat.com> --- tools/tracing/rtla/src/actions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/actions.c index aaf0808125d7..eab51c0c0ce2 100644 --- a/tools/tracing/rtla/src/actions.c +++ b/tools/tracing/rtla/src/actions.c @@ -131,7 +131,7 @@ actions_parse(struct actions *self, const char *trigger) { enum action_type type = ACTION_NONE; char *token; - char trigger_c[strlen(trigger)]; + char trigger_c[strlen(trigger) + 1]; /* For ACTION_SIGNAL */ int signal = 0, pid = 0; -- 2.48.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse 2025-09-08 2:05 ` [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse Ivan Pravdin @ 2025-09-26 14:32 ` Tomas Glozar 2025-09-27 9:59 ` Steven Rostedt 2025-09-29 15:13 ` Ivan Pravdin 0 siblings, 2 replies; 9+ messages in thread From: Tomas Glozar @ 2025-09-26 14:32 UTC (permalink / raw) To: rostedt; +Cc: Ivan Pravdin, linux-trace-kernel, linux-kernel Steven, po 8. 9. 2025 v 4:06 odesílatel Ivan Pravdin <ipravdin.official@gmail.com> napsal: > > Currently, tests 3 and 13-22 in tests/timerlat.t fail with error: > > *** buffer overflow detected ***: terminated > timeout: the monitored command dumped core > > The result of running `sudo make check` is > > tests/timerlat.t (Wstat: 0 Tests: 22 Failed: 11) > Failed tests: 3, 13-22 > Files=3, Tests=34, 140 wallclock secs ( 0.07 usr 0.01 sys + 27.63 cusr > 27.96 csys = 55.67 CPU) > Result: FAIL > > Fix buffer overflow in actions_parse to avoid this error. After this > change, the tests results are > > tests/hwnoise.t ... ok > tests/osnoise.t ... ok > tests/timerlat.t .. ok > All tests successful. > Files=3, Tests=34, 186 wallclock secs ( 0.06 usr 0.01 sys + 41.10 cusr > 44.38 csys = 85.55 CPU) > Result: PASS > > Fixes: 6ea082b171e0 ("rtla/timerlat: Add action on threshold feature") > Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> > Reviewed-by: Tomas Glozar <tglozar@redhat.com> > --- > tools/tracing/rtla/src/actions.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Could you take this simple fix? (Might require tweaking the starting letter "fix" -> "Fix", I don't care that much about it, but as you said, tracing requires capital letters there :) ) The rest of the patchset conflicts with [1] but this one doesn't and is also more important. [1] https://patchwork.kernel.org/project/linux-trace-kernel/list/?series=999703 Tomas ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse 2025-09-26 14:32 ` Tomas Glozar @ 2025-09-27 9:59 ` Steven Rostedt 2025-09-29 15:13 ` Ivan Pravdin 1 sibling, 0 replies; 9+ messages in thread From: Steven Rostedt @ 2025-09-27 9:59 UTC (permalink / raw) To: Tomas Glozar; +Cc: Ivan Pravdin, linux-trace-kernel, linux-kernel On Fri, 26 Sep 2025 16:32:52 +0200 Tomas Glozar <tglozar@redhat.com> wrote: > Could you take this simple fix? (Might require tweaking the starting > letter "fix" -> "Fix", I don't care that much about it, but as you > said, tracing requires capital letters there :) ) Yeah, I can update it. > > The rest of the patchset conflicts with [1] but this one doesn't and > is also more important. > > [1] https://patchwork.kernel.org/project/linux-trace-kernel/list/?series=999703 Should I expect a v4 on patches 2 and 3? -- Steve ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse 2025-09-26 14:32 ` Tomas Glozar 2025-09-27 9:59 ` Steven Rostedt @ 2025-09-29 15:13 ` Ivan Pravdin 1 sibling, 0 replies; 9+ messages in thread From: Ivan Pravdin @ 2025-09-29 15:13 UTC (permalink / raw) To: Tomas Glozar, rostedt; +Cc: linux-trace-kernel, linux-kernel On Fri, Sep 26, 2025 at 04:32:52PM +0200, Tomas Glozar wrote: > Steven, > > po 8. 9. 2025 v 4:06 odesílatel Ivan Pravdin > <ipravdin.official@gmail.com> napsal: > > > > Currently, tests 3 and 13-22 in tests/timerlat.t fail with error: > > > > *** buffer overflow detected ***: terminated > > timeout: the monitored command dumped core > > > > The result of running `sudo make check` is > > > > tests/timerlat.t (Wstat: 0 Tests: 22 Failed: 11) > > Failed tests: 3, 13-22 > > Files=3, Tests=34, 140 wallclock secs ( 0.07 usr 0.01 sys + 27.63 cusr > > 27.96 csys = 55.67 CPU) > > Result: FAIL > > > > Fix buffer overflow in actions_parse to avoid this error. After this > > change, the tests results are > > > > tests/hwnoise.t ... ok > > tests/osnoise.t ... ok > > tests/timerlat.t .. ok > > All tests successful. > > Files=3, Tests=34, 186 wallclock secs ( 0.06 usr 0.01 sys + 41.10 cusr > > 44.38 csys = 85.55 CPU) > > Result: PASS > > > > Fixes: 6ea082b171e0 ("rtla/timerlat: Add action on threshold feature") > > Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> > > Reviewed-by: Tomas Glozar <tglozar@redhat.com> > > --- > > tools/tracing/rtla/src/actions.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > Could you take this simple fix? (Might require tweaking the starting > letter "fix" -> "Fix", I don't care that much about it, but as you > said, tracing requires capital letters there :) ) > > The rest of the patchset conflicts with [1] but this one doesn't and > is also more important. > > [1] https://patchwork.kernel.org/project/linux-trace-kernel/list/?series=999703 Thanks Tomas. I will monitor it and rebase my patches once it is merged. > > Tomas > Ivan Pravdin ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 2/3] rtla: fix -C/--cgroup interface 2025-09-08 2:05 [PATCH v3 0/3] rtla: fix cgroup and trace options parsing Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse Ivan Pravdin @ 2025-09-08 2:05 ` Ivan Pravdin 2025-09-11 11:29 ` Tomas Glozar 2025-09-08 2:05 ` [PATCH v3 3/3] rtla: fix -a overriding -t argument Ivan Pravdin 2 siblings, 1 reply; 9+ messages in thread From: Ivan Pravdin @ 2025-09-08 2:05 UTC (permalink / raw) To: rostedt, tglozar, linux-trace-kernel, linux-kernel; +Cc: Ivan Pravdin 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> --- 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/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..1dc39de79d78 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -422,9 +422,9 @@ static void osnoise_hist_usage(char *usage) 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", @@ -435,10 +435,10 @@ 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]", + " -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", @@ -559,13 +559,7 @@ static struct osnoise_params break; case 'C': params->cgroup = 1; - if (!optarg) { - /* will inherit this cgroup */ - params->cgroup_name = NULL; - } else if (*optarg == '=') { - /* skip the = */ - params->cgroup_name = ++optarg; - } + params->cgroup_name = parse_optional_arg(argc, argv); break; case 'D': config_debug = 1; @@ -630,14 +624,8 @@ static struct osnoise_params params->threshold = get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] == '=') - params->trace_output = &optarg[1]; - else - params->trace_output = &optarg[0]; - } else if (optind < argc && argv[optind][0] != '0') - params->trace_output = argv[optind]; - else + params->trace_output = parse_optional_arg(argc, argv); + if (!params->trace_output) params->trace_output = "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 2c12780c8aa9..b3e161536ed8 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -257,8 +257,8 @@ static void osnoise_top_usage(struct osnoise_params *params, char *usage) 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", @@ -269,10 +269,10 @@ 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]", + " -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", @@ -394,13 +394,7 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv) break; case 'C': params->cgroup = 1; - if (!optarg) { - /* will inherit this cgroup */ - params->cgroup_name = NULL; - } else if (*optarg == '=') { - /* skip the = */ - params->cgroup_name = ++optarg; - } + params->cgroup_name = parse_optional_arg(argc, argv); break; case 'D': config_debug = 1; @@ -460,14 +454,8 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv) params->stop_total_us = get_llong_from_str(optarg); break; case 't': - if (optarg) { - if (optarg[0] == '=') - params->trace_output = &optarg[1]; - else - params->trace_output = &optarg[0]; - } else if (optind < argc && argv[optind][0] != '-') - params->trace_output = argv[optind]; - else + params->trace_output = parse_optional_arg(argc, argv); + if (!params->trace_output) params->trace_output = "osnoise_trace.txt"; break; case 'T': diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 9baea1b251ed..ad713dafa3c3 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -713,9 +713,9 @@ static void timerlat_hist_usage(char *usage) 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", @@ -726,11 +726,11 @@ 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", - " -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", @@ -885,13 +885,7 @@ static struct timerlat_params break; case 'C': params->cgroup = 1; - if (!optarg) { - /* will inherit this cgroup */ - params->cgroup_name = NULL; - } else if (*optarg == '=') { - /* skip the = */ - params->cgroup_name = ++optarg; - } + params->cgroup_name = parse_optional_arg(argc, argv); break; case 'b': params->bucket_size = get_llong_from_str(optarg); @@ -962,14 +956,8 @@ static struct timerlat_params params->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': diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index c80b81c0b4da..7f1885018624 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -480,8 +480,8 @@ static void timerlat_top_usage(char *usage) 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", @@ -492,11 +492,11 @@ 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)", - " -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", @@ -650,13 +650,7 @@ static struct timerlat_params break; case 'C': params->cgroup = 1; - if (!optarg) { - /* will inherit this cgroup */ - params->cgroup_name = NULL; - } else if (*optarg == '=') { - /* skip the = */ - params->cgroup_name = ++optarg; - } + params->cgroup_name = optarg; break; case 'D': config_debug = 1; @@ -719,14 +713,8 @@ static struct timerlat_params params->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': diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index d6ab15dcb490..bd5f34b44648 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -959,3 +959,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; + } +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index a2a6f89f342d..d8d83abf0f0d 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -24,6 +24,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 -- 2.48.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/3] rtla: fix -C/--cgroup interface 2025-09-08 2:05 ` [PATCH v3 2/3] rtla: fix -C/--cgroup interface Ivan Pravdin @ 2025-09-11 11:29 ` Tomas Glozar 0 siblings, 0 replies; 9+ messages in thread From: Tomas Glozar @ 2025-09-11 11:29 UTC (permalink / raw) To: Ivan Pravdin; +Cc: rostedt, linux-trace-kernel, linux-kernel po 8. 9. 2025 v 4:06 odesílatel Ivan Pravdin <ipravdin.official@gmail.com> napsal: > > Refactor identical logic between -t/--trace and -C/--cgroup into a > common function. > > Change documentation to reflect this user interface change. > Looks good to me, thank you for implementing the refactoring, now that the logic is shared. Reviewed-by: Tomas Glozar <tglozar@redhat.com> Tomas ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 3/3] rtla: fix -a overriding -t argument 2025-09-08 2:05 [PATCH v3 0/3] rtla: fix cgroup and trace options parsing Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 2/3] rtla: fix -C/--cgroup interface Ivan Pravdin @ 2025-09-08 2:05 ` Ivan Pravdin 2025-09-11 11:32 ` Tomas Glozar 2 siblings, 1 reply; 9+ messages in thread From: Ivan Pravdin @ 2025-09-08 2:05 UTC (permalink / raw) To: rostedt, tglozar, linux-trace-kernel, linux-kernel; +Cc: Ivan Pravdin When running rtla as `rtla <timerlat|osnoise> <top|hist> -t custom_file.txt -a 100` -a options override trace output filename specified by -t option. Running the command above will create <timerlat|osnoise>_trace.txt file instead of custom_file.txt. Fix this by making sure that -a option does not override trace output filename even if it's passed after trace output filename is specified. Fixes: 173a3b014827 ("rtla/timerlat: Add the automatic trace option") Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> --- tools/tracing/rtla/src/osnoise_hist.c | 3 ++- tools/tracing/rtla/src/osnoise_top.c | 3 ++- tools/tracing/rtla/src/timerlat_hist.c | 3 ++- tools/tracing/rtla/src/timerlat_top.c | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index 1dc39de79d78..3aa74affac26 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -543,7 +543,8 @@ static struct osnoise_params params->threshold = 1; /* set trace */ - params->trace_output = "osnoise_trace.txt"; + if (!params->trace_output) + params->trace_output = "osnoise_trace.txt"; break; case 'b': diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index b3e161536ed8..6bcb8d10c342 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -383,7 +383,8 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv) params->threshold = 1; /* set trace */ - params->trace_output = "osnoise_trace.txt"; + if (!params->trace_output) + params->trace_output = "osnoise_trace.txt"; break; case 'c': diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index ad713dafa3c3..f845d5fa8141 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -874,7 +874,8 @@ static struct timerlat_params params->print_stack = auto_thresh; /* set trace */ - trace_output = "timerlat_trace.txt"; + if (!trace_output) + trace_output = "timerlat_trace.txt"; break; case 'c': diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 7f1885018624..42d85ea2e996 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -625,7 +625,8 @@ static struct timerlat_params params->print_stack = auto_thresh; /* set trace */ - trace_output = "timerlat_trace.txt"; + if (!trace_output) + trace_output = "timerlat_trace.txt"; break; case '5': -- 2.48.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 3/3] rtla: fix -a overriding -t argument 2025-09-08 2:05 ` [PATCH v3 3/3] rtla: fix -a overriding -t argument Ivan Pravdin @ 2025-09-11 11:32 ` Tomas Glozar 0 siblings, 0 replies; 9+ messages in thread From: Tomas Glozar @ 2025-09-11 11:32 UTC (permalink / raw) To: Ivan Pravdin; +Cc: rostedt, linux-trace-kernel, linux-kernel po 8. 9. 2025 v 4:06 odesílatel Ivan Pravdin <ipravdin.official@gmail.com> napsal: > > When running rtla as > > `rtla <timerlat|osnoise> <top|hist> -t custom_file.txt -a 100` > > -a options override trace output filename specified by -t option. > Running the command above will create <timerlat|osnoise>_trace.txt file > instead of custom_file.txt. Fix this by making sure that -a option does > not override trace output filename even if it's passed after trace > output filename is specified. > > Fixes: 173a3b014827 ("rtla/timerlat: Add the automatic trace option") > Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> This part is good, the only problematic bit was the clear_terminal stuff. Reviewed-by: Tomas Glozar <tglozar@redhat.com> Tomas ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-09-29 15:13 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-08 2:05 [PATCH v3 0/3] rtla: fix cgroup and trace options parsing Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 1/3] rtla: fix buffer overflow in actions_parse Ivan Pravdin 2025-09-26 14:32 ` Tomas Glozar 2025-09-27 9:59 ` Steven Rostedt 2025-09-29 15:13 ` Ivan Pravdin 2025-09-08 2:05 ` [PATCH v3 2/3] rtla: fix -C/--cgroup interface Ivan Pravdin 2025-09-11 11:29 ` Tomas Glozar 2025-09-08 2:05 ` [PATCH v3 3/3] rtla: fix -a overriding -t argument Ivan Pravdin 2025-09-11 11:32 ` Tomas Glozar
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox