1616#include "utils.h"
1717#include "osnoise.h"
1818#include "timerlat.h"
19+ #include "timerlat_aa.h"
1920
2021struct timerlat_hist_params {
2122 char * cpus ;
@@ -34,6 +35,8 @@ struct timerlat_hist_params {
3435 int dma_latency ;
3536 int cgroup ;
3637 int hk_cpus ;
38+ int no_aa ;
39+ int dump_tasks ;
3740 cpu_set_t hk_cpu_set ;
3841 struct sched_attr sched_param ;
3942 struct trace_events * events ;
@@ -438,7 +441,7 @@ static void timerlat_hist_usage(char *usage)
438441 " usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\" ,
439442 " [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\" ,
440443 " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\" ,
441- " [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]]" ,
444+ " [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] " ,
442445 "" ,
443446 " -h/--help: print this menu" ,
444447 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit" ,
@@ -450,12 +453,14 @@ static void timerlat_hist_usage(char *usage)
450453 " -H/--house-keeping cpus: run rtla control threads only on the given cpus" ,
451454 " -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited" ,
452455 " -d/--duration time[m|h|d]: duration of the session in seconds" ,
456+ " --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)" ,
453457 " -D/--debug: print debug info" ,
454458 " -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]" ,
455459 " -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed" ,
456460 " --filter <filter>: enable a trace event filter to the previous -e event" ,
457461 " --trigger <trigger>: enable a trace event trigger to the previous -e event" ,
458462 " -n/--nano: display data in nanoseconds" ,
463+ " --no-aa: disable auto-analysis, reducing rtla timerlat cpu usage" ,
459464 " -b/--bucket-size N: set the histogram bucket size (default 1)" ,
460465 " -E/--entries N: set the number of entries of the histogram (default 256)" ,
461466 " --no-irq: ignore IRQ latencies" ,
@@ -537,13 +542,15 @@ static struct timerlat_hist_params
537542 {"trigger" , required_argument , 0 , '6' },
538543 {"filter" , required_argument , 0 , '7' },
539544 {"dma-latency" , required_argument , 0 , '8' },
545+ {"no-aa" , no_argument , 0 , '9' },
546+ {"dump-task" , no_argument , 0 , '\1' },
540547 {0 , 0 , 0 , 0 }
541548 };
542549
543550 /* getopt_long stores the option index here. */
544551 int option_index = 0 ;
545552
546- c = getopt_long (argc , argv , "a:c:C::b:d:e:E:DhH:i:np:P:s:t::T:0123456:7:8:" ,
553+ c = getopt_long (argc , argv , "a:c:C::b:d:e:E:DhH:i:np:P:s:t::T:0123456:7:8:9\1 " ,
547554 long_options , & option_index );
548555
549556 /* detect the end of the options. */
@@ -556,6 +563,7 @@ static struct timerlat_hist_params
556563
557564 /* set thread stop to auto_thresh */
558565 params -> stop_total_us = auto_thresh ;
566+ params -> stop_us = auto_thresh ;
559567
560568 /* get stack trace */
561569 params -> print_stack = auto_thresh ;
@@ -699,6 +707,12 @@ static struct timerlat_hist_params
699707 exit (EXIT_FAILURE );
700708 }
701709 break ;
710+ case '9' :
711+ params -> no_aa = 1 ;
712+ break ;
713+ case '\1' :
714+ params -> dump_tasks = 1 ;
715+ break ;
702716 default :
703717 timerlat_hist_usage ("Invalid option" );
704718 }
@@ -715,6 +729,12 @@ static struct timerlat_hist_params
715729 if (params -> no_index && !params -> with_zeros )
716730 timerlat_hist_usage ("no-index set with with-zeros is not set - it does not make sense" );
717731
732+ /*
733+ * Auto analysis only happens if stop tracing, thus:
734+ */
735+ if (!params -> stop_us && !params -> stop_total_us )
736+ params -> no_aa = 1 ;
737+
718738 return params ;
719739}
720740
@@ -848,6 +868,7 @@ int timerlat_hist_main(int argc, char *argv[])
848868 struct timerlat_hist_params * params ;
849869 struct osnoise_tool * record = NULL ;
850870 struct osnoise_tool * tool = NULL ;
871+ struct osnoise_tool * aa = NULL ;
851872 struct trace_instance * trace ;
852873 int dma_latency_fd = -1 ;
853874 int return_value = 1 ;
@@ -919,6 +940,26 @@ int timerlat_hist_main(int argc, char *argv[])
919940 trace_instance_start (& record -> trace );
920941 }
921942
943+ if (!params -> no_aa ) {
944+ aa = osnoise_init_tool ("timerlat_aa" );
945+ if (!aa )
946+ goto out_hist ;
947+
948+ retval = timerlat_aa_init (aa , params -> dump_tasks );
949+ if (retval ) {
950+ err_msg ("Failed to enable the auto analysis instance\n" );
951+ goto out_hist ;
952+ }
953+
954+ retval = enable_timerlat (& aa -> trace );
955+ if (retval ) {
956+ err_msg ("Failed to enable timerlat tracer\n" );
957+ goto out_hist ;
958+ }
959+
960+ trace_instance_start (& aa -> trace );
961+ }
962+
922963 tool -> start_time = time (NULL );
923964 timerlat_hist_set_signals (params );
924965
@@ -946,19 +987,25 @@ int timerlat_hist_main(int argc, char *argv[])
946987
947988 if (trace_is_off (& tool -> trace , & record -> trace )) {
948989 printf ("rtla timerlat hit stop tracing\n" );
990+
991+ if (!params -> no_aa )
992+ timerlat_auto_analysis (params -> stop_us , params -> stop_total_us );
993+
949994 if (params -> trace_output ) {
950995 printf (" Saving trace to %s\n" , params -> trace_output );
951996 save_trace_to_file (record -> trace .inst , params -> trace_output );
952997 }
953998 }
954999
9551000out_hist :
1001+ timerlat_aa_destroy ();
9561002 if (dma_latency_fd >= 0 )
9571003 close (dma_latency_fd );
9581004 trace_events_destroy (& record -> trace , params -> events );
9591005 params -> events = NULL ;
9601006out_free :
9611007 timerlat_free_histogram (tool -> data );
1008+ osnoise_destroy_tool (aa );
9621009 osnoise_destroy_tool (record );
9631010 osnoise_destroy_tool (tool );
9641011 free (params );
0 commit comments