Skip to content

Commit 7b71f3a

Browse files
ivpravdinlenticularis39
authored andcommitted
rtla: Fix -C/--cgroup interface
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: a957cbc ("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>
1 parent 49c1579 commit 7b71f3a

7 files changed

Lines changed: 56 additions & 77 deletions

File tree

Documentation/tools/rtla/common_options.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
- *f:prio* - use SCHED_FIFO with *prio*;
4343
- *d:runtime[us|ms|s]:period[us|ms|s]* - use SCHED_DEADLINE with *runtime* and *period* in nanoseconds.
4444

45-
**-C**, **--cgroup**\[*=cgroup*]
45+
**-C**, **--cgroup** \[*cgroup*]
4646

4747
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.
4848

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ static void osnoise_hist_usage(void)
414414
static const char * const msg[] = {
415415
"",
416416
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
417-
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
417+
" [-T us] [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
418418
" [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\",
419-
" [--no-index] [--with-zeros] [-C[=cgroup_name]] [--warm-up]",
419+
" [--no-index] [--with-zeros] [-C [cgroup_name]] [--warm-up]",
420420
"",
421421
" -h/--help: print this menu",
422422
" -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)
427427
" -T/--threshold us: the minimum delta to be considered a noise",
428428
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
429429
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
430-
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
430+
" -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
431431
" -d/--duration time[s|m|h|d]: duration of the session",
432432
" -D/--debug: print debug info",
433-
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
433+
" -t/--trace [file]: save the stopped trace to [file|osnoise_trace.txt]",
434434
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
435435
" --filter <filter>: enable a trace event filter to the previous -e event",
436436
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -551,13 +551,7 @@ static struct common_params
551551
break;
552552
case 'C':
553553
params->common.cgroup = 1;
554-
if (!optarg) {
555-
/* will inherit this cgroup */
556-
params->common.cgroup_name = NULL;
557-
} else if (*optarg == '=') {
558-
/* skip the = */
559-
params->common.cgroup_name = ++optarg;
560-
}
554+
params->common.cgroup_name = parse_optional_arg(argc, argv);
561555
break;
562556
case 'D':
563557
config_debug = 1;
@@ -619,14 +613,8 @@ static struct common_params
619613
params->threshold = get_llong_from_str(optarg);
620614
break;
621615
case 't':
622-
if (optarg) {
623-
if (optarg[0] == '=')
624-
trace_output = &optarg[1];
625-
else
626-
trace_output = &optarg[0];
627-
} else if (optind < argc && argv[optind][0] != '0')
628-
trace_output = argv[optind];
629-
else
616+
trace_output = parse_optional_arg(argc, argv);
617+
if (!trace_output)
630618
trace_output = "osnoise_trace.txt";
631619
break;
632620
case '0': /* no header */

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ static void osnoise_top_usage(struct osnoise_params *params)
261261

262262
static const char * const msg[] = {
263263
" [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
264-
" [-T us] [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
265-
" [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]] [--warm-up s]",
264+
" [-T us] [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
265+
" [-c cpu-list] [-H cpu-list] [-P priority] [-C [cgroup_name]] [--warm-up s]",
266266
"",
267267
" -h/--help: print this menu",
268268
" -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)
273273
" -T/--threshold us: the minimum delta to be considered a noise",
274274
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
275275
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
276-
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
276+
" -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
277277
" -d/--duration time[s|m|h|d]: duration of the session",
278278
" -D/--debug: print debug info",
279-
" -t/--trace[file]: save the stopped trace to [file|osnoise_trace.txt]",
279+
" -t/--trace [file]: save the stopped trace to [file|osnoise_trace.txt]",
280280
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
281281
" --filter <filter>: enable a trace event filter to the previous -e event",
282282
" --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)
397397
break;
398398
case 'C':
399399
params->common.cgroup = 1;
400-
if (!optarg) {
401-
/* will inherit this cgroup */
402-
params->common.cgroup_name = NULL;
403-
} else if (*optarg == '=') {
404-
/* skip the = */
405-
params->common.cgroup_name = ++optarg;
406-
}
400+
params->common.cgroup_name = parse_optional_arg(argc, argv);
407401
break;
408402
case 'D':
409403
config_debug = 1;
@@ -459,14 +453,8 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
459453
params->common.stop_total_us = get_llong_from_str(optarg);
460454
break;
461455
case 't':
462-
if (optarg) {
463-
if (optarg[0] == '=')
464-
trace_output = &optarg[1];
465-
else
466-
trace_output = &optarg[0];
467-
} else if (optind < argc && argv[optind][0] != '-')
468-
trace_output = argv[optind];
469-
else
456+
trace_output = parse_optional_arg(argc, argv);
457+
if (!trace_output)
470458
trace_output = "osnoise_trace.txt";
471459
break;
472460
case 'T':

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ static void timerlat_hist_usage(void)
701701
char *msg[] = {
702702
"",
703703
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
704-
" [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
704+
" [-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
705705
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
706-
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
706+
" [--no-index] [--with-zeros] [--dma-latency us] [-C [cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
707707
" [--warm-up s] [--deepest-idle-state n]",
708708
"",
709709
" -h/--help: print this menu",
@@ -714,11 +714,11 @@ static void timerlat_hist_usage(void)
714714
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
715715
" -c/--cpus cpus: run the tracer only on the given cpus",
716716
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
717-
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
717+
" -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
718718
" -d/--duration time[m|h|d]: duration of the session in seconds",
719719
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
720720
" -D/--debug: print debug info",
721-
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
721+
" -t/--trace [file]: save the stopped trace to [file|timerlat_trace.txt]",
722722
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
723723
" --filter <filter>: enable a trace event filter to the previous -e event",
724724
" --trigger <trigger>: enable a trace event trigger to the previous -e event",
@@ -864,13 +864,7 @@ static struct common_params
864864
break;
865865
case 'C':
866866
params->common.cgroup = 1;
867-
if (!optarg) {
868-
/* will inherit this cgroup */
869-
params->common.cgroup_name = NULL;
870-
} else if (*optarg == '=') {
871-
/* skip the = */
872-
params->common.cgroup_name = ++optarg;
873-
}
867+
params->common.cgroup_name = parse_optional_arg(argc, argv);
874868
break;
875869
case 'b':
876870
params->common.hist.bucket_size = get_llong_from_str(optarg);
@@ -939,14 +933,8 @@ static struct common_params
939933
params->common.stop_total_us = get_llong_from_str(optarg);
940934
break;
941935
case 't':
942-
if (optarg) {
943-
if (optarg[0] == '=')
944-
trace_output = &optarg[1];
945-
else
946-
trace_output = &optarg[0];
947-
} else if (optind < argc && argv[optind][0] != '-')
948-
trace_output = argv[optind];
949-
else
936+
trace_output = parse_optional_arg(argc, argv);
937+
if (!trace_output)
950938
trace_output = "timerlat_trace.txt";
951939
break;
952940
case 'u':

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ static void timerlat_top_usage(void)
481481
static const char *const msg[] = {
482482
"",
483483
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
484-
" [[-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
485-
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s] [--deepest-idle-state n]",
484+
" [[-t [file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
485+
" [-P priority] [--dma-latency us] [--aa-only us] [-C [cgroup_name]] [-u|-k] [--warm-up s] [--deepest-idle-state n]",
486486
"",
487487
" -h/--help: print this menu",
488488
" -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)
493493
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
494494
" -c/--cpus cpus: run the tracer only on the given cpus",
495495
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
496-
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
496+
" -C/--cgroup [cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
497497
" -d/--duration time[s|m|h|d]: duration of the session",
498498
" -D/--debug: print debug info",
499499
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
500-
" -t/--trace[file]: save the stopped trace to [file|timerlat_trace.txt]",
500+
" -t/--trace [file]: save the stopped trace to [file|timerlat_trace.txt]",
501501
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed",
502502
" --filter <command>: enable a trace event filter to the previous -e event",
503503
" --trigger <command>: enable a trace event trigger to the previous -e event",
@@ -642,13 +642,7 @@ static struct common_params
642642
break;
643643
case 'C':
644644
params->common.cgroup = 1;
645-
if (!optarg) {
646-
/* will inherit this cgroup */
647-
params->common.cgroup_name = NULL;
648-
} else if (*optarg == '=') {
649-
/* skip the = */
650-
params->common.cgroup_name = ++optarg;
651-
}
645+
params->common.cgroup_name = optarg;
652646
break;
653647
case 'D':
654648
config_debug = 1;
@@ -707,14 +701,8 @@ static struct common_params
707701
params->common.stop_total_us = get_llong_from_str(optarg);
708702
break;
709703
case 't':
710-
if (optarg) {
711-
if (optarg[0] == '=')
712-
trace_output = &optarg[1];
713-
else
714-
trace_output = &optarg[0];
715-
} else if (optind < argc && argv[optind][0] != '-')
716-
trace_output = argv[optind];
717-
else
704+
trace_output = parse_optional_arg(argc, argv);
705+
if (!trace_output)
718706
trace_output = "timerlat_trace.txt";
719707
break;
720708
case 'u':

tools/tracing/rtla/src/utils.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,3 +974,29 @@ int auto_house_keeping(cpu_set_t *monitored_cpus)
974974

975975
return 1;
976976
}
977+
978+
/**
979+
* parse_optional_arg - Parse optional argument value
980+
*
981+
* Parse optional argument value, which can be in the form of:
982+
* -sarg, -s/--long=arg, -s/--long arg
983+
*
984+
* Returns arg value if found, NULL otherwise.
985+
*/
986+
char *parse_optional_arg(int argc, char **argv)
987+
{
988+
if (optarg) {
989+
if (optarg[0] == '=') {
990+
/* skip the = */
991+
return &optarg[1];
992+
} else {
993+
return optarg;
994+
}
995+
/* parse argument of form -s [arg] and --long [arg]*/
996+
} else if (optind < argc && argv[optind][0] != '-') {
997+
/* consume optind */
998+
return argv[optind++];
999+
} else {
1000+
return NULL;
1001+
}
1002+
}

tools/tracing/rtla/src/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ long parse_seconds_duration(char *val);
2525
void get_duration(time_t start_time, char *output, int output_size);
2626

2727
int parse_cpu_list(char *cpu_list, char **monitored_cpus);
28+
char *parse_optional_arg(int argc, char **argv);
2829
long long get_llong_from_str(char *start);
2930

3031
static inline void

0 commit comments

Comments
 (0)