Skip to content

Commit 3aadb65

Browse files
lenticularis39rostedt
authored andcommitted
rtla/timerlat: Add action on end feature
Implement actions on end next to actions on threshold. A new option, --on-end is added, parallel to --on-threshold. Instead of being executed whenever a latency threshold is reached, it is executed at the end of the measurement. For example: $ rtla timerlat hist -d 5s --on-end trace will save the trace output at the end. All actions supported by --on-threshold are also supported by --on-end, except for continue, which does nothing with --on-end. Cc: John Kacur <[email protected]> Cc: Luis Goncalves <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Chang Yin <[email protected]> Cc: Costa Shulyupin <[email protected]> Cc: Crystal Wood <[email protected]> Cc: Gabriele Monaco <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Tomas Glozar <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 8d933d5 commit 3aadb65

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

tools/tracing/rtla/src/timerlat.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ struct timerlat_params {
4848
struct sched_attr sched_param;
4949
struct trace_events *events;
5050
enum timerlat_tracing_mode mode;
51-
struct actions actions;
51+
52+
struct actions threshold_actions;
53+
struct actions end_actions;
54+
5255
union {
5356
struct {
5457
/* top only */

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ static void timerlat_hist_usage(char *usage)
758758
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
759759
" --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
760760
" --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
761+
" --on-end <action>: define action to be executed at measurement end, multiple are allowed",
761762
NULL,
762763
};
763764

@@ -793,7 +794,8 @@ static struct timerlat_params
793794
if (!params)
794795
exit(1);
795796

796-
actions_init(&params->actions);
797+
actions_init(&params->threshold_actions);
798+
actions_init(&params->end_actions);
797799

798800
/* disabled by default */
799801
params->dma_latency = -1;
@@ -846,6 +848,7 @@ static struct timerlat_params
846848
{"trace-buffer-size", required_argument, 0, '\3'},
847849
{"deepest-idle-state", required_argument, 0, '\4'},
848850
{"on-threshold", required_argument, 0, '\5'},
851+
{"on-end", required_argument, 0, '\6'},
849852
{0, 0, 0, 0}
850853
};
851854

@@ -1038,7 +1041,14 @@ static struct timerlat_params
10381041
params->deepest_idle_state = get_llong_from_str(optarg);
10391042
break;
10401043
case '\5':
1041-
retval = actions_parse(&params->actions, optarg);
1044+
retval = actions_parse(&params->threshold_actions, optarg);
1045+
if (retval) {
1046+
err_msg("Invalid action %s\n", optarg);
1047+
exit(EXIT_FAILURE);
1048+
}
1049+
break;
1050+
case '\6':
1051+
retval = actions_parse(&params->end_actions, optarg);
10421052
if (retval) {
10431053
err_msg("Invalid action %s\n", optarg);
10441054
exit(EXIT_FAILURE);
@@ -1050,7 +1060,7 @@ static struct timerlat_params
10501060
}
10511061

10521062
if (trace_output)
1053-
actions_add_trace_output(&params->actions, trace_output);
1063+
actions_add_trace_output(&params->threshold_actions, trace_output);
10541064

10551065
if (geteuid()) {
10561066
err_msg("rtla needs root permission\n");
@@ -1077,7 +1087,8 @@ static struct timerlat_params
10771087
* mixed mode
10781088
*/
10791089
if (params->mode == TRACING_MODE_BPF &&
1080-
(params->actions.present[ACTION_TRACE_OUTPUT] || !params->no_aa))
1090+
(params->threshold_actions.present[ACTION_TRACE_OUTPUT] ||
1091+
params->end_actions.present[ACTION_TRACE_OUTPUT] || !params->no_aa))
10811092
params->mode = TRACING_MODE_MIXED;
10821093

10831094
return params;
@@ -1270,13 +1281,15 @@ int timerlat_hist_main(int argc, char *argv[])
12701281
}
12711282
}
12721283

1273-
if (params->actions.present[ACTION_TRACE_OUTPUT]) {
1284+
if (params->threshold_actions.present[ACTION_TRACE_OUTPUT] ||
1285+
params->end_actions.present[ACTION_TRACE_OUTPUT]) {
12741286
record = osnoise_init_trace_tool("timerlat");
12751287
if (!record) {
12761288
err_msg("Failed to enable the trace instance\n");
12771289
goto out_free;
12781290
}
1279-
params->actions.trace_output_inst = record->trace.inst;
1291+
params->threshold_actions.trace_output_inst = record->trace.inst;
1292+
params->end_actions.trace_output_inst = record->trace.inst;
12801293

12811294
if (params->events) {
12821295
retval = trace_events_enable(&record->trace, params->events);
@@ -1342,7 +1355,7 @@ int timerlat_hist_main(int argc, char *argv[])
13421355
* tracing while enabling other instances. The trace instance is the
13431356
* one with most valuable information.
13441357
*/
1345-
if (params->actions.present[ACTION_TRACE_OUTPUT])
1358+
if (record)
13461359
trace_instance_start(&record->trace);
13471360
if (!params->no_aa)
13481361
trace_instance_start(&aa->trace);
@@ -1375,14 +1388,14 @@ int timerlat_hist_main(int argc, char *argv[])
13751388
}
13761389

13771390
if (osnoise_trace_is_off(tool, record)) {
1378-
actions_perform(&params->actions);
1391+
actions_perform(&params->threshold_actions);
13791392

1380-
if (!params->actions.continue_flag)
1393+
if (!params->threshold_actions.continue_flag)
13811394
/* continue flag not set, break */
13821395
break;
13831396

13841397
/* continue action reached, re-enable tracing */
1385-
if (params->actions.present[ACTION_TRACE_OUTPUT])
1398+
if (record)
13861399
trace_instance_start(&record->trace);
13871400
if (!params->no_aa)
13881401
trace_instance_start(&aa->trace);
@@ -1403,14 +1416,14 @@ int timerlat_hist_main(int argc, char *argv[])
14031416

14041417
if (!stop_tracing) {
14051418
/* Threshold overflow, perform actions on threshold */
1406-
actions_perform(&params->actions);
1419+
actions_perform(&params->threshold_actions);
14071420

1408-
if (!params->actions.continue_flag)
1421+
if (!params->threshold_actions.continue_flag)
14091422
/* continue flag not set, break */
14101423
break;
14111424

14121425
/* continue action reached, re-enable tracing */
1413-
if (params->actions.present[ACTION_TRACE_OUTPUT])
1426+
if (record)
14141427
trace_instance_start(&record->trace);
14151428
if (!params->no_aa)
14161429
trace_instance_start(&aa->trace);
@@ -1435,6 +1448,8 @@ int timerlat_hist_main(int argc, char *argv[])
14351448

14361449
timerlat_print_stats(params, tool);
14371450

1451+
actions_perform(&params->end_actions);
1452+
14381453
return_value = PASSED;
14391454

14401455
if (osnoise_trace_is_off(tool, record) && !stop_tracing) {
@@ -1464,7 +1479,8 @@ int timerlat_hist_main(int argc, char *argv[])
14641479
osnoise_destroy_tool(aa);
14651480
osnoise_destroy_tool(record);
14661481
osnoise_destroy_tool(tool);
1467-
actions_destroy(&params->actions);
1482+
actions_destroy(&params->threshold_actions);
1483+
actions_destroy(&params->end_actions);
14681484
if (params->mode != TRACING_MODE_TRACEFS)
14691485
timerlat_bpf_destroy();
14701486
free(params);

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static void timerlat_top_usage(char *usage)
517517
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
518518
" --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency",
519519
" --on-threshold <action>: define action to be executed at latency threshold, multiple are allowed",
520+
" --on-end: define action to be executed at measurement end, multiple are allowed",
520521
NULL,
521522
};
522523

@@ -552,7 +553,8 @@ static struct timerlat_params
552553
if (!params)
553554
exit(1);
554555

555-
actions_init(&params->actions);
556+
actions_init(&params->threshold_actions);
557+
actions_init(&params->end_actions);
556558

557559
/* disabled by default */
558560
params->dma_latency = -1;
@@ -597,6 +599,7 @@ static struct timerlat_params
597599
{"trace-buffer-size", required_argument, 0, '7'},
598600
{"deepest-idle-state", required_argument, 0, '8'},
599601
{"on-threshold", required_argument, 0, '9'},
602+
{"on-end", required_argument, 0, '\1'},
600603
{0, 0, 0, 0}
601604
};
602605

@@ -623,6 +626,7 @@ static struct timerlat_params
623626

624627
/* set trace */
625628
trace_output = "timerlat_trace.txt";
629+
626630
break;
627631
case '5':
628632
/* it is here because it is similar to -a */
@@ -776,7 +780,14 @@ static struct timerlat_params
776780
params->deepest_idle_state = get_llong_from_str(optarg);
777781
break;
778782
case '9':
779-
retval = actions_parse(&params->actions, optarg);
783+
retval = actions_parse(&params->threshold_actions, optarg);
784+
if (retval) {
785+
err_msg("Invalid action %s\n", optarg);
786+
exit(EXIT_FAILURE);
787+
}
788+
break;
789+
case '\1':
790+
retval = actions_parse(&params->end_actions, optarg);
780791
if (retval) {
781792
err_msg("Invalid action %s\n", optarg);
782793
exit(EXIT_FAILURE);
@@ -788,7 +799,7 @@ static struct timerlat_params
788799
}
789800

790801
if (trace_output)
791-
actions_add_trace_output(&params->actions, trace_output);
802+
actions_add_trace_output(&params->threshold_actions, trace_output);
792803

793804
if (geteuid()) {
794805
err_msg("rtla needs root permission\n");
@@ -812,7 +823,8 @@ static struct timerlat_params
812823
* mixed mode
813824
*/
814825
if (params->mode == TRACING_MODE_BPF &&
815-
(params->actions.present[ACTION_TRACE_OUTPUT] || !params->no_aa))
826+
(params->threshold_actions.present[ACTION_TRACE_OUTPUT] ||
827+
params->end_actions.present[ACTION_TRACE_OUTPUT] || !params->no_aa))
816828
params->mode = TRACING_MODE_MIXED;
817829

818830
return params;
@@ -934,14 +946,14 @@ timerlat_top_main_loop(struct osnoise_tool *top,
934946
timerlat_print_stats(params, top);
935947

936948
if (osnoise_trace_is_off(top, record)) {
937-
actions_perform(&params->actions);
949+
actions_perform(&params->threshold_actions);
938950

939-
if (!params->actions.continue_flag)
951+
if (!params->threshold_actions.continue_flag)
940952
/* continue flag not set, break */
941953
break;
942954

943955
/* continue action reached, re-enable tracing */
944-
if (params->actions.present[ACTION_TRACE_OUTPUT])
956+
if (record)
945957
trace_instance_start(&record->trace);
946958
if (!params->no_aa)
947959
trace_instance_start(&aa->trace);
@@ -993,14 +1005,14 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *top,
9931005

9941006
if (wait_retval == 1) {
9951007
/* Stopping requested by tracer */
996-
actions_perform(&params->actions);
1008+
actions_perform(&params->threshold_actions);
9971009

998-
if (!params->actions.continue_flag)
1010+
if (!params->threshold_actions.continue_flag)
9991011
/* continue flag not set, break */
10001012
break;
10011013

10021014
/* continue action reached, re-enable tracing */
1003-
if (params->actions.present[ACTION_TRACE_OUTPUT])
1015+
if (record)
10041016
trace_instance_start(&record->trace);
10051017
if (!params->no_aa)
10061018
trace_instance_start(&aa->trace);
@@ -1128,13 +1140,15 @@ int timerlat_top_main(int argc, char *argv[])
11281140
}
11291141
}
11301142

1131-
if (params->actions.present[ACTION_TRACE_OUTPUT]) {
1143+
if (params->threshold_actions.present[ACTION_TRACE_OUTPUT] ||
1144+
params->end_actions.present[ACTION_TRACE_OUTPUT]) {
11321145
record = osnoise_init_trace_tool("timerlat");
11331146
if (!record) {
11341147
err_msg("Failed to enable the trace instance\n");
11351148
goto out_free;
11361149
}
1137-
params->actions.trace_output_inst = record->trace.inst;
1150+
params->threshold_actions.trace_output_inst = record->trace.inst;
1151+
params->end_actions.trace_output_inst = record->trace.inst;
11381152

11391153
if (params->events) {
11401154
retval = trace_events_enable(&record->trace, params->events);
@@ -1201,7 +1215,7 @@ int timerlat_top_main(int argc, char *argv[])
12011215
* tracing while enabling other instances. The trace instance is the
12021216
* one with most valuable information.
12031217
*/
1204-
if (params->actions.present[ACTION_TRACE_OUTPUT])
1218+
if (record)
12051219
trace_instance_start(&record->trace);
12061220
if (!params->no_aa)
12071221
trace_instance_start(&aa->trace);
@@ -1236,6 +1250,8 @@ int timerlat_top_main(int argc, char *argv[])
12361250

12371251
timerlat_print_stats(params, top);
12381252

1253+
actions_perform(&params->end_actions);
1254+
12391255
return_value = PASSED;
12401256

12411257
if (osnoise_trace_is_off(top, record) && !stop_tracing) {
@@ -1276,7 +1292,8 @@ int timerlat_top_main(int argc, char *argv[])
12761292
osnoise_destroy_tool(aa);
12771293
osnoise_destroy_tool(record);
12781294
osnoise_destroy_tool(top);
1279-
actions_destroy(&params->actions);
1295+
actions_destroy(&params->threshold_actions);
1296+
actions_destroy(&params->end_actions);
12801297
if (params->mode != TRACING_MODE_TRACEFS)
12811298
timerlat_bpf_destroy();
12821299
free(params);

0 commit comments

Comments
 (0)