@@ -28,6 +28,7 @@ struct timerlat_hist_params {
2828 int output_divisor ;
2929 int duration ;
3030 int set_sched ;
31+ int dma_latency ;
3132 struct sched_attr sched_param ;
3233 struct trace_events * events ;
3334
@@ -432,7 +433,7 @@ static void timerlat_hist_usage(char *usage)
432433 " usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\" ,
433434 " [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] \\" ,
434435 " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\" ,
435- " [--no-index] [--with-zeros]" ,
436+ " [--no-index] [--with-zeros] [--dma-latency us] " ,
436437 "" ,
437438 " -h/--help: print this menu" ,
438439 " -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)
456457 " --no-summary: do not print summary" ,
457458 " --no-index: do not print index" ,
458459 " --with-zeros: print zero only entries" ,
460+ " --dma-latency us: set /dev/cpu_dma_latency latency <us> to reduce exit from idle latency" ,
459461 " -P/--priority o:prio|r:prio|f:prio|d:runtime:period : set scheduling parameters" ,
460462 " o:prio - use SCHED_OTHER with prio" ,
461463 " r:prio - use SCHED_RR with prio" ,
@@ -492,6 +494,9 @@ static struct timerlat_hist_params
492494 if (!params )
493495 exit (1 );
494496
497+ /* disabled by default */
498+ params -> dma_latency = -1 ;
499+
495500 /* display data in microseconds */
496501 params -> output_divisor = 1000 ;
497502 params -> bucket_size = 1 ;
@@ -522,13 +527,14 @@ static struct timerlat_hist_params
522527 {"with-zeros" , no_argument , 0 , '5' },
523528 {"trigger" , required_argument , 0 , '6' },
524529 {"filter" , required_argument , 0 , '7' },
530+ {"dma-latency" , required_argument , 0 , '8' },
525531 {0 , 0 , 0 , 0 }
526532 };
527533
528534 /* getopt_long stores the option index here. */
529535 int option_index = 0 ;
530536
531- c = getopt_long (argc , argv , "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:" ,
537+ c = getopt_long (argc , argv , "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:8: " ,
532538 long_options , & option_index );
533539
534540 /* detect the end of the options. */
@@ -659,6 +665,13 @@ static struct timerlat_hist_params
659665 timerlat_hist_usage ("--filter requires a previous -e\n" );
660666 }
661667 break ;
668+ case '8' :
669+ params -> dma_latency = get_llong_from_str (optarg );
670+ if (params -> dma_latency < 0 || params -> dma_latency > 10000 ) {
671+ err_msg ("--dma-latency needs to be >= 0 and < 10000" );
672+ exit (EXIT_FAILURE );
673+ }
674+ break ;
662675 default :
663676 timerlat_hist_usage ("Invalid option" );
664677 }
@@ -791,6 +804,7 @@ int timerlat_hist_main(int argc, char *argv[])
791804 struct osnoise_tool * record = NULL ;
792805 struct osnoise_tool * tool = NULL ;
793806 struct trace_instance * trace ;
807+ int dma_latency_fd = -1 ;
794808 int return_value = 1 ;
795809 int retval ;
796810
@@ -826,6 +840,14 @@ int timerlat_hist_main(int argc, char *argv[])
826840 }
827841 }
828842
843+ if (params -> dma_latency >= 0 ) {
844+ dma_latency_fd = set_cpu_dma_latency (params -> dma_latency );
845+ if (dma_latency_fd < 0 ) {
846+ err_msg ("Could not set /dev/cpu_dma_latency.\n" );
847+ goto out_hist ;
848+ }
849+ }
850+
829851 trace_instance_start (trace );
830852
831853 if (params -> trace_output ) {
@@ -878,6 +900,8 @@ int timerlat_hist_main(int argc, char *argv[])
878900 }
879901
880902out_hist :
903+ if (dma_latency_fd >= 0 )
904+ close (dma_latency_fd );
881905 trace_events_destroy (& record -> trace , params -> events );
882906 params -> events = NULL ;
883907 timerlat_free_histogram (tool -> data );
0 commit comments