From a99d0d5f4a53f31e0d9c8f3d03436d9709116b6b Mon Sep 17 00:00:00 2001 From: Rong Tao Date: Mon, 24 Apr 2023 18:46:06 +0800 Subject: rtla: Add .gitignore file Add .gitignore file to ignore the rtla binary. Link: https://lore.kernel.org/linux-trace-devel/tencent_3C22A3418CD06196C2E5A84AE3EBC2281206@qq.com Signed-off-by: Rong Tao Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/tracing/rtla/.gitignore diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore new file mode 100644 index 000000000000..e9df32419b2b --- /dev/null +++ b/tools/tracing/rtla/.gitignore @@ -0,0 +1 @@ +/rtla -- cgit v1.2.3 From 54a0dffa62de0c91b406ff32082a121ccfa0d7f1 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 24 Apr 2023 10:47:30 +0100 Subject: rv: Fix addition on an uninitialized variable 'run' The variable run is not initialized however it is being accumulated by the return value from the call to ikm_run_monitor. Fix this by initializing run to zero at the start of the function. Link: https://lkml.kernel.org/r/20230424094730.105313-1-colin.i.king@gmail.com Fixes: 4bc4b131d44c ("rv: Add rv tool") Signed-off-by: Colin Ian King Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/verification/rv/src/rv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c index e601cd9c411e..1ddb85532816 100644 --- a/tools/verification/rv/src/rv.c +++ b/tools/verification/rv/src/rv.c @@ -74,7 +74,7 @@ static void rv_list(int argc, char **argv) static void rv_mon(int argc, char **argv) { char *monitor_name; - int i, run; + int i, run = 0; static const char *const usage[] = { "", -- cgit v1.2.3 From 73e053cbd00ed890abfc812d6c602cbfa8d234dc Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 18 Apr 2023 16:00:18 +0100 Subject: rv: Remove redundant assignment to variable retval Variable retval is being assigned a value that is never read, it is being re-assigned a new value in both paths of a following if statement. Remove the assignment. Cleans up clang-scan warning: kernel/trace/rv/rv.c:293:2: warning: Value stored to 'retval' is never read [deadcode.DeadStores] retval = count; Link: https://lkml.kernel.org/r/20230418150018.3123753-1-colin.i.king@gmail.com Cc: Masami Hiramatsu Signed-off-by: Colin Ian King Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/rv/rv.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index 7e9061828c24..2f68e93fff0b 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -290,8 +290,6 @@ static ssize_t monitor_enable_write_data(struct file *filp, const char __user *u if (retval) return retval; - retval = count; - mutex_lock(&rv_interface_lock); if (val) -- cgit v1.2.3 From 9fa48a2477de747b644c778a1e35d679cabcd917 Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Wed, 29 Mar 2023 18:23:32 +0200 Subject: rtla/timerlat: Add auto-analysis only option Parsing and formating timerlat data might consume a reasonable amount of CPU time on very large systems, or when timerlat has a too short period. Add an option to run timerlat with auto-analysis enabled while skipping the statistics parsing. In this mode, rtla timerlat periodically checks if the tracing is on, going to sleep waiting for the stop tracing condition to stop tracing, or for the tracing session to finish. If the stop tracing condition is hit, the tool prints the auto analysis. Otherwise, the tool prints the max observed latency and exit. The max observed latency is captured via tracing_max_latency. Link: https://lore.kernel.org/linux-trace-devel/4dc514d1d5dc353c537a466a9b5af44c266b6da2.1680106912.git.bristot@kernel.org Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- Documentation/tools/rtla/common_timerlat_aa.rst | 7 ++++ tools/tracing/rtla/src/timerlat_top.c | 49 ++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Documentation/tools/rtla/common_timerlat_aa.rst b/Documentation/tools/rtla/common_timerlat_aa.rst index 077029e6b289..795b9fbcbc6d 100644 --- a/Documentation/tools/rtla/common_timerlat_aa.rst +++ b/Documentation/tools/rtla/common_timerlat_aa.rst @@ -5,3 +5,10 @@ **--no-aa** disable auto-analysis, reducing rtla timerlat cpu usage + +**--aa-only** *us* + + Set stop tracing conditions and run without collecting and displaying statistics. + Print the auto-analysis if the system hits the stop tracing condition. This option + is useful to reduce rtla timerlat CPU, enabling the debug without the overhead of + collecting the statistics. diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c index eea5b3357e27..92c658c64f28 100644 --- a/tools/tracing/rtla/src/timerlat_top.c +++ b/tools/tracing/rtla/src/timerlat_top.c @@ -33,6 +33,7 @@ struct timerlat_top_params { int set_sched; int dma_latency; int no_aa; + int aa_only; int dump_tasks; struct sched_attr sched_param; struct trace_events *events; @@ -142,10 +143,12 @@ timerlat_top_handler(struct trace_seq *s, struct tep_record *record, top = container_of(trace, struct osnoise_tool, trace); params = top->params; - tep_get_field_val(s, event, "context", record, &thread, 1); - tep_get_field_val(s, event, "timer_latency", record, &latency, 1); + if (!params->aa_only) { + tep_get_field_val(s, event, "context", record, &thread, 1); + tep_get_field_val(s, event, "timer_latency", record, &latency, 1); - timerlat_top_update(top, cpu, thread, latency); + timerlat_top_update(top, cpu, thread, latency); + } if (!params->no_aa) timerlat_aa_handler(s, record, event, context); @@ -250,6 +253,9 @@ timerlat_print_stats(struct timerlat_top_params *params, struct osnoise_tool *to static int nr_cpus = -1; int i; + if (params->aa_only) + return; + if (nr_cpus == -1) nr_cpus = sysconf(_SC_NPROCESSORS_CONF); @@ -279,10 +285,11 @@ 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] [--dma-latency us]", + " [-P priority] [--dma-latency us] [--aa-only us]", "", " -h/--help: print this menu", " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", + " --aa-only us: stop if latency is hit, only printing the auto analysis (reduces CPU usage)", " -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", @@ -362,13 +369,14 @@ static struct timerlat_top_params {"dma-latency", required_argument, 0, '2'}, {"no-aa", no_argument, 0, '3'}, {"dump-tasks", no_argument, 0, '4'}, + {"aa-only", 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:d:De:hi:np:P:qs:t::T:0:1:2:34", + c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:1:2:345:", long_options, &option_index); /* detect the end of the options. */ @@ -389,6 +397,20 @@ static struct timerlat_top_params /* set trace */ params->trace_output = "timerlat_trace.txt"; break; + case '5': + /* it is here because it is similar to -a */ + auto_thresh = get_llong_from_str(optarg); + + /* set thread stop to auto_thresh */ + params->stop_total_us = auto_thresh; + params->stop_us = auto_thresh; + + /* get stack trace */ + params->print_stack = auto_thresh; + + /* set aa_only to avoid parsing the trace */ + params->aa_only = 1; + break; case 'c': retval = parse_cpu_list(optarg, ¶ms->monitored_cpus); if (retval) @@ -503,6 +525,9 @@ static struct timerlat_top_params if (!params->stop_us && !params->stop_total_us) params->no_aa = 1; + if (params->no_aa && params->aa_only) + timerlat_top_usage("--no-aa and --aa-only are mutually exclusive!"); + return params; } @@ -634,6 +659,7 @@ int timerlat_top_main(int argc, char *argv[]) struct trace_instance *trace; int dma_latency_fd = -1; int return_value = 1; + char *max_lat; int retval; params = timerlat_top_parse_args(argc, argv); @@ -700,6 +726,9 @@ int timerlat_top_main(int argc, char *argv[]) while (!stop_tracing) { sleep(params->sleep_time); + if (params->aa_only && !trace_is_off(&top->trace, &record->trace)) + continue; + retval = tracefs_iterate_raw_events(trace->tep, trace->inst, NULL, @@ -733,6 +762,16 @@ int timerlat_top_main(int argc, char *argv[]) printf(" Saving trace to %s\n", params->trace_output); save_trace_to_file(record->trace.inst, params->trace_output); } + } else if (params->aa_only) { + /* + * If the trace did not stop with --aa-only, at least print the + * max known latency. + */ + max_lat = tracefs_instance_file_read(trace->inst, "tracing_max_latency", NULL); + if (max_lat) { + printf(" Max latency was %s\n", max_lat); + free(max_lat); + } } out_top: -- cgit v1.2.3 From 82253a271aae9271fcf0aaa5e0ecc6dd38fb872b Mon Sep 17 00:00:00 2001 From: Daniel Bristot de Oliveira Date: Fri, 24 Mar 2023 20:26:42 +0100 Subject: rtla/timerlat: Fix "Previous IRQ" auto analysis' line The "Previous IRQ interference" line is misaligned and without a \n, breaking the tool's output: ## CPU 12 hit stop tracing, analyzing it ## Previous IRQ interference: up to 2.22 us IRQ handler delay: 18.06 us (0.00 %) IRQ latency: 18.52 us Timerlat IRQ duration: 4.41 us (0.00 %) Blocking thread: 216.93 us (0.03 %) Fix the output: ## CPU 7 hit stop tracing, analyzing it ## Previous IRQ interference: up to 8.93 us IRQ handler delay: 0.98 us (0.00 %) IRQ latency: 2.95 us Timerlat IRQ duration: 11.26 us (0.03 %) Link: https://lore.kernel.org/linux-trace-devel/8b5819077f15ccf24745c9bf3205451e16ee32d9.1679685525.git.bristot@kernel.org Fixes: 27e348b221f6 ("rtla/timerlat: Add auto-analysis core") Cc: Masami Hiramatsu Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- tools/tracing/rtla/src/timerlat_aa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/timerlat_aa.c index ec4e0f4b0e6c..1843fff66da5 100644 --- a/tools/tracing/rtla/src/timerlat_aa.c +++ b/tools/tracing/rtla/src/timerlat_aa.c @@ -548,7 +548,7 @@ static void timerlat_thread_analysis(struct timerlat_aa_data *taa_data, int cpu, exp_irq_ts = taa_data->timer_irq_start_time - taa_data->timer_irq_start_delay; if (exp_irq_ts < taa_data->prev_irq_timstamp + taa_data->prev_irq_duration) - printf(" Previous IRQ interference: \t up to %9.2f us", + printf(" Previous IRQ interference: \t\t up to %9.2f us\n", ns_to_usf(taa_data->prev_irq_duration)); /* -- cgit v1.2.3