16
16
#include "utils.h"
17
17
#include "osnoise.h"
18
18
#include "timerlat.h"
19
+ #include "timerlat_aa.h"
19
20
20
21
struct timerlat_hist_params {
21
22
char * cpus ;
@@ -34,6 +35,8 @@ struct timerlat_hist_params {
34
35
int dma_latency ;
35
36
int cgroup ;
36
37
int hk_cpus ;
38
+ int no_aa ;
39
+ int dump_tasks ;
37
40
cpu_set_t hk_cpu_set ;
38
41
struct sched_attr sched_param ;
39
42
struct trace_events * events ;
@@ -438,7 +441,7 @@ static void timerlat_hist_usage(char *usage)
438
441
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\" ,
439
442
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\" ,
440
443
" [-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] " ,
442
445
"" ,
443
446
" -h/--help: print this menu" ,
444
447
" -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)
450
453
" -H/--house-keeping cpus: run rtla control threads only on the given cpus" ,
451
454
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited" ,
452
455
" -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)" ,
453
457
" -D/--debug: print debug info" ,
454
458
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]" ,
455
459
" -e/--event <sys:event>: enable the <sys:event> in the trace instance, multiple -e are allowed" ,
456
460
" --filter <filter>: enable a trace event filter to the previous -e event" ,
457
461
" --trigger <trigger>: enable a trace event trigger to the previous -e event" ,
458
462
" -n/--nano: display data in nanoseconds" ,
463
+ " --no-aa: disable auto-analysis, reducing rtla timerlat cpu usage" ,
459
464
" -b/--bucket-size N: set the histogram bucket size (default 1)" ,
460
465
" -E/--entries N: set the number of entries of the histogram (default 256)" ,
461
466
" --no-irq: ignore IRQ latencies" ,
@@ -537,13 +542,15 @@ static struct timerlat_hist_params
537
542
{"trigger" , required_argument , 0 , '6' },
538
543
{"filter" , required_argument , 0 , '7' },
539
544
{"dma-latency" , required_argument , 0 , '8' },
545
+ {"no-aa" , no_argument , 0 , '9' },
546
+ {"dump-task" , no_argument , 0 , '\1' },
540
547
{0 , 0 , 0 , 0 }
541
548
};
542
549
543
550
/* getopt_long stores the option index here. */
544
551
int option_index = 0 ;
545
552
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 " ,
547
554
long_options , & option_index );
548
555
549
556
/* detect the end of the options. */
@@ -556,6 +563,7 @@ static struct timerlat_hist_params
556
563
557
564
/* set thread stop to auto_thresh */
558
565
params -> stop_total_us = auto_thresh ;
566
+ params -> stop_us = auto_thresh ;
559
567
560
568
/* get stack trace */
561
569
params -> print_stack = auto_thresh ;
@@ -699,6 +707,12 @@ static struct timerlat_hist_params
699
707
exit (EXIT_FAILURE );
700
708
}
701
709
break ;
710
+ case '9' :
711
+ params -> no_aa = 1 ;
712
+ break ;
713
+ case '\1' :
714
+ params -> dump_tasks = 1 ;
715
+ break ;
702
716
default :
703
717
timerlat_hist_usage ("Invalid option" );
704
718
}
@@ -715,6 +729,12 @@ static struct timerlat_hist_params
715
729
if (params -> no_index && !params -> with_zeros )
716
730
timerlat_hist_usage ("no-index set with with-zeros is not set - it does not make sense" );
717
731
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
+
718
738
return params ;
719
739
}
720
740
@@ -848,6 +868,7 @@ int timerlat_hist_main(int argc, char *argv[])
848
868
struct timerlat_hist_params * params ;
849
869
struct osnoise_tool * record = NULL ;
850
870
struct osnoise_tool * tool = NULL ;
871
+ struct osnoise_tool * aa = NULL ;
851
872
struct trace_instance * trace ;
852
873
int dma_latency_fd = -1 ;
853
874
int return_value = 1 ;
@@ -919,6 +940,26 @@ int timerlat_hist_main(int argc, char *argv[])
919
940
trace_instance_start (& record -> trace );
920
941
}
921
942
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
+
922
963
tool -> start_time = time (NULL );
923
964
timerlat_hist_set_signals (params );
924
965
@@ -946,19 +987,25 @@ int timerlat_hist_main(int argc, char *argv[])
946
987
947
988
if (trace_is_off (& tool -> trace , & record -> trace )) {
948
989
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
+
949
994
if (params -> trace_output ) {
950
995
printf (" Saving trace to %s\n" , params -> trace_output );
951
996
save_trace_to_file (record -> trace .inst , params -> trace_output );
952
997
}
953
998
}
954
999
955
1000
out_hist :
1001
+ timerlat_aa_destroy ();
956
1002
if (dma_latency_fd >= 0 )
957
1003
close (dma_latency_fd );
958
1004
trace_events_destroy (& record -> trace , params -> events );
959
1005
params -> events = NULL ;
960
1006
out_free :
961
1007
timerlat_free_histogram (tool -> data );
1008
+ osnoise_destroy_tool (aa );
962
1009
osnoise_destroy_tool (record );
963
1010
osnoise_destroy_tool (tool );
964
1011
free (params );
0 commit comments