From 61c57d578bd7ca2aff3652ed62d95e3f8fc6d16e Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:26 +0100 Subject: rtla/osnoise: Add support to adjust the tracing_thresh osnoise uses the tracing_thresh parameter to define the delta between two reads of the time to be considered a noise. Add support to get and set the tracing_thresh from osnoise tools. Link: https://lkml.kernel.org/r/715ad2a53fd40e41bab8c3f1214c1a94e12fb595.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/osnoise.c | 83 ++++++++++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/osnoise.h | 8 ++++ 2 files changed, 91 insertions(+) (limited to 'tools') diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osnoise.c index e60f1862bad0..b8ec6c15bccb 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -655,6 +655,85 @@ void osnoise_put_print_stack(struct osnoise_context *context) context->orig_print_stack = OSNOISE_OPTION_INIT_VAL; } +/* + * osnoise_get_tracing_thresh - read and save the original "tracing_thresh" + */ +static long long +osnoise_get_tracing_thresh(struct osnoise_context *context) +{ + long long tracing_thresh; + + if (context->tracing_thresh != OSNOISE_OPTION_INIT_VAL) + return context->tracing_thresh; + + if (context->orig_tracing_thresh != OSNOISE_OPTION_INIT_VAL) + return context->orig_tracing_thresh; + + tracing_thresh = osnoise_read_ll_config("tracing_thresh"); + if (tracing_thresh < 0) + goto out_err; + + context->orig_tracing_thresh = tracing_thresh; + return tracing_thresh; + +out_err: + return OSNOISE_OPTION_INIT_VAL; +} + +/* + * osnoise_set_tracing_thresh - set "tracing_thresh" + */ +int osnoise_set_tracing_thresh(struct osnoise_context *context, long long tracing_thresh) +{ + long long curr_tracing_thresh = osnoise_get_tracing_thresh(context); + int retval; + + if (curr_tracing_thresh == OSNOISE_OPTION_INIT_VAL) + return -1; + + retval = osnoise_write_ll_config("tracing_thresh", tracing_thresh); + if (retval < 0) + return -1; + + context->tracing_thresh = tracing_thresh; + + return 0; +} + +/* + * osnoise_restore_tracing_thresh - restore the original "tracing_thresh" + */ +void osnoise_restore_tracing_thresh(struct osnoise_context *context) +{ + int retval; + + if (context->orig_tracing_thresh == OSNOISE_OPTION_INIT_VAL) + return; + + if (context->orig_tracing_thresh == context->tracing_thresh) + goto out_done; + + retval = osnoise_write_ll_config("tracing_thresh", context->orig_tracing_thresh); + if (retval < 0) + err_msg("Could not restore original tracing_thresh\n"); + +out_done: + context->tracing_thresh = OSNOISE_OPTION_INIT_VAL; +} + +/* + * osnoise_put_tracing_thresh - restore original values and cleanup data + */ +void osnoise_put_tracing_thresh(struct osnoise_context *context) +{ + osnoise_restore_tracing_thresh(context); + + if (context->orig_tracing_thresh == OSNOISE_OPTION_INIT_VAL) + return; + + context->orig_tracing_thresh = OSNOISE_OPTION_INIT_VAL; +} + /* * enable_osnoise - enable osnoise tracer in the trace_instance */ @@ -716,6 +795,9 @@ struct osnoise_context *osnoise_context_alloc(void) context->orig_print_stack = OSNOISE_OPTION_INIT_VAL; context->print_stack = OSNOISE_OPTION_INIT_VAL; + context->orig_tracing_thresh = OSNOISE_OPTION_INIT_VAL; + context->tracing_thresh = OSNOISE_OPTION_INIT_VAL; + osnoise_get_context(context); return context; @@ -741,6 +823,7 @@ void osnoise_put_context(struct osnoise_context *context) osnoise_put_stop_total_us(context); osnoise_put_timerlat_period_us(context); osnoise_put_print_stack(context); + osnoise_put_tracing_thresh(context); free(context); } diff --git a/tools/tracing/rtla/src/osnoise.h b/tools/tracing/rtla/src/osnoise.h index 9e4b2e2a4559..04a4384cc544 100644 --- a/tools/tracing/rtla/src/osnoise.h +++ b/tools/tracing/rtla/src/osnoise.h @@ -23,6 +23,10 @@ struct osnoise_context { long long orig_timerlat_period_us; long long timerlat_period_us; + /* 0 as init value */ + long long orig_tracing_thresh; + long long tracing_thresh; + /* -1 as init value because 0 is disabled */ long long orig_stop_us; long long stop_us; @@ -67,6 +71,10 @@ int osnoise_set_timerlat_period_us(struct osnoise_context *context, long long timerlat_period_us); void osnoise_restore_timerlat_period_us(struct osnoise_context *context); +int osnoise_set_tracing_thresh(struct osnoise_context *context, + long long tracing_thresh); +void osnoise_restore_tracing_thresh(struct osnoise_context *context); + void osnoise_restore_print_stack(struct osnoise_context *context); int osnoise_set_print_stack(struct osnoise_context *context, long long print_stack); -- cgit v1.2.3 From d635316ae92291083ae7a36014e29ed7b306cb04 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:27 +0100 Subject: rtla/osnoise: Add an option to set the threshold Add the -T/--threshold option to set the minimum threshold to be considered a noise to osnoise top and hist commands. Also update the man pages. Link: https://lkml.kernel.org/r/031861200ffdb24a1df4aa72c458706889a20d5d.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- .../tools/rtla/common_osnoise_options.rst | 5 +++++ tools/tracing/rtla/src/osnoise_hist.c | 22 ++++++++++++++++++---- tools/tracing/rtla/src/osnoise_top.c | 20 +++++++++++++++++--- 3 files changed, 40 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_osnoise_options.rst b/Documentation/tools/rtla/common_osnoise_options.rst index d556883e4e26..27f1493f7bc0 100644 --- a/Documentation/tools/rtla/common_osnoise_options.rst +++ b/Documentation/tools/rtla/common_osnoise_options.rst @@ -15,3 +15,8 @@ Stop the trace if the total sample is higher than the argument in microseconds. If **-T** is set, it will also save the trace to the output. + +**-T**, **--threshold** *us* + + Specify the minimum delta between two time reads to be considered noise. + The default threshold is *5 us*. diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index 52c053cc1789..ab02219de528 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -21,6 +21,7 @@ struct osnoise_hist_params { char *trace_output; unsigned long long runtime; unsigned long long period; + long long threshold; long long stop_us; long long stop_total_us; int sleep_time; @@ -425,15 +426,16 @@ static void osnoise_hist_usage(char *usage) static const char * const msg[] = { "", - " usage: rtla osnoise hist [-h] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-t[=file]] \\", - " [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\", - " [--no-index] [--with-zeros]", + " usage: rtla osnoise hist [-h] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-T us] \\", + " [-t[=file]] [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] \\", + " [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", " -s/--stop us: stop trace if a single sample is higher than the argument in us", " -S/--stop-total us: stop trace if the total sample is higher than the argument in us", + " -T/--threshold us: the minimum delta to be considered a noise", " -c/--cpus cpu-list: list of cpus to run osnoise threads", " -d/--duration time[s|m|h|d]: duration of the session", " -D/--debug: print debug info", @@ -497,6 +499,7 @@ static struct osnoise_hist_params {"stop", required_argument, 0, 's'}, {"stop-total", required_argument, 0, 'S'}, {"trace", optional_argument, 0, 't'}, + {"threshold", required_argument, 0, 'T'}, {"no-header", no_argument, 0, '0'}, {"no-summary", no_argument, 0, '1'}, {"no-index", no_argument, 0, '2'}, @@ -507,7 +510,7 @@ static struct osnoise_hist_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:b:d:E:Dhp:P:r:s:S:t::0123", + c = getopt_long(argc, argv, "c:b:d:E:Dhp:P:r:s:S:t::T:0123", long_options, &option_index); /* detect the end of the options. */ @@ -565,6 +568,9 @@ static struct osnoise_hist_params case 'S': params->stop_total_us = get_llong_from_str(optarg); break; + case 'T': + params->threshold = get_llong_from_str(optarg); + break; case 't': if (optarg) /* skip = */ @@ -645,6 +651,14 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params } } + if (params->threshold) { + retval = osnoise_set_tracing_thresh(tool->context, params->threshold); + if (retval) { + err_msg("Failed to set tracing_thresh\n"); + goto out_err; + } + } + return 0; out_err: diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index 7af769b9c0de..07fb1b8314d3 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -23,6 +23,7 @@ struct osnoise_top_params { char *trace_output; unsigned long long runtime; unsigned long long period; + long long threshold; long long stop_us; long long stop_total_us; int sleep_time; @@ -244,14 +245,15 @@ void osnoise_top_usage(char *usage) int i; static const char * const msg[] = { - " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-t[=file]] \\", - " [-c cpu-list] [-P priority]", + " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-T us] \\", + " [-t[=file]] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", " -s/--stop us: stop trace if a single sample is higher than the argument in us", " -S/--stop-total us: stop trace if the total sample is higher than the argument in us", + " -T/--threshold us: the minimum delta to be considered a noise", " -c/--cpus cpu-list: list of cpus to run osnoise threads", " -d/--duration time[s|m|h|d]: duration of the session", " -D/--debug: print debug info", @@ -302,6 +304,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) {"runtime", required_argument, 0, 'r'}, {"stop", required_argument, 0, 's'}, {"stop-total", required_argument, 0, 'S'}, + {"threshold", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, {0, 0, 0, 0} }; @@ -309,7 +312,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:d:Dhp:P:qr:s:S:t::", + c = getopt_long(argc, argv, "c:d:Dhp:P:qr:s:S:t::T:", long_options, &option_index); /* Detect the end of the options. */ @@ -367,6 +370,9 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) else params->trace_output = "osnoise_trace.txt"; break; + case 'T': + params->threshold = get_llong_from_str(optarg); + break; default: osnoise_top_usage("Invalid option"); } @@ -425,6 +431,14 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p } } + if (params->threshold) { + retval = osnoise_set_tracing_thresh(tool->context, params->threshold); + if (retval) { + err_msg("Failed to set tracing_thresh\n"); + goto out_err; + } + } + return 0; out_err: -- cgit v1.2.3 From 2b622edd5eb5a12c1203fdb353c2ce0681672571 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:28 +0100 Subject: rtla/osnoise: Add the automatic trace option Add the -a/--auto option. This option sets some commonly used options while debugging the system. It aims to help users produce reports in the field, reducing the number of arguments passed to the tool in the first approach to a problem. It is equivalent to setting osnoise/stop_tracing_us with the argument, setting tracing_thresh to 1 us, and saving the trace to osnoise_trace.txt file if the trace is stopped automatically. Link: https://lkml.kernel.org/r/ef04c961b227eb93a83cd0b54bfca45e1a381b77.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_osnoise_options.rst | 5 +++++ tools/tracing/rtla/src/osnoise_hist.c | 19 ++++++++++++++++--- tools/tracing/rtla/src/osnoise_top.c | 19 ++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_osnoise_options.rst b/Documentation/tools/rtla/common_osnoise_options.rst index 27f1493f7bc0..f792ca58c211 100644 --- a/Documentation/tools/rtla/common_osnoise_options.rst +++ b/Documentation/tools/rtla/common_osnoise_options.rst @@ -1,3 +1,8 @@ +**-a**, **--auto** *us* + + Set the automatic trace mode. This mode sets some commonly used options + while debugging the system. It is equivalent to use **-s** *us* **-T 1 -t**. + **-p**, **--period** *us* Set the *osnoise* tracer period in microseconds. diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index ab02219de528..5698da2fe3dd 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -426,11 +426,12 @@ static void osnoise_hist_usage(char *usage) static const char * const msg[] = { "", - " usage: rtla osnoise hist [-h] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-T us] \\", - " [-t[=file]] [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] \\", + " usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", + " [-T us] [-t[=file]] [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] \\", " [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", + " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", " -s/--stop us: stop trace if a single sample is higher than the argument in us", @@ -487,6 +488,7 @@ static struct osnoise_hist_params while (1) { static struct option long_options[] = { + {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, {"cpus", required_argument, 0, 'c'}, @@ -510,7 +512,7 @@ static struct osnoise_hist_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:b:d:E:Dhp:P:r:s:S:t::T:0123", + c = getopt_long(argc, argv, "a:c:b:d:E:Dhp:P:r:s:S:t::T:0123", long_options, &option_index); /* detect the end of the options. */ @@ -518,6 +520,17 @@ static struct osnoise_hist_params break; switch (c) { + case 'a': + /* set sample stop to auto_thresh */ + params->stop_us = get_llong_from_str(optarg); + + /* set sample threshold to 1 */ + params->threshold = 1; + + /* set trace */ + params->trace_output = "osnoise_trace.txt"; + + break; case 'b': params->bucket_size = get_llong_from_str(optarg); if ((params->bucket_size == 0) || (params->bucket_size >= 1000000)) diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index 07fb1b8314d3..a6f434f85738 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -245,10 +245,11 @@ void osnoise_top_usage(char *usage) int i; static const char * const msg[] = { - " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-p us] [-r us] [-s us] [-S us] [-T us] \\", - " [-t[=file]] [-c cpu-list] [-P priority]", + " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", + " [-T us] [-t[=file]] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", + " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", " -p/--period us: osnoise period in us", " -r/--runtime us: osnoise runtime in us", " -s/--stop us: stop trace if a single sample is higher than the argument in us", @@ -294,6 +295,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) while (1) { static struct option long_options[] = { + {"auto", required_argument, 0, 'a'}, {"cpus", required_argument, 0, 'c'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, @@ -312,7 +314,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:d:Dhp:P:qr:s:S:t::T:", + c = getopt_long(argc, argv, "a:c:d:Dhp:P:qr:s:S:t::T:", long_options, &option_index); /* Detect the end of the options. */ @@ -320,6 +322,17 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) break; switch (c) { + case 'a': + /* set sample stop to auto_thresh */ + params->stop_us = get_llong_from_str(optarg); + + /* set sample threshold to 1 */ + params->threshold = 1; + + /* set trace */ + params->trace_output = "osnoise_trace.txt"; + + break; case 'c': retval = parse_cpu_list(optarg, ¶ms->monitored_cpus); if (retval) -- cgit v1.2.3 From 173a3b014827955cefdf972ae673d94b60e31cf8 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:29 +0100 Subject: rtla/timerlat: Add the automatic trace option Add the -a/--auto option. This option sets some commonly used options while debugging the system. It aims to help users produce reports in the field, reducing the number of arguments passed to the tool in the first approach to a problem. It is equivalent to setting osnoise/stop_tracing_total_us and print_stack with the argument, and saving the trace to timerlat_trace.txt file if the trace is stopped automatically. Link: https://lkml.kernel.org/r/92438f7ef132c731f538cebdf77850300afe04a5.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- .../tools/rtla/common_timerlat_options.rst | 7 +++++++ tools/tracing/rtla/src/timerlat_hist.c | 24 ++++++++++++++++++---- tools/tracing/rtla/src/timerlat_top.c | 22 +++++++++++++++++--- 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_timerlat_options.rst b/Documentation/tools/rtla/common_timerlat_options.rst index e9c1bfd55d48..14a24a121f5d 100644 --- a/Documentation/tools/rtla/common_timerlat_options.rst +++ b/Documentation/tools/rtla/common_timerlat_options.rst @@ -1,3 +1,10 @@ +**-a**, **--auto** *us* + + Set the automatic trace mode. This mode sets some commonly used options + while debugging the system. It is equivalent to use **-T** *us* **-s** *us* + **-t**. By default, *timerlat* tracer uses FIFO:95 for *timerlat* threads, + thus equilavent to **-P** *f:95*. + **-p**, **--period** *us* Set the *timerlat* tracer period in microseconds. diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 237e1735afa7..9cd97095b04a 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -428,11 +428,12 @@ static void timerlat_hist_usage(char *usage) char *msg[] = { "", - " usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] [-t[=file]] \\", - " [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\", - " [--no-index] [--with-zeros]", + " usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\", + " [-t[=file]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] \\", + " [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", + " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", " -p/--period us: timerlat period in us", " -i/--irq us: stop trace if the irq latency is higher than the argument in us", " -T/--thread us: stop trace if the thread latency is higher than the argument in us", @@ -477,6 +478,7 @@ static struct timerlat_hist_params *timerlat_hist_parse_args(int argc, char *argv[]) { struct timerlat_hist_params *params; + int auto_thresh; int retval; int c; @@ -491,6 +493,7 @@ static struct timerlat_hist_params while (1) { static struct option long_options[] = { + {"auto", required_argument, 0, 'a'}, {"cpus", required_argument, 0, 'c'}, {"bucket-size", required_argument, 0, 'b'}, {"debug", no_argument, 0, 'D'}, @@ -516,7 +519,7 @@ static struct timerlat_hist_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:b:d:E:Dhi:np:P:s:t::T:012345", + c = getopt_long(argc, argv, "a:c:b:d:E:Dhi:np:P:s:t::T:012345", long_options, &option_index); /* detect the end of the options. */ @@ -524,6 +527,19 @@ static struct timerlat_hist_params break; switch (c) { + case 'a': + auto_thresh = get_llong_from_str(optarg); + + /* set thread stop to auto_thresh */ + params->stop_total_us = auto_thresh; + + /* get stack trace */ + params->print_stack = auto_thresh; + + /* set trace */ + params->trace_output = "timerlat_trace.txt"; + + break; case 'c': retval = parse_cpu_list(optarg, ¶ms->monitored_cpus); if (retval) diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index d4187f6534ed..aef044832964 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -266,10 +266,11 @@ static void timerlat_top_usage(char *usage) static const char *const msg[] = { "", - " usage: rtla timerlat [top] [-h] [-q] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] [-t[=file]] \\", - " [-c cpu-list] [-P priority]", + " usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\", + " [[-t[=file]] -c cpu-list] [-P priority]", "", " -h/--help: print this menu", + " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", " -p/--period us: timerlat period in us", " -i/--irq us: stop trace if the irq latency is higher than the argument in us", " -T/--thread us: stop trace if the thread latency is higher than the argument in us", @@ -307,6 +308,7 @@ static struct timerlat_top_params *timerlat_top_parse_args(int argc, char **argv) { struct timerlat_top_params *params; + long long auto_thresh; int retval; int c; @@ -319,6 +321,7 @@ static struct timerlat_top_params while (1) { static struct option long_options[] = { + {"auto", required_argument, 0, 'a'}, {"cpus", required_argument, 0, 'c'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, @@ -337,7 +340,7 @@ static struct timerlat_top_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "c:d:Dhi:np:P:qs:t::T:", + c = getopt_long(argc, argv, "a:c:d:Dhi:np:P:qs:t::T:", long_options, &option_index); /* detect the end of the options. */ @@ -345,6 +348,19 @@ static struct timerlat_top_params break; switch (c) { + case 'a': + auto_thresh = get_llong_from_str(optarg); + + /* set thread stop to auto_thresh */ + params->stop_total_us = auto_thresh; + + /* get stack trace */ + params->print_stack = auto_thresh; + + /* set trace */ + params->trace_output = "timerlat_trace.txt"; + + break; case 'c': retval = parse_cpu_list(optarg, ¶ms->monitored_cpus); if (retval) -- cgit v1.2.3 From b5aa0be25c27a7f21d9a28f0e0057915552d3c1b Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:30 +0100 Subject: rtla/trace: Add trace events helpers Add a set of helper functions to allow the rtla tools to enable additional tracepoints in the trace instance. Link: https://lkml.kernel.org/r/932398b36c1bbaa22c7810d7a40ca9b8c5595b94.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/trace.c | 104 +++++++++++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 15 ++++++ 2 files changed, 119 insertions(+) (limited to 'tools') diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 83de259abcc1..9ad3d8890ec5 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -190,3 +190,107 @@ int trace_instance_start(struct trace_instance *trace) { return tracefs_trace_on(trace->inst); } + +/* + * trace_events_free - free a list of trace events + */ +static void trace_events_free(struct trace_events *events) +{ + struct trace_events *tevent = events; + struct trace_events *free_event; + + while (tevent) { + free_event = tevent; + + tevent = tevent->next; + + free(free_event->system); + free(free_event); + } +} + +/* + * trace_event_alloc - alloc and parse a single trace event + */ +struct trace_events *trace_event_alloc(const char *event_string) +{ + struct trace_events *tevent; + + tevent = calloc(1, sizeof(*tevent)); + if (!tevent) + return NULL; + + tevent->system = strdup(event_string); + if (!tevent->system) { + free(tevent); + return NULL; + } + + tevent->event = strstr(tevent->system, ":"); + if (tevent->event) { + *tevent->event = '\0'; + tevent->event = &tevent->event[1]; + } + + return tevent; +} + +/* + * trace_events_disable - disable all trace events + */ +void trace_events_disable(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + + if (!events) + return; + + while (tevent) { + debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); + if (tevent->enabled) + tracefs_event_disable(instance->inst, tevent->system, tevent->event); + + tevent->enabled = 0; + tevent = tevent->next; + } +} + +/* + * trace_events_enable - enable all events + */ +int trace_events_enable(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + int retval; + + while (tevent) { + debug_msg("Enabling event %s:%s\n", tevent->system, tevent->event ? : "*"); + retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event); + if (retval < 0) { + err_msg("Error enabling event %s:%s\n", tevent->system, + tevent->event ? : "*"); + return 1; + } + + + tevent->enabled = 1; + tevent = tevent->next; + } + + return 0; +} + +/* + * trace_events_destroy - disable and free all trace events + */ +void trace_events_destroy(struct trace_instance *instance, + struct trace_events *events) +{ + if (!events) + return; + + trace_events_disable(instance, events); + trace_events_free(events); +} diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 0ea1df0ad9a7..9f9751f7ee36 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -2,6 +2,13 @@ #include #include +struct trace_events { + struct trace_events *next; + char *system; + char *event; + char enabled; +}; + struct trace_instance { struct tracefs_instance *inst; struct tep_handle *tep; @@ -25,3 +32,11 @@ void destroy_instance(struct tracefs_instance *inst); int save_trace_to_file(struct tracefs_instance *inst, const char *filename); int collect_registered_events(struct tep_event *tep, struct tep_record *record, int cpu, void *context); + +struct trace_events *trace_event_alloc(const char *event_string); +void trace_events_disable(struct trace_instance *instance, + struct trace_events *events); +void trace_events_destroy(struct trace_instance *instance, + struct trace_events *events); +int trace_events_enable(struct trace_instance *instance, + struct trace_events *events); -- cgit v1.2.3 From 51d64c3a181938da8fb56404524e15776e9c6bf8 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:31 +0100 Subject: rtla: Add -e/--event support Add -e/--event option. This option enables an event in the trace (-t) session. The argument can be a specific event, e.g., -e sched:sched_switch, or all events of a system group, e.g., -e sched. Multiple -e are allowed. It is only active when -t or -a are set. This option is available for all current tools. Link: https://lkml.kernel.org/r/6a3b753be9b1e811953995f7f21a86918ad13390.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_options.rst | 4 ++++ tools/tracing/rtla/src/osnoise_hist.c | 31 ++++++++++++++++++++++++--- tools/tracing/rtla/src/osnoise_top.c | 29 +++++++++++++++++++++++-- tools/tracing/rtla/src/timerlat_hist.c | 33 +++++++++++++++++++++++++---- tools/tracing/rtla/src/timerlat_top.c | 28 ++++++++++++++++++++++-- 5 files changed, 114 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst index 721790ad984e..89d783dc3304 100644 --- a/Documentation/tools/rtla/common_options.rst +++ b/Documentation/tools/rtla/common_options.rst @@ -14,6 +14,10 @@ Save the stopped trace to [*file|osnoise_trace.txt*]. +**-e**, **--event** *sys:event* + + Enable an event in the trace (**-t**) session. The argument can be a specific event, e.g., **-e** *sched:sched_switch*, or all events of a system group, e.g., **-e** *sched*. Multiple **-e** are allowed. It is only active when **-t** or **-a** are set. + **-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period* Set scheduling parameters to the osnoise tracer threads, the format to set the priority are: diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index 5698da2fe3dd..10d683a98087 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -29,6 +29,7 @@ struct osnoise_hist_params { int set_sched; int output_divisor; struct sched_attr sched_param; + struct trace_events *events; char no_header; char no_summary; @@ -427,8 +428,8 @@ 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]] [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] \\", - " [--no-summary] [--no-index] [--with-zeros]", + " [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority] [-b N] [-E N] \\", + " [--no-header] [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -441,6 +442,7 @@ static void osnoise_hist_usage(char *usage) " -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]", + " -e/--event : enable the in the trace instance, multiple -e are allowed", " -b/--bucket-size N: set the histogram bucket size (default 1)", " -E/--entries N: set the number of entries of the histogram (default 256)", " --no-header: do not print header", @@ -474,6 +476,7 @@ static struct osnoise_hist_params *osnoise_hist_parse_args(int argc, char *argv[]) { struct osnoise_hist_params *params; + struct trace_events *tevent; int retval; int c; @@ -501,6 +504,7 @@ static struct osnoise_hist_params {"stop", required_argument, 0, 's'}, {"stop-total", required_argument, 0, 'S'}, {"trace", optional_argument, 0, 't'}, + {"event", required_argument, 0, 'e'}, {"threshold", required_argument, 0, 'T'}, {"no-header", no_argument, 0, '0'}, {"no-summary", no_argument, 0, '1'}, @@ -512,7 +516,7 @@ static struct osnoise_hist_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:E:Dhp:P:r:s:S:t::T:0123", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:0123", long_options, &option_index); /* detect the end of the options. */ @@ -550,6 +554,18 @@ static struct osnoise_hist_params if (!params->duration) osnoise_hist_usage("Invalid -D duration\n"); break; + case 'e': + tevent = trace_event_alloc(optarg); + if (!tevent) { + err_msg("Error alloc trace event"); + exit(EXIT_FAILURE); + } + + if (params->events) + tevent->next = params->events; + + params->events = tevent; + break; case 'E': params->entries = get_llong_from_str(optarg); if ((params->entries < 10) || (params->entries > 9999999)) @@ -778,6 +794,13 @@ int osnoise_hist_main(int argc, char *argv[]) err_msg("Failed to enable the trace instance\n"); goto out_hist; } + + if (params->events) { + retval = trace_events_enable(&record->trace, params->events); + if (retval) + goto out_hist; + } + trace_instance_start(&record->trace); } @@ -817,6 +840,8 @@ int osnoise_hist_main(int argc, char *argv[]) } out_hist: + trace_events_destroy(&record->trace, params->events); + params->events = NULL; osnoise_free_histogram(tool->data); out_destroy: osnoise_destroy_tool(record); diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index a6f434f85738..218dc1114139 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -31,6 +31,7 @@ struct osnoise_top_params { int quiet; int set_sched; struct sched_attr sched_param; + struct trace_events *events; }; struct osnoise_top_cpu { @@ -246,7 +247,7 @@ void osnoise_top_usage(char *usage) static const char * const msg[] = { " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", - " [-T us] [-t[=file]] [-c cpu-list] [-P priority]", + " [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -259,6 +260,7 @@ void osnoise_top_usage(char *usage) " -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]", + " -e/--event : enable the in the trace instance, multiple -e are allowed", " -q/--quiet print only a summary at the end", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", " o:prio - use SCHED_OTHER with prio", @@ -286,6 +288,7 @@ void osnoise_top_usage(char *usage) struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) { struct osnoise_top_params *params; + struct trace_events *tevent; int retval; int c; @@ -299,6 +302,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) {"cpus", required_argument, 0, 'c'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, + {"event", required_argument, 0, 'e'}, {"help", no_argument, 0, 'h'}, {"period", required_argument, 0, 'p'}, {"priority", required_argument, 0, 'P'}, @@ -314,7 +318,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:Dhp:P:qr:s:S:t::T:", + c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:", long_options, &option_index); /* Detect the end of the options. */ @@ -347,6 +351,18 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) if (!params->duration) osnoise_top_usage("Invalid -D duration\n"); break; + case 'e': + tevent = trace_event_alloc(optarg); + if (!tevent) { + err_msg("Error alloc trace event"); + exit(EXIT_FAILURE); + } + + if (params->events) + tevent->next = params->events; + params->events = tevent; + + break; case 'h': case '?': osnoise_top_usage(NULL); @@ -556,6 +572,13 @@ int osnoise_top_main(int argc, char **argv) err_msg("Failed to enable the trace instance\n"); goto out_top; } + + if (params->events) { + retval = trace_events_enable(&record->trace, params->events); + if (retval) + goto out_top; + } + trace_instance_start(&record->trace); } @@ -597,6 +620,8 @@ int osnoise_top_main(int argc, char **argv) } out_top: + trace_events_destroy(&record->trace, params->events); + params->events = NULL; osnoise_free_top(tool->data); osnoise_destroy_tool(record); osnoise_destroy_tool(tool); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 9cd97095b04a..2bd668fd36f5 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -29,6 +29,7 @@ struct timerlat_hist_params { int duration; int set_sched; struct sched_attr sched_param; + struct trace_events *events; char no_irq; char no_thread; @@ -429,8 +430,8 @@ 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]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] \\", - " [--no-summary] [--no-index] [--with-zeros]", + " [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] \\", + " [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -441,7 +442,8 @@ static void timerlat_hist_usage(char *usage) " -c/--cpus cpus: run the tracer only on the given cpus", " -d/--duration time[m|h|d]: duration of the session in seconds", " -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 : enable the in the trace instance, multiple -e are allowed", " -n/--nano: display data in nanoseconds", " -b/--bucket-size N: set the histogram bucket size (default 1)", " -E/--entries N: set the number of entries of the histogram (default 256)", @@ -478,6 +480,7 @@ static struct timerlat_hist_params *timerlat_hist_parse_args(int argc, char *argv[]) { struct timerlat_hist_params *params; + struct trace_events *tevent; int auto_thresh; int retval; int c; @@ -507,6 +510,7 @@ static struct timerlat_hist_params {"stack", required_argument, 0, 's'}, {"thread", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, + {"event", required_argument, 0, 'e'}, {"no-irq", no_argument, 0, '0'}, {"no-thread", no_argument, 0, '1'}, {"no-header", no_argument, 0, '2'}, @@ -519,7 +523,7 @@ static struct timerlat_hist_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:E:Dhi:np:P:s:t::T:012345", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:012345", long_options, &option_index); /* detect the end of the options. */ @@ -559,6 +563,18 @@ static struct timerlat_hist_params if (!params->duration) timerlat_hist_usage("Invalid -D duration\n"); break; + case 'e': + tevent = trace_event_alloc(optarg); + if (!tevent) { + err_msg("Error alloc trace event"); + exit(EXIT_FAILURE); + } + + if (params->events) + tevent->next = params->events; + + params->events = tevent; + break; case 'E': params->entries = get_llong_from_str(optarg); if ((params->entries < 10) || (params->entries > 9999999)) @@ -791,6 +807,13 @@ int timerlat_hist_main(int argc, char *argv[]) err_msg("Failed to enable the trace instance\n"); goto out_hist; } + + if (params->events) { + retval = trace_events_enable(&record->trace, params->events); + if (retval) + goto out_hist; + } + trace_instance_start(&record->trace); } @@ -828,6 +851,8 @@ int timerlat_hist_main(int argc, char *argv[]) } out_hist: + trace_events_destroy(&record->trace, params->events); + params->events = NULL; timerlat_free_histogram(tool->data); osnoise_destroy_tool(record); osnoise_destroy_tool(tool); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index aef044832964..13bd922ab147 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -30,6 +30,7 @@ struct timerlat_top_params { int quiet; int set_sched; struct sched_attr sched_param; + struct trace_events *events; }; struct timerlat_top_cpu { @@ -267,7 +268,7 @@ 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]] -c cpu-list] [-P priority]", + " [[-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -279,6 +280,7 @@ static void timerlat_top_usage(char *usage) " -d/--duration time[m|h|d]: duration of the session in seconds", " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]", + " -e/--event : enable the in the trace instance, multiple -e are allowed", " -n/--nano: display data in nanoseconds", " -q/--quiet print only a summary at the end", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", @@ -308,6 +310,7 @@ static struct timerlat_top_params *timerlat_top_parse_args(int argc, char **argv) { struct timerlat_top_params *params; + struct trace_events *tevent; long long auto_thresh; int retval; int c; @@ -325,6 +328,7 @@ static struct timerlat_top_params {"cpus", required_argument, 0, 'c'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, + {"event", required_argument, 0, 'e'}, {"help", no_argument, 0, 'h'}, {"irq", required_argument, 0, 'i'}, {"nano", no_argument, 0, 'n'}, @@ -340,7 +344,7 @@ static struct timerlat_top_params /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:Dhi:np:P:qs:t::T:", + c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:", long_options, &option_index); /* detect the end of the options. */ @@ -375,6 +379,17 @@ static struct timerlat_top_params if (!params->duration) timerlat_top_usage("Invalid -D duration\n"); break; + case 'e': + tevent = trace_event_alloc(optarg); + if (!tevent) { + err_msg("Error alloc trace event"); + exit(EXIT_FAILURE); + } + + if (params->events) + tevent->next = params->events; + params->events = tevent; + break; case 'h': case '?': timerlat_top_usage(NULL); @@ -583,6 +598,13 @@ int timerlat_top_main(int argc, char *argv[]) err_msg("Failed to enable the trace instance\n"); goto out_top; } + + if (params->events) { + retval = trace_events_enable(&record->trace, params->events); + if (retval) + goto out_top; + } + trace_instance_start(&record->trace); } @@ -624,6 +646,8 @@ int timerlat_top_main(int argc, char *argv[]) } out_top: + trace_events_destroy(&record->trace, params->events); + params->events = NULL; timerlat_free_top(top->data); osnoise_destroy_tool(record); osnoise_destroy_tool(top); -- cgit v1.2.3 From 336c92b26cf9aee6c5d5907ef49b90d2665e9d70 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:32 +0100 Subject: rtla/trace: Add trace event trigger helpers Add a set of helper functions to allow rtla tools to trigger event actions in the trace instance. Link: https://lkml.kernel.org/r/e0d31abe879a78a5600b64f904d0dfa8f76e4fbb.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/trace.c | 88 +++++++++++++++++++++++++++++++++++++++++- tools/tracing/rtla/src/trace.h | 4 ++ 2 files changed, 91 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 9ad3d8890ec5..7f8661b2724d 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -204,6 +204,8 @@ static void trace_events_free(struct trace_events *events) tevent = tevent->next; + if (free_event->trigger) + free(free_event->trigger); free(free_event->system); free(free_event); } @@ -235,6 +237,48 @@ struct trace_events *trace_event_alloc(const char *event_string) return tevent; } +/* + * trace_event_add_trigger - record an event trigger action + */ +int trace_event_add_trigger(struct trace_events *event, char *trigger) +{ + if (event->trigger) + free(event->trigger); + + event->trigger = strdup(trigger); + if (!event->trigger) + return 1; + + return 0; +} + +/* + * trace_event_disable_trigger - disable an event trigger + */ +static void trace_event_disable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return; + + if (!tevent->trigger_enabled) + return; + + debug_msg("Disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + snprintf(trigger, 1024, "!%s\n", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) + err_msg("Error disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); +} + /* * trace_events_disable - disable all trace events */ @@ -248,14 +292,52 @@ void trace_events_disable(struct trace_instance *instance, while (tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); - if (tevent->enabled) + if (tevent->enabled) { + trace_event_disable_trigger(instance, tevent); tracefs_event_disable(instance->inst, tevent->system, tevent->event); + } tevent->enabled = 0; tevent = tevent->next; } } +/* + * trace_event_enable_trigger - enable an event trigger associated with an event + */ +static int trace_event_enable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return 0; + + if (!tevent->event) { + err_msg("Trigger %s applies only for single events, not for all %s:* events\n", + tevent->trigger, tevent->system); + return 1; + } + + snprintf(trigger, 1024, "%s\n", tevent->trigger); + + debug_msg("Enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) { + err_msg("Error enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + return 1; + } + + tevent->trigger_enabled = 1; + + return 0; +} + /* * trace_events_enable - enable all events */ @@ -275,6 +357,10 @@ int trace_events_enable(struct trace_instance *instance, } + retval = trace_event_enable_trigger(instance, tevent); + if (retval) + return 1; + tevent->enabled = 1; tevent = tevent->next; } diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 9f9751f7ee36..856b26d93064 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -6,7 +6,9 @@ struct trace_events { struct trace_events *next; char *system; char *event; + char *trigger; char enabled; + char trigger_enabled; }; struct trace_instance { @@ -40,3 +42,5 @@ void trace_events_destroy(struct trace_instance *instance, struct trace_events *events); int trace_events_enable(struct trace_instance *instance, struct trace_events *events); + +int trace_event_add_trigger(struct trace_events *event, char *trigger); -- cgit v1.2.3 From 1a754893653f73724d007c2cf95cf6c47d5114c4 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:33 +0100 Subject: rtla: Add --trigger support Add --trigger option. This option enables a trace event trigger to the previous -e sys:event argument, allowing some advanced tracing options. For instance, in a system with CPUs 2:23 isolated, it is possible to get a stack trace of thread wakeup targeting those CPUs while running osnoise with the following command line: # osnoise top -c 2-23 -a 50 -e sched:sched_wakeup --trigger="stacktrace if target_cpu >= 2" This option is available for all current tools. Link: https://lkml.kernel.org/r/07d2983d5f71261d4da89dbaf02efcad100ab8ee.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_options.rst | 3 +++ tools/tracing/rtla/src/osnoise_hist.c | 19 ++++++++++++++++--- tools/tracing/rtla/src/osnoise_top.c | 17 +++++++++++++++-- tools/tracing/rtla/src/timerlat_hist.c | 19 ++++++++++++++++--- tools/tracing/rtla/src/timerlat_top.c | 17 +++++++++++++++-- 5 files changed, 65 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst index 89d783dc3304..e5870b944334 100644 --- a/Documentation/tools/rtla/common_options.rst +++ b/Documentation/tools/rtla/common_options.rst @@ -18,6 +18,9 @@ Enable an event in the trace (**-t**) session. The argument can be a specific event, e.g., **-e** *sched:sched_switch*, or all events of a system group, e.g., **-e** *sched*. Multiple **-e** are allowed. It is only active when **-t** or **-a** are set. +**--trigger** ** + Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. + **-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period* Set scheduling parameters to the osnoise tracer threads, the format to set the priority are: diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index 10d683a98087..3e8f89b4f306 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -428,8 +428,8 @@ 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]] [-c cpu-list] [-P priority] [-b N] [-E N] \\", - " [--no-header] [--no-summary] [--no-index] [--with-zeros]", + " [-T us] [-t[=file]] [-e sys[:event]] [--trigger ] [-c cpu-list] [-P priority] \\", + " [-b N] [-E N] [--no-header] [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -443,6 +443,7 @@ static void osnoise_hist_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]", " -e/--event : enable the in the trace instance, multiple -e are allowed", + " --trigger : enable a trace event trigger to the previous -e event", " -b/--bucket-size N: set the histogram bucket size (default 1)", " -E/--entries N: set the number of entries of the histogram (default 256)", " --no-header: do not print header", @@ -510,13 +511,14 @@ static struct osnoise_hist_params {"no-summary", no_argument, 0, '1'}, {"no-index", no_argument, 0, '2'}, {"with-zeros", no_argument, 0, '3'}, + {"trigger", required_argument, 0, '4'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:0123", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:01234:", long_options, &option_index); /* detect the end of the options. */ @@ -619,6 +621,17 @@ static struct osnoise_hist_params case '3': /* with zeros */ params->with_zeros = 1; break; + case '4': /* trigger */ + if (params->events) { + retval = trace_event_add_trigger(params->events, optarg); + if (retval) { + err_msg("Error adding trigger %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + osnoise_hist_usage("--trigger requires a previous -e\n"); + } + break; default: osnoise_hist_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index 218dc1114139..d16c7ce3e9fa 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -247,7 +247,7 @@ void osnoise_top_usage(char *usage) static const char * const msg[] = { " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", - " [-T us] [-t[=file]] [-e sys[:event]] [-c cpu-list] [-P priority]", + " [-T us] [-t[=file]] [-e sys[:event]] [--trigger ] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -261,6 +261,7 @@ void osnoise_top_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]", " -e/--event : enable the in the trace instance, multiple -e are allowed", + " --trigger : enable a trace event trigger to the previous -e event", " -q/--quiet print only a summary at the end", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", " o:prio - use SCHED_OTHER with prio", @@ -312,13 +313,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) {"stop-total", required_argument, 0, 'S'}, {"threshold", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, + {"trigger", required_argument, 0, '0'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:", + c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:0:", long_options, &option_index); /* Detect the end of the options. */ @@ -402,6 +404,17 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) case 'T': params->threshold = get_llong_from_str(optarg); break; + case '0': /* trigger */ + if (params->events) { + retval = trace_event_add_trigger(params->events, optarg); + if (retval) { + err_msg("Error adding trigger %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + osnoise_top_usage("--trigger requires a previous -e\n"); + } + break; default: osnoise_top_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 2bd668fd36f5..765b5a313bd2 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -430,8 +430,8 @@ 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]] [-c cpu-list] [-P priority] [-E N] [-b N] [--no-irq] \\", - " [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]", + " [-t[=file]] [-e sys[:event]] [--trigger ] [-c cpu-list] [-P priority] [-E N] \\", + " [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -444,6 +444,7 @@ static void timerlat_hist_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]", " -e/--event : enable the in the trace instance, multiple -e are allowed", + " --trigger : enable a trace event trigger to the previous -e event", " -n/--nano: display data in nanoseconds", " -b/--bucket-size N: set the histogram bucket size (default 1)", " -E/--entries N: set the number of entries of the histogram (default 256)", @@ -517,13 +518,14 @@ static struct timerlat_hist_params {"no-summary", no_argument, 0, '3'}, {"no-index", no_argument, 0, '4'}, {"with-zeros", no_argument, 0, '5'}, + {"trigger", required_argument, 0, '6'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:012345", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:", long_options, &option_index); /* detect the end of the options. */ @@ -632,6 +634,17 @@ static struct timerlat_hist_params case '5': /* with zeros */ params->with_zeros = 1; break; + case '6': /* trigger */ + if (params->events) { + retval = trace_event_add_trigger(params->events, optarg); + if (retval) { + err_msg("Error adding trigger %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + timerlat_hist_usage("--trigger requires a previous -e\n"); + } + break; default: timerlat_hist_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 13bd922ab147..76927d4e0dac 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -268,7 +268,7 @@ 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]] [-c cpu-list] [-P priority]", + " [[-t[=file]] [-e sys[:event]] [--trigger ] [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -281,6 +281,7 @@ static void timerlat_top_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]", " -e/--event : enable the in the trace instance, multiple -e are allowed", + " --trigger : enable a trace event trigger to the previous -e event", " -n/--nano: display data in nanoseconds", " -q/--quiet print only a summary at the end", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", @@ -338,13 +339,14 @@ static struct timerlat_top_params {"stack", required_argument, 0, 's'}, {"thread", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, + {"trigger", required_argument, 0, '0'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:", + c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:", long_options, &option_index); /* detect the end of the options. */ @@ -427,6 +429,17 @@ static struct timerlat_top_params else params->trace_output = "timerlat_trace.txt"; break; + case '0': /* trigger */ + if (params->events) { + retval = trace_event_add_trigger(params->events, optarg); + if (retval) { + err_msg("Error adding trigger %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + timerlat_top_usage("--trigger requires a previous -e\n"); + } + break; default: timerlat_top_usage("Invalid option"); } -- cgit v1.2.3 From 5487b6ce267bbafd399f3642062d974832d3eddc Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:34 +0100 Subject: rtla/trace: Add trace event filter helpers Add a set of helper functions to allow rtla tools to filter events in the trace instance. Link: https://lkml.kernel.org/r/12623b1684684549d53b90f4bf66fae44584fd14.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/trace.c | 83 ++++++++++++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 3 ++ 2 files changed, 86 insertions(+) (limited to 'tools') diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 7f8661b2724d..ef44bab0c404 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -204,6 +204,8 @@ static void trace_events_free(struct trace_events *events) tevent = tevent->next; + if (free_event->filter) + free(free_event->filter); if (free_event->trigger) free(free_event->trigger); free(free_event->system); @@ -237,6 +239,21 @@ struct trace_events *trace_event_alloc(const char *event_string) return tevent; } +/* + * trace_event_add_filter - record an event filter + */ +int trace_event_add_filter(struct trace_events *event, char *filter) +{ + if (event->filter) + free(event->filter); + + event->filter = strdup(filter); + if (!event->filter) + return 1; + + return 0; +} + /* * trace_event_add_trigger - record an event trigger action */ @@ -252,6 +269,33 @@ int trace_event_add_trigger(struct trace_events *event, char *trigger) return 0; } +/* + * trace_event_disable_filter - disable an event filter + */ +static void trace_event_disable_filter(struct trace_instance *instance, + struct trace_events *tevent) +{ + char filter[1024]; + int retval; + + if (!tevent->filter) + return; + + if (!tevent->filter_enabled) + return; + + debug_msg("Disabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + + snprintf(filter, 1024, "!%s\n", tevent->filter); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "filter", filter); + if (retval < 0) + err_msg("Error disabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); +} + /* * trace_event_disable_trigger - disable an event trigger */ @@ -293,6 +337,7 @@ void trace_events_disable(struct trace_instance *instance, while (tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); if (tevent->enabled) { + trace_event_disable_filter(instance, tevent); trace_event_disable_trigger(instance, tevent); tracefs_event_disable(instance->inst, tevent->system, tevent->event); } @@ -302,6 +347,41 @@ void trace_events_disable(struct trace_instance *instance, } } +/* + * trace_event_enable_filter - enable an event filter associated with an event + */ +static int trace_event_enable_filter(struct trace_instance *instance, + struct trace_events *tevent) +{ + char filter[1024]; + int retval; + + if (!tevent->filter) + return 0; + + if (!tevent->event) { + err_msg("Filter %s applies only for single events, not for all %s:* events\n", + tevent->filter, tevent->system); + return 1; + } + + snprintf(filter, 1024, "%s\n", tevent->filter); + + debug_msg("Enabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "filter", filter); + if (retval < 0) { + err_msg("Error enabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + return 1; + } + + tevent->filter_enabled = 1; + return 0; +} + /* * trace_event_enable_trigger - enable an event trigger associated with an event */ @@ -356,6 +436,9 @@ int trace_events_enable(struct trace_instance *instance, return 1; } + retval = trace_event_enable_filter(instance, tevent); + if (retval) + return 1; retval = trace_event_enable_trigger(instance, tevent); if (retval) diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 856b26d93064..51ad344c600b 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -6,8 +6,10 @@ struct trace_events { struct trace_events *next; char *system; char *event; + char *filter; char *trigger; char enabled; + char filter_enabled; char trigger_enabled; }; @@ -43,4 +45,5 @@ void trace_events_destroy(struct trace_instance *instance, int trace_events_enable(struct trace_instance *instance, struct trace_events *events); +int trace_event_add_filter(struct trace_events *event, char *filter); int trace_event_add_trigger(struct trace_events *event, char *trigger); -- cgit v1.2.3 From 44f3a37d1d3eb10770c7fec4eb89495d37957a26 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:35 +0100 Subject: rtla: Add --filter support Add --filter option. This option enables a trace event filtering of the previous -e sys:event argument. This option is available for all current tools. Link: https://lkml.kernel.org/r/509d70b6348d3e5bcbf1f07ab725ce08d063149a.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_options.rst | 4 ++++ tools/tracing/rtla/src/osnoise_hist.c | 20 +++++++++++++++++--- tools/tracing/rtla/src/osnoise_top.c | 18 ++++++++++++++++-- tools/tracing/rtla/src/timerlat_hist.c | 20 +++++++++++++++++--- tools/tracing/rtla/src/timerlat_top.c | 18 ++++++++++++++++-- 5 files changed, 70 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst index e5870b944334..afd45bae821f 100644 --- a/Documentation/tools/rtla/common_options.rst +++ b/Documentation/tools/rtla/common_options.rst @@ -18,6 +18,10 @@ Enable an event in the trace (**-t**) session. The argument can be a specific event, e.g., **-e** *sched:sched_switch*, or all events of a system group, e.g., **-e** *sched*. Multiple **-e** are allowed. It is only active when **-t** or **-a** are set. +**--filter** ** + + Filter the previous **-e** *sys:event* event with **. For further information about event filtering see https://www.kernel.org/doc/html/latest/trace/events.html#event-filtering. + **--trigger** ** Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index 3e8f89b4f306..f86b5fb94efd 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -428,8 +428,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]] [--trigger ] [-c cpu-list] [-P priority] \\", - " [-b N] [-E N] [--no-header] [--no-summary] [--no-index] [--with-zeros]", + " [-T us] [-t[=file]] [-e sys[:event]] [--filter ] [--trigger ] \\", + " [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] [--no-index] \\", + " [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -443,6 +444,7 @@ static void osnoise_hist_usage(char *usage) " -D/--debug: print debug info", " -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", " -b/--bucket-size N: set the histogram bucket size (default 1)", " -E/--entries N: set the number of entries of the histogram (default 256)", @@ -512,13 +514,14 @@ static struct osnoise_hist_params {"no-index", no_argument, 0, '2'}, {"with-zeros", no_argument, 0, '3'}, {"trigger", required_argument, 0, '4'}, + {"filter", required_argument, 0, '5'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:01234:", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:01234:5:", long_options, &option_index); /* detect the end of the options. */ @@ -632,6 +635,17 @@ static struct osnoise_hist_params osnoise_hist_usage("--trigger requires a previous -e\n"); } break; + case '5': /* filter */ + if (params->events) { + retval = trace_event_add_filter(params->events, optarg); + if (retval) { + err_msg("Error adding filter %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + osnoise_hist_usage("--filter requires a previous -e\n"); + } + break; default: osnoise_hist_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index d16c7ce3e9fa..c3d75ee456a5 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -247,7 +247,8 @@ void osnoise_top_usage(char *usage) static const char * const msg[] = { " usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\", - " [-T us] [-t[=file]] [-e sys[:event]] [--trigger ] [-c cpu-list] [-P priority]", + " [-T us] [-t[=file]] [-e sys[:event]] [--filter ] [--trigger ] \\", + " [-c cpu-list] [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit", @@ -261,6 +262,7 @@ void osnoise_top_usage(char *usage) " -D/--debug: print debug info", " -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", " -q/--quiet print only a summary at the end", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", @@ -314,13 +316,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) {"threshold", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, {"trigger", required_argument, 0, '0'}, + {"filter", required_argument, 0, '1'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:0:", + c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:0:1:", long_options, &option_index); /* Detect the end of the options. */ @@ -415,6 +418,17 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) osnoise_top_usage("--trigger requires a previous -e\n"); } break; + case '1': /* filter */ + if (params->events) { + retval = trace_event_add_filter(params->events, optarg); + if (retval) { + err_msg("Error adding filter %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + osnoise_top_usage("--filter requires a previous -e\n"); + } + break; default: osnoise_top_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 765b5a313bd2..8341f38fd0b1 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -430,8 +430,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]] [--trigger ] [-c cpu-list] [-P priority] [-E N] \\", - " [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] [--no-index] [--with-zeros]", + " [-t[=file]] [-e sys[:event]] [--filter ] [--trigger ] [-c cpu-list] \\", + " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\", + " [--no-index] [--with-zeros]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -444,6 +445,7 @@ static void timerlat_hist_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|timerlat_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", " -n/--nano: display data in nanoseconds", " -b/--bucket-size N: set the histogram bucket size (default 1)", @@ -519,13 +521,14 @@ static struct timerlat_hist_params {"no-index", no_argument, 0, '4'}, {"with-zeros", no_argument, 0, '5'}, {"trigger", required_argument, 0, '6'}, + {"filter", required_argument, 0, '7'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:", long_options, &option_index); /* detect the end of the options. */ @@ -645,6 +648,17 @@ static struct timerlat_hist_params timerlat_hist_usage("--trigger requires a previous -e\n"); } break; + case '7': /* filter */ + if (params->events) { + retval = trace_event_add_filter(params->events, optarg); + if (retval) { + err_msg("Error adding filter %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + timerlat_hist_usage("--filter requires a previous -e\n"); + } + break; default: timerlat_hist_usage("Invalid option"); } diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 76927d4e0dac..9ce5a09664bc 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -268,7 +268,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]] [--trigger ] [-c cpu-list] [-P priority]", + " [[-t[=file]] [-e sys[:event]] [--filter ] [--trigger ] [-c cpu-list] \\", + " [-P priority]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -281,6 +282,7 @@ static void timerlat_top_usage(char *usage) " -D/--debug: print debug info", " -t/--trace[=file]: save the stopped trace to [file|timerlat_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", " -n/--nano: display data in nanoseconds", " -q/--quiet print only a summary at the end", @@ -340,13 +342,14 @@ static struct timerlat_top_params {"thread", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'}, {"trigger", required_argument, 0, '0'}, + {"filter", required_argument, 0, '1'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:", + c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:1:", long_options, &option_index); /* detect the end of the options. */ @@ -440,6 +443,17 @@ static struct timerlat_top_params timerlat_top_usage("--trigger requires a previous -e\n"); } break; + case '1': /* filter */ + if (params->events) { + retval = trace_event_add_filter(params->events, optarg); + if (retval) { + err_msg("Error adding filter %s\n", optarg); + exit(EXIT_FAILURE); + } + } else { + timerlat_top_usage("--filter requires a previous -e\n"); + } + break; default: timerlat_top_usage("Invalid option"); } -- cgit v1.2.3 From 761916fd02c2525139aca957b8a53fda1d8b3616 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:36 +0100 Subject: rtla/trace: Save event histogram output to a file The hist: trigger generates a histogram in the file sys/event/hist. If the hist: trigger is used, automatically save the histogram output of the event sys:event in the sys_event_hist.txt file. Link: https://lkml.kernel.org/r/b5c906af31d4e022ffe87fb0848fac5c089087c8.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_options.rst | 10 +++++- tools/tracing/rtla/src/trace.c | 53 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_options.rst b/Documentation/tools/rtla/common_options.rst index afd45bae821f..af76df6205d4 100644 --- a/Documentation/tools/rtla/common_options.rst +++ b/Documentation/tools/rtla/common_options.rst @@ -23,7 +23,15 @@ Filter the previous **-e** *sys:event* event with **. For further information about event filtering see https://www.kernel.org/doc/html/latest/trace/events.html#event-filtering. **--trigger** ** - Enable a trace event trigger to the previous **-e** *sys:event*. For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. + Enable a trace event trigger to the previous **-e** *sys:event*. + If the *hist:* trigger is activated, the output histogram will be automatically saved to a file named *system_event_hist.txt*. + For example, the command: + + rtla -t -e osnoise:irq_noise --trigger="hist:key=desc,duration/1000:sort=desc,duration/1000:vals=hitcount" + + Will automatically save the content of the histogram associated to *osnoise:irq_noise* event in *osnoise_irq_noise_hist.txt*. + + For further information about event trigger see https://www.kernel.org/doc/html/latest/trace/events.html#event-triggers. **-P**, **--priority** *o:prio|r:prio|f:prio|d:runtime:period* diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index ef44bab0c404..8249ec4d77cc 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -296,6 +296,57 @@ static void trace_event_disable_filter(struct trace_instance *instance, tevent->event ? : "*", tevent->filter); } +/* + * trace_event_save_hist - save the content of an event hist + * + * If the trigger is a hist: one, save the content of the hist file. + */ +static void trace_event_save_hist(struct trace_instance *instance, + struct trace_events *tevent) +{ + int retval, index, out_fd; + mode_t mode = 0644; + char path[1024]; + char *hist; + + if (!tevent) + return; + + /* trigger enables hist */ + if (!tevent->trigger) + return; + + /* is this a hist: trigger? */ + retval = strncmp(tevent->trigger, "hist:", strlen("hist:")); + if (retval) + return; + + snprintf(path, 1024, "%s_%s_hist.txt", tevent->system, tevent->event); + + printf(" Saving event %s:%s hist to %s\n", tevent->system, tevent->event, path); + + out_fd = creat(path, mode); + if (out_fd < 0) { + err_msg(" Failed to create %s output file\n", path); + return; + } + + hist = tracefs_event_file_read(instance->inst, tevent->system, tevent->event, "hist", 0); + if (!hist) { + err_msg(" Failed to read %s:%s hist file\n", tevent->system, tevent->event); + goto out_close; + } + + index = 0; + do { + index += write(out_fd, &hist[index], strlen(hist) - index); + } while (index < strlen(hist)); + + free(hist); +out_close: + close(out_fd); +} + /* * trace_event_disable_trigger - disable an event trigger */ @@ -314,6 +365,8 @@ static void trace_event_disable_trigger(struct trace_instance *instance, debug_msg("Disabling %s:%s trigger %s\n", tevent->system, tevent->event ? : "*", tevent->trigger); + trace_event_save_hist(instance, tevent); + snprintf(trigger, 1024, "!%s\n", tevent->trigger); retval = tracefs_event_file_write(instance->inst, tevent->system, -- cgit v1.2.3 From 28d2160cb1a18cca87a51345e7df47499447f5a4 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:37 +0100 Subject: rtla: Check for trace off also in the trace instance With the addition of --trigger option, it is also possible to stop the trace from the -t tracing instance using the traceoff trigger. Make rtla tools to check if the trace is stopped also in the trace instance, stopping the execution of the tool. Link: https://lkml.kernel.org/r/59fc7c6f23dddd5c8b7ef1782cf3da51ea2ce0f5.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/osnoise_hist.c | 4 ++-- tools/tracing/rtla/src/osnoise_top.c | 4 ++-- tools/tracing/rtla/src/timerlat_hist.c | 4 ++-- tools/tracing/rtla/src/timerlat_top.c | 4 ++-- tools/tracing/rtla/src/trace.c | 19 +++++++++++++++++++ tools/tracing/rtla/src/trace.h | 1 + 6 files changed, 28 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index f86b5fb94efd..b73b919bd6b4 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -848,7 +848,7 @@ int osnoise_hist_main(int argc, char *argv[]) goto out_hist; } - if (!tracefs_trace_is_on(trace->inst)) + if (trace_is_off(&tool->trace, &record->trace)) break; }; @@ -858,7 +858,7 @@ int osnoise_hist_main(int argc, char *argv[]) return_value = 0; - if (!tracefs_trace_is_on(trace->inst)) { + if (trace_is_off(&tool->trace, &record->trace)) { printf("rtla timelat hit stop tracing\n"); if (params->trace_output) { printf(" Saving trace to %s\n", params->trace_output); diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index c3d75ee456a5..fd29a4049322 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -629,7 +629,7 @@ int osnoise_top_main(int argc, char **argv) if (!params->quiet) osnoise_print_stats(params, tool); - if (!tracefs_trace_is_on(trace->inst)) + if (trace_is_off(&tool->trace, &record->trace)) break; } while (!stop_tracing); @@ -638,7 +638,7 @@ int osnoise_top_main(int argc, char **argv) return_value = 0; - if (!tracefs_trace_is_on(trace->inst)) { + if (trace_is_off(&tool->trace, &record->trace)) { printf("osnoise hit stop tracing\n"); if (params->trace_output) { printf(" Saving trace to %s\n", params->trace_output); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 8341f38fd0b1..17188ccb6e8b 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -861,7 +861,7 @@ int timerlat_hist_main(int argc, char *argv[]) goto out_hist; } - if (!tracefs_trace_is_on(trace->inst)) + if (trace_is_off(&tool->trace, &record->trace)) break; }; @@ -869,7 +869,7 @@ int timerlat_hist_main(int argc, char *argv[]) return_value = 0; - if (!tracefs_trace_is_on(trace->inst)) { + if (trace_is_off(&tool->trace, &record->trace)) { printf("rtla timelat hit stop tracing\n"); if (params->trace_output) { printf(" Saving trace to %s\n", params->trace_output); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 9ce5a09664bc..bf2a50350e61 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -655,7 +655,7 @@ int timerlat_top_main(int argc, char *argv[]) if (!params->quiet) timerlat_print_stats(params, top); - if (!tracefs_trace_is_on(trace->inst)) + if (trace_is_off(&top->trace, &record->trace)) break; }; @@ -664,7 +664,7 @@ int timerlat_top_main(int argc, char *argv[]) return_value = 0; - if (!tracefs_trace_is_on(trace->inst)) { + if (trace_is_off(&top->trace, &record->trace)) { printf("rtla timelat hit stop tracing\n"); if (params->trace_output) { printf(" Saving trace to %s\n", params->trace_output); diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 8249ec4d77cc..5784c9f9e570 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -516,3 +516,22 @@ void trace_events_destroy(struct trace_instance *instance, trace_events_disable(instance, events); trace_events_free(events); } + +int trace_is_off(struct trace_instance *tool, struct trace_instance *trace) +{ + /* + * The tool instance is always present, it is the one used to collect + * data. + */ + if (!tracefs_trace_is_on(tool->inst)) + return 1; + + /* + * The trace instance is only enabled when -t is set. IOW, when the system + * is tracing. + */ + if (trace && !tracefs_trace_is_on(trace->inst)) + return 1; + + return 0; +} diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 51ad344c600b..2e9a89a25615 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -47,3 +47,4 @@ int trace_events_enable(struct trace_instance *instance, int trace_event_add_filter(struct trace_events *event, char *filter); int trace_event_add_trigger(struct trace_events *event, char *trigger); +int trace_is_off(struct trace_instance *tool, struct trace_instance *trace); -- cgit v1.2.3 From 7d38c35167c58153e8b5bea839616d00e90564b9 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:38 +0100 Subject: rtla/osnoise: Fix osnoise hist stop tracing message rtla osnoise hist is printing the following message when hitting stop tracing: printf("rtla timelat hit stop tracing\n"); which is obviosly wrong. s/timerlat/osnoise/ fixing the printf. Link: https://lkml.kernel.org/r/2b8f090556fe37b81d183b74ce271421f131c77b.1646247211.git.bristot@kernel.org Fixes: 829a6c0b5698 ("rtla/osnoise: Add the hist mode") Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/osnoise_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index b73b919bd6b4..c47780fedbaf 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -859,7 +859,7 @@ int osnoise_hist_main(int argc, char *argv[]) return_value = 0; if (trace_is_off(&tool->trace, &record->trace)) { - printf("rtla timelat hit stop tracing\n"); + printf("rtla osnoise hit stop tracing\n"); if (params->trace_output) { printf(" Saving trace to %s\n", params->trace_output); save_trace_to_file(record->trace.inst, params->trace_output); -- cgit v1.2.3 From 7d0dc9576dc3817c483b408715e506c3e9f37bed Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:39 +0100 Subject: rtla/timerlat: Add --dma-latency option Add the --dma-latency to set /dev/cpu_dma_latency to the specified value, this aims to avoid having exit from idle states latencies that could be influencing the analysis. Link: https://lkml.kernel.org/r/72ddb0d913459f13217086dadafad88a7c46dd28.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- .../tools/rtla/common_timerlat_options.rst | 5 ++++ tools/tracing/rtla/src/timerlat_hist.c | 28 ++++++++++++++++-- tools/tracing/rtla/src/timerlat_top.c | 28 ++++++++++++++++-- tools/tracing/rtla/src/utils.c | 33 ++++++++++++++++++++++ tools/tracing/rtla/src/utils.h | 1 + 5 files changed, 91 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/Documentation/tools/rtla/common_timerlat_options.rst b/Documentation/tools/rtla/common_timerlat_options.rst index 14a24a121f5d..bacdea6de7a3 100644 --- a/Documentation/tools/rtla/common_timerlat_options.rst +++ b/Documentation/tools/rtla/common_timerlat_options.rst @@ -21,3 +21,8 @@ Save the stack trace at the *IRQ* if a *Thread* latency is higher than the argument in us. + +**--dma-latency** *us* + Set the /dev/cpu_dma_latency to *us*, aiming to bound exit from idle latencies. + *cyclictest* sets this value to *0* by default, use **--dma-latency** *0* to have + similar results. diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 17188ccb6e8b..0f6ce80a198a 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -28,6 +28,7 @@ struct timerlat_hist_params { int output_divisor; int duration; int set_sched; + int dma_latency; struct sched_attr sched_param; struct trace_events *events; @@ -432,7 +433,7 @@ static void timerlat_hist_usage(char *usage) " 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] \\", " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\", - " [--no-index] [--with-zeros]", + " [--no-index] [--with-zeros] [--dma-latency us]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -456,6 +457,7 @@ static void timerlat_hist_usage(char *usage) " --no-summary: do not print summary", " --no-index: do not print index", " --with-zeros: print zero only entries", + " --dma-latency us: set /dev/cpu_dma_latency latency to reduce exit from idle latency", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", " o:prio - use SCHED_OTHER with prio", " r:prio - use SCHED_RR with prio", @@ -492,6 +494,9 @@ static struct timerlat_hist_params if (!params) exit(1); + /* disabled by default */ + params->dma_latency = -1; + /* display data in microseconds */ params->output_divisor = 1000; params->bucket_size = 1; @@ -522,13 +527,14 @@ static struct timerlat_hist_params {"with-zeros", no_argument, 0, '5'}, {"trigger", required_argument, 0, '6'}, {"filter", required_argument, 0, '7'}, + {"dma-latency", required_argument, 0, '8'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:", + c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:8:", long_options, &option_index); /* detect the end of the options. */ @@ -659,6 +665,13 @@ static struct timerlat_hist_params timerlat_hist_usage("--filter requires a previous -e\n"); } break; + case '8': + params->dma_latency = get_llong_from_str(optarg); + if (params->dma_latency < 0 || params->dma_latency > 10000) { + err_msg("--dma-latency needs to be >= 0 and < 10000"); + exit(EXIT_FAILURE); + } + break; default: timerlat_hist_usage("Invalid option"); } @@ -791,6 +804,7 @@ int timerlat_hist_main(int argc, char *argv[]) struct osnoise_tool *record = NULL; struct osnoise_tool *tool = NULL; struct trace_instance *trace; + int dma_latency_fd = -1; int return_value = 1; int retval; @@ -826,6 +840,14 @@ int timerlat_hist_main(int argc, char *argv[]) } } + if (params->dma_latency >= 0) { + dma_latency_fd = set_cpu_dma_latency(params->dma_latency); + if (dma_latency_fd < 0) { + err_msg("Could not set /dev/cpu_dma_latency.\n"); + goto out_hist; + } + } + trace_instance_start(trace); if (params->trace_output) { @@ -878,6 +900,8 @@ int timerlat_hist_main(int argc, char *argv[]) } out_hist: + if (dma_latency_fd >= 0) + close(dma_latency_fd); trace_events_destroy(&record->trace, params->events); params->events = NULL; timerlat_free_histogram(tool->data); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index bf2a50350e61..53f4cdfd395e 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -29,6 +29,7 @@ struct timerlat_top_params { int duration; int quiet; int set_sched; + int dma_latency; struct sched_attr sched_param; struct trace_events *events; }; @@ -269,7 +270,7 @@ static void timerlat_top_usage(char *usage) "", " 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] \\", - " [-P priority]", + " [-P priority] [--dma-latency us]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", @@ -286,6 +287,7 @@ static void timerlat_top_usage(char *usage) " --trigger : enable a trace event trigger to the previous -e event", " -n/--nano: display data in nanoseconds", " -q/--quiet print only a summary at the end", + " --dma-latency us: set /dev/cpu_dma_latency latency to reduce exit from idle latency", " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters", " o:prio - use SCHED_OTHER with prio", " r:prio - use SCHED_RR with prio", @@ -322,6 +324,9 @@ static struct timerlat_top_params if (!params) exit(1); + /* disabled by default */ + params->dma_latency = -1; + /* display data in microseconds */ params->output_divisor = 1000; @@ -343,13 +348,14 @@ static struct timerlat_top_params {"trace", optional_argument, 0, 't'}, {"trigger", required_argument, 0, '0'}, {"filter", required_argument, 0, '1'}, + {"dma-latency", required_argument, 0, '2'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:1:", + c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:1:2:", long_options, &option_index); /* detect the end of the options. */ @@ -454,6 +460,13 @@ static struct timerlat_top_params timerlat_top_usage("--filter requires a previous -e\n"); } break; + case '2': /* dma-latency */ + params->dma_latency = get_llong_from_str(optarg); + if (params->dma_latency < 0 || params->dma_latency > 10000) { + err_msg("--dma-latency needs to be >= 0 and < 10000"); + exit(EXIT_FAILURE); + } + break; default: timerlat_top_usage("Invalid option"); } @@ -582,6 +595,7 @@ int timerlat_top_main(int argc, char *argv[]) struct osnoise_tool *record = NULL; struct osnoise_tool *top = NULL; struct trace_instance *trace; + int dma_latency_fd = -1; int return_value = 1; int retval; @@ -617,6 +631,14 @@ int timerlat_top_main(int argc, char *argv[]) } } + if (params->dma_latency >= 0) { + dma_latency_fd = set_cpu_dma_latency(params->dma_latency); + if (dma_latency_fd < 0) { + err_msg("Could not set /dev/cpu_dma_latency.\n"); + goto out_top; + } + } + trace_instance_start(trace); if (params->trace_output) { @@ -673,6 +695,8 @@ int timerlat_top_main(int argc, char *argv[]) } out_top: + if (dma_latency_fd >= 0) + close(dma_latency_fd); trace_events_destroy(&record->trace, params->events); params->events = NULL; timerlat_free_top(top->data); diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index ffaf8ec84001..da2b590edaed 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -431,3 +432,35 @@ int parse_prio(char *arg, struct sched_attr *sched_param) } return 0; } + +/* + * set_cpu_dma_latency - set the /dev/cpu_dma_latecy + * + * This is used to reduce the exit from idle latency. The value + * will be reset once the file descriptor of /dev/cpu_dma_latecy + * is closed. + * + * Return: the /dev/cpu_dma_latecy file descriptor + */ +int set_cpu_dma_latency(int32_t latency) +{ + int retval; + int fd; + + fd = open("/dev/cpu_dma_latency", O_RDWR); + if (fd < 0) { + err_msg("Error opening /dev/cpu_dma_latency\n"); + return -1; + } + + retval = write(fd, &latency, 4); + if (retval < 1) { + err_msg("Error setting /dev/cpu_dma_latency\n"); + close(fd); + return -1; + } + + debug_msg("Set /dev/cpu_dma_latency to %d\n", latency); + + return fd; +} diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h index 9aa962319ca2..fa08e374870a 100644 --- a/tools/tracing/rtla/src/utils.h +++ b/tools/tracing/rtla/src/utils.h @@ -54,3 +54,4 @@ struct sched_attr { int parse_prio(char *arg, struct sched_attr *sched_param); int set_comm_sched_attr(const char *comm, struct sched_attr *attr); +int set_cpu_dma_latency(int32_t latency); -- cgit v1.2.3 From 75016ca3acd0de79868ef5b0694195fe05288ade Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 2 Mar 2022 20:01:40 +0100 Subject: rtla: Tools main loop cleanup I probably started using "do {} while();", but changed all but osnoise_top to "while(){};" leaving the ; behind. Cleanup the main loop code, making all tools use "while() {}" Changcheng Deng reported this problem, as reported by coccicheck: Fix the following coccicheck review: ./tools/tracing/rtla/src/timerlat_hist.c: 800: 2-3: Unneeded semicolon ./tools/tracing/rtla/src/osnoise_hist.c: 776: 2-3: Unneeded semicolon ./tools/tracing/rtla/src/timerlat_top.c: 596: 2-3: Unneeded semicolon Link: https://lkml.kernel.org/r/3c1642110aa87c396f5da4a037dabc72dbb9c601.1646247211.git.bristot@kernel.org Cc: Daniel Bristot de Oliveira Cc: Clark Williams Cc: Juri Lelli Cc: Jonathan Corbet Reported-by: Changcheng Deng Reported-by: Zeal Robot Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/osnoise_hist.c | 2 +- tools/tracing/rtla/src/osnoise_top.c | 4 ++-- tools/tracing/rtla/src/timerlat_hist.c | 2 +- tools/tracing/rtla/src/timerlat_top.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index c47780fedbaf..b4380d45cacd 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -850,7 +850,7 @@ int osnoise_hist_main(int argc, char *argv[]) if (trace_is_off(&tool->trace, &record->trace)) break; - }; + } osnoise_read_trace_hist(tool); diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index fd29a4049322..72c2fd6ce005 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -612,7 +612,7 @@ int osnoise_top_main(int argc, char **argv) tool->start_time = time(NULL); osnoise_top_set_signals(params); - do { + while (!stop_tracing) { sleep(params->sleep_time); retval = tracefs_iterate_raw_events(trace->tep, @@ -632,7 +632,7 @@ int osnoise_top_main(int argc, char **argv) if (trace_is_off(&tool->trace, &record->trace)) break; - } while (!stop_tracing); + } osnoise_print_stats(params, tool); diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c index 0f6ce80a198a..dc908126c610 100644 --- a/tools/tracing/rtla/src/timerlat_hist.c +++ b/tools/tracing/rtla/src/timerlat_hist.c @@ -885,7 +885,7 @@ int timerlat_hist_main(int argc, char *argv[]) if (trace_is_off(&tool->trace, &record->trace)) break; - }; + } timerlat_print_stats(params, tool); diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index 53f4cdfd395e..1f754c3df53f 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -680,7 +680,7 @@ int timerlat_top_main(int argc, char *argv[]) if (trace_is_off(&top->trace, &record->trace)) break; - }; + } timerlat_print_stats(params, top); -- cgit v1.2.3