Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 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>

authored by

Ivan Pravdin and committed by
Tomas Glozar
7b71f3a6 49c15794

+56 -77
+1 -1
Documentation/tools/rtla/common_options.rst
··· 42 42 - *f:prio* - use SCHED_FIFO with *prio*; 43 43 - *d:runtime[us|ms|s]:period[us|ms|s]* - use SCHED_DEADLINE with *runtime* and *period* in nanoseconds. 44 44 45 - **-C**, **--cgroup**\[*=cgroup*] 45 + **-C**, **--cgroup** \[*cgroup*] 46 46 47 47 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. 48 48
+7 -19
tools/tracing/rtla/src/osnoise_hist.c
··· 414 414 static const char * const msg[] = { 415 415 "", 416 416 " 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>] \\", 418 418 " [-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]", 420 420 "", 421 421 " -h/--help: print this menu", 422 422 " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", ··· 427 427 " -T/--threshold us: the minimum delta to be considered a noise", 428 428 " -c/--cpus cpu-list: list of cpus to run osnoise threads", 429 429 " -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", 431 431 " -d/--duration time[s|m|h|d]: duration of the session", 432 432 " -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]", 434 434 " -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", 435 435 " --filter <filter>: enable a trace event filter to the previous -e event", 436 436 " --trigger <trigger>: enable a trace event trigger to the previous -e event", ··· 551 551 break; 552 552 case 'C': 553 553 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); 561 555 break; 562 556 case 'D': 563 557 config_debug = 1; ··· 613 619 params->threshold = get_llong_from_str(optarg); 614 620 break; 615 621 case 't': 616 - if (optarg) { 617 - if (optarg[0] == '=') 618 - trace_output = &optarg[1]; 619 - else 620 - trace_output = &optarg[0]; 621 - } else if (optind < argc && argv[optind][0] != '0') 622 - trace_output = argv[optind]; 623 - else 622 + trace_output = parse_optional_arg(argc, argv); 623 + if (!trace_output) 624 624 trace_output = "osnoise_trace.txt"; 625 625 break; 626 626 case '0': /* no header */
+7 -19
tools/tracing/rtla/src/osnoise_top.c
··· 261 261 262 262 static const char * const msg[] = { 263 263 " [-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]", 266 266 "", 267 267 " -h/--help: print this menu", 268 268 " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", ··· 273 273 " -T/--threshold us: the minimum delta to be considered a noise", 274 274 " -c/--cpus cpu-list: list of cpus to run osnoise threads", 275 275 " -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", 277 277 " -d/--duration time[s|m|h|d]: duration of the session", 278 278 " -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]", 280 280 " -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", 281 281 " --filter <filter>: enable a trace event filter to the previous -e event", 282 282 " --trigger <trigger>: enable a trace event trigger to the previous -e event", ··· 397 397 break; 398 398 case 'C': 399 399 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); 407 401 break; 408 402 case 'D': 409 403 config_debug = 1; ··· 453 459 params->common.stop_total_us = get_llong_from_str(optarg); 454 460 break; 455 461 case 't': 456 - if (optarg) { 457 - if (optarg[0] == '=') 458 - trace_output = &optarg[1]; 459 - else 460 - trace_output = &optarg[0]; 461 - } else if (optind < argc && argv[optind][0] != '-') 462 - trace_output = argv[optind]; 463 - else 462 + trace_output = parse_optional_arg(argc, argv); 463 + if (!trace_output) 464 464 trace_output = "osnoise_trace.txt"; 465 465 break; 466 466 case 'T':
+7 -19
tools/tracing/rtla/src/timerlat_hist.c
··· 701 701 char *msg[] = { 702 702 "", 703 703 " 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]\\", 705 705 " [-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]", 707 707 " [--warm-up s] [--deepest-idle-state n]", 708 708 "", 709 709 " -h/--help: print this menu", ··· 714 714 " -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us", 715 715 " -c/--cpus cpus: run the tracer only on the given cpus", 716 716 " -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", 718 718 " -d/--duration time[m|h|d]: duration of the session in seconds", 719 719 " --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)", 720 720 " -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]", 722 722 " -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", 723 723 " --filter <filter>: enable a trace event filter to the previous -e event", 724 724 " --trigger <trigger>: enable a trace event trigger to the previous -e event", ··· 864 864 break; 865 865 case 'C': 866 866 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); 874 868 break; 875 869 case 'b': 876 870 params->common.hist.bucket_size = get_llong_from_str(optarg); ··· 933 939 params->common.stop_total_us = get_llong_from_str(optarg); 934 940 break; 935 941 case 't': 936 - if (optarg) { 937 - if (optarg[0] == '=') 938 - trace_output = &optarg[1]; 939 - else 940 - trace_output = &optarg[0]; 941 - } else if (optind < argc && argv[optind][0] != '-') 942 - trace_output = argv[optind]; 943 - else 942 + trace_output = parse_optional_arg(argc, argv); 943 + if (!trace_output) 944 944 trace_output = "timerlat_trace.txt"; 945 945 break; 946 946 case 'u':
+7 -19
tools/tracing/rtla/src/timerlat_top.c
··· 481 481 static const char *const msg[] = { 482 482 "", 483 483 " 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]", 486 486 "", 487 487 " -h/--help: print this menu", 488 488 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", ··· 493 493 " -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us", 494 494 " -c/--cpus cpus: run the tracer only on the given cpus", 495 495 " -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", 497 497 " -d/--duration time[s|m|h|d]: duration of the session", 498 498 " -D/--debug: print debug info", 499 499 " --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]", 501 501 " -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed", 502 502 " --filter <command>: enable a trace event filter to the previous -e event", 503 503 " --trigger <command>: enable a trace event trigger to the previous -e event", ··· 642 642 break; 643 643 case 'C': 644 644 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; 652 646 break; 653 647 case 'D': 654 648 config_debug = 1; ··· 701 707 params->common.stop_total_us = get_llong_from_str(optarg); 702 708 break; 703 709 case 't': 704 - if (optarg) { 705 - if (optarg[0] == '=') 706 - trace_output = &optarg[1]; 707 - else 708 - trace_output = &optarg[0]; 709 - } else if (optind < argc && argv[optind][0] != '-') 710 - trace_output = argv[optind]; 711 - else 710 + trace_output = parse_optional_arg(argc, argv); 711 + if (!trace_output) 712 712 trace_output = "timerlat_trace.txt"; 713 713 break; 714 714 case 'u':
+26
tools/tracing/rtla/src/utils.c
··· 974 974 975 975 return 1; 976 976 } 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 + }
+1
tools/tracing/rtla/src/utils.h
··· 25 25 void get_duration(time_t start_time, char *output, int output_size); 26 26 27 27 int parse_cpu_list(char *cpu_list, char **monitored_cpus); 28 + char *parse_optional_arg(int argc, char **argv); 28 29 long long get_llong_from_str(char *start); 29 30 30 31 static inline void