Some rtla features
Subsystems (2)
cover Some rtla features
This set introduces some tracing facilities to rtla tools.
It adds the possibility to change the tracing_thresh to osnoise, allowing a fine tune of OS noise detection.
It also adds the auto tracing feature (-a threshold us), which aims helping the first approach to a problem by setting common tracing features with a single parameter.
Finally, it also allow osnoise top and timerlat top to enable additional trace events via (possible multiple) -e sys:event options.
Daniel Bristot de Oliveira (7):
rtla/osnoise: Add support to adjust the tracing_thresh rtla/osnoise: Add an option to set the threshold rtla/osnoise: Add the automatic trace option rtla/timerlat: Add the automatic trace option rtla/trace: Add trace events helpers rtla/osnoise: Add -e/--event option rtla/timerlat: Add -e/--event option
.../tools/rtla/common_osnoise_options.rst | 10 ++ .../tools/rtla/common_timerlat_options.rst | 7 ++ tools/tracing/rtla/src/osnoise.c | 83 ++++++++++++++ tools/tracing/rtla/src/osnoise.h | 8 ++ tools/tracing/rtla/src/osnoise_hist.c | 35 +++++- tools/tracing/rtla/src/osnoise_top.c | 58 +++++++++- tools/tracing/rtla/src/timerlat_hist.c | 24 +++- tools/tracing/rtla/src/timerlat_top.c | 50 ++++++++- tools/tracing/rtla/src/trace.c | 105 ++++++++++++++++++ tools/tracing/rtla/src/trace.h | 15 +++ 10 files changed, 382 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/7 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.
--- tools/tracing/rtla/src/osnoise.c | 83 ++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/osnoise.h | 8 +++ 2 files changed, 91 insertions(+)
tools/tracing/rtla/src/osnoise.c +83 -0
@@ -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); }
tools/tracing/rtla/src/osnoise.h +8 -0
@@ -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);
Signature · 1 line
2.34.1
PATCH 2/7 rtla/osnoise: Add an option to set the threshold
In reply to Daniel Bristot de OliveiraAdd 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.
--- .../tools/rtla/common_osnoise_options.rst | 5 +++++ tools/tracing/rtla/src/osnoise_hist.c | 16 +++++++++++++++- tools/tracing/rtla/src/osnoise_top.c | 16 +++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-)
Documentation/tools/rtla/common_osnoise_options.rst +5 -0
@@ -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*.
tools/tracing/rtla/src/osnoise_hist.c +15 -1
@@ -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;
@@ -434,6 +435,7 @@ static void osnoise_hist_usage(char *usage)" -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_paramscase '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:
tools/tracing/rtla/src/osnoise_top.c +15 -1
@@ -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;
@@ -252,6 +253,7 @@ void osnoise_top_usage(char *usage)" -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:
Signature · 1 line
2.34.1
PATCH 3/7 rtla/osnoise: Add the automatic trace option
In reply to Daniel Bristot de OliveiraAdd the -a/--auto <arg in us> 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.
--- .../tools/rtla/common_osnoise_options.rst | 5 +++++ tools/tracing/rtla/src/osnoise_hist.c | 21 +++++++++++++++---- tools/tracing/rtla/src/osnoise_top.c | 17 +++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-)
Documentation/tools/rtla/common_osnoise_options.rst +5 -0
@@ -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.
tools/tracing/rtla/src/osnoise_hist.c +17 -4
@@ -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[=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] [-a us] [-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]" ,"" ," -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_paramswhile (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_paramsbreak ;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 ))
tools/tracing/rtla/src/osnoise_top.c +15 -2
@@ -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[=file]] \\" , +" usage: rtla osnoise [top] [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s 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 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)
Signature · 1 line
2.34.1
PATCH 4/7 rtla/timerlat: Add the automatic trace option
In reply to Daniel Bristot de OliveiraAdd the -a/--auto <arg in us> 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.
--- .../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(-)
Documentation/tools/rtla/common_timerlat_options.rst +7 -0
@@ -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.
tools/tracing/rtla/src/timerlat_hist.c +20 -4
@@ -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_paramswhile (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_paramsbreak ;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)
tools/tracing/rtla/src/timerlat_top.c +19 -3
@@ -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_paramswhile (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_paramsbreak ;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)
Signature · 1 line
2.34.1
PATCH 5/7 rtla/trace: Add trace events helpers
In reply to Daniel Bristot de OliveiraAdd a set of helper functions to allow the rtla tools to enable additional tracepoints in the trace instance.
--- tools/tracing/rtla/src/trace.c | 105 +++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 15 +++++ 2 files changed, 120 insertions(+)
tools/tracing/rtla/src/trace.c +105 -0
@@ -190,3 +190,108 @@ int trace_instance_start(struct trace_instance *trace) {return tracefs_trace_on (trace->inst); } + +/* +* free_trace_events - free a list of trace events +*/ +static void free_trace_events (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); + } +} + +/* +* alloc_trace_event - alloc and parse a single trace event +*/ +struct trace_events *alloc_trace_event (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; +} + +/* +* disable_trace_events - disable all trace events +*/ +void disable_trace_events (struct trace_instance *instance, +struct trace_events *events) +{ +struct trace_events *tevent = events; + +if (!events) +return ; + +while (tevent) { +if (tevent->enabled) +tracefs_event_disable (instance->inst, tevent->system, tevent->event); + + tevent->enabled =0 ; + tevent = tevent->next; + } +} + +/* +* enable_trace_events - enable all events +*/ +int enable_trace_events (struct trace_instance *instance, +struct trace_events *events) +{ +struct trace_events *tevent = events; +int retval; + +while (tevent) { + retval =tracefs_event_enable (instance->inst, tevent->system, tevent->event); +if (retval <0 ) { +if (tevent->event) +err_msg ("Error enabling event %s:%s\n" , + tevent->system, tevent->event); +else +err_msg ("Error enabling events %s:*\n" , + tevent->system); +return 1 ; + } + + tevent->enabled =1 ; + tevent = tevent->next; + } + +return 0 ; +} + +/* +* destroy_trace_events - disable and free all trace events +*/ +void destroy_trace_events (struct trace_instance *instance, +struct trace_events *events) +{ +if (!events) +return ; + +disable_trace_events (instance, events); +free_trace_events (events); +}
tools/tracing/rtla/src/trace.h +15 -0
@@ -2,6 +2,13 @@#include <tracefs.h> #include <stddef.h> +struct trace_events { +struct trace_events *next; +char *system; +char *event; +int 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 *alloc_trace_event (const char *event_string); +void disable_trace_events (struct trace_instance *instance, +struct trace_events *events); +void destroy_trace_events (struct trace_instance *instance, +struct trace_events *events); +int enable_trace_events (struct trace_instance *instance, +struct trace_events *events);
Signature · 1 line
2.34.1
PATCH 6/7 rtla/osnoise: Add -e/--event option
In reply to Daniel Bristot de OliveiraAdd the -e <sys:[event]> option. This option allows the osnoise top to enable additional events to the trace instance. Multiple -e are enabled, and it implies the -t option (if not already set).
--- tools/tracing/rtla/src/osnoise_top.c | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
tools/tracing/rtla/src/osnoise_top.c +28 -1
@@ -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 {
@@ -286,6 +287,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 +301,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 +317,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 +350,21 @@ 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 =alloc_trace_event (optarg); +if (!tevent) { +err_msg ("error alloc trace event" ); +exit (EXIT_FAILURE ); + } + +if (params->events) + tevent->next = params->events; + params->events = tevent; + +/* if -e && !-t -> -t */ +if (!params->trace_output) + params->trace_output ="osnoise_trace.txt" ; +break ;case 'h' :case '?' :osnoise_top_usage (NULL );
@@ -556,6 +574,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 =enable_trace_events (&record->trace, params->events); +if (retval) + goto out_top; + } +trace_instance_start (&record->trace); }
@@ -597,6 +622,8 @@ int osnoise_top_main(int argc, char **argv) } out_top: +destroy_trace_events (&record->trace, params->events); + params->events =NULL ;osnoise_free_top (tool->data);osnoise_destroy_tool (record);osnoise_destroy_tool (tool);
Signature · 1 line
2.34.1
PATCH 7/7 rtla/timerlat: Add -e/--event option
In reply to Daniel Bristot de OliveiraAdd the -e <sys:[event]> option. This option allows the timerlat top to enable additional events to the trace instance. Multiple -e are enabled, and it implies the -t option (if not already set).
--- tools/tracing/rtla/src/timerlat_top.c | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
tools/tracing/rtla/src/timerlat_top.c +30 -2
@@ -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 <sys:event>: enable the <sys:event> 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,21 @@ static struct timerlat_top_paramsif (!params->duration)timerlat_top_usage ("Invalid -D duration\n" );break ; +case 'e' : + tevent =alloc_trace_event (optarg); +if (!tevent) { +err_msg ("error alloc trace event" ); +exit (EXIT_FAILURE ); + } + +if (params->events) + tevent->next = params->events; + params->events = tevent; + +/* if -e && !-t -> -t */ +if (!params->trace_output) + params->trace_output ="timerlat_trace.txt" ; +break ;case 'h' :case '?' :timerlat_top_usage (NULL );
@@ -583,6 +602,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 =enable_trace_events (&record->trace, params->events); +if (retval) + goto out_top; + } +trace_instance_start (&record->trace); }
@@ -624,6 +650,8 @@ int timerlat_top_main(int argc, char *argv[]) } out_top: +destroy_trace_events (&record->trace, params->events); + params->events =NULL ;timerlat_free_top (top->data);osnoise_destroy_tool (record);osnoise_destroy_tool (top);
Signature · 1 line
2.34.1