Skip to content

Commit 8d933d5

Browse files
lenticularis39rostedt
authored andcommitted
rtla/timerlat: Add continue action
Introduce option to resume tracing after a latency threshold overflow. The option is implemented as an action named "continue". Example: $ rtla timerlat top -q -T 200 -d 1s --on-threshold \ exec,command="echo Threshold" --on-threshold continue Threshold Threshold Threshold Timer Latency ... The feature is supported for both hist and top. After the continue action is executed, processing of the list of actions is stopped and tracing is resumed. 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 3b78670 commit 8d933d5

File tree

4 files changed

+100
-29
lines changed

4 files changed

+100
-29
lines changed

tools/tracing/rtla/src/actions.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ actions_init(struct actions *self)
1717
self->size = action_default_size;
1818
self->list = calloc(self->size, sizeof(struct action));
1919
self->len = 0;
20+
self->continue_flag = false;
2021

2122
memset(&self->present, 0, sizeof(self->present));
2223

@@ -108,6 +109,20 @@ actions_add_shell(struct actions *self, const char *command)
108109
return 0;
109110
}
110111

112+
/*
113+
* actions_add_continue - add an action to resume measurement
114+
*/
115+
int
116+
actions_add_continue(struct actions *self)
117+
{
118+
struct action *action = actions_new(self);
119+
120+
self->present[ACTION_CONTINUE] = true;
121+
action->type = ACTION_CONTINUE;
122+
123+
return 0;
124+
}
125+
111126
/*
112127
* actions_parse - add an action based on text specification
113128
*/
@@ -133,6 +148,8 @@ actions_parse(struct actions *self, const char *trigger)
133148
type = ACTION_SIGNAL;
134149
else if (strcmp(token, "shell") == 0)
135150
type = ACTION_SHELL;
151+
else if (strcmp(token, "continue") == 0)
152+
type = ACTION_CONTINUE;
136153
else
137154
/* Invalid trigger type */
138155
return -1;
@@ -187,6 +204,11 @@ actions_parse(struct actions *self, const char *trigger)
187204
if (strlen(token) > 8 && strncmp(token, "command=", 8) == 0)
188205
return actions_add_shell(self, token + 8);
189206
return -1;
207+
case ACTION_CONTINUE:
208+
/* Takes no argument */
209+
if (token != NULL)
210+
return -1;
211+
return actions_add_continue(self);
190212
default:
191213
return -1;
192214
}
@@ -196,7 +218,7 @@ actions_parse(struct actions *self, const char *trigger)
196218
* actions_perform - perform all actions
197219
*/
198220
int
199-
actions_perform(const struct actions *self)
221+
actions_perform(struct actions *self)
200222
{
201223
int pid, retval;
202224
const struct action *action;
@@ -226,6 +248,9 @@ actions_perform(const struct actions *self)
226248
if (retval)
227249
return retval;
228250
break;
251+
case ACTION_CONTINUE:
252+
self->continue_flag = true;
253+
return 0;
229254
default:
230255
break;
231256
}

tools/tracing/rtla/src/actions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ enum action_type {
77
ACTION_TRACE_OUTPUT,
88
ACTION_SIGNAL,
99
ACTION_SHELL,
10+
ACTION_CONTINUE,
1011
ACTION_FIELD_N
1112
};
1213

@@ -35,6 +36,7 @@ struct actions {
3536
struct action *list;
3637
int len, size;
3738
bool present[ACTION_FIELD_N];
39+
bool continue_flag;
3840

3941
/* External dependencies */
4042
struct tracefs_instance *trace_output_inst;
@@ -45,5 +47,6 @@ void actions_destroy(struct actions *self);
4547
int actions_add_trace_output(struct actions *self, const char *trace_output);
4648
int actions_add_signal(struct actions *self, int signal, int pid);
4749
int actions_add_shell(struct actions *self, const char *command);
50+
int actions_add_continue(struct actions *self);
4851
int actions_parse(struct actions *self, const char *trigger);
49-
int actions_perform(const struct actions *self);
52+
int actions_perform(struct actions *self);

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,20 @@ int timerlat_hist_main(int argc, char *argv[])
13741374
goto out_hist;
13751375
}
13761376

1377-
if (osnoise_trace_is_off(tool, record))
1378-
break;
1377+
if (osnoise_trace_is_off(tool, record)) {
1378+
actions_perform(&params->actions);
1379+
1380+
if (!params->actions.continue_flag)
1381+
/* continue flag not set, break */
1382+
break;
1383+
1384+
/* continue action reached, re-enable tracing */
1385+
if (params->actions.present[ACTION_TRACE_OUTPUT])
1386+
trace_instance_start(&record->trace);
1387+
if (!params->no_aa)
1388+
trace_instance_start(&aa->trace);
1389+
trace_instance_start(trace);
1390+
}
13791391

13801392
/* is there still any user-threads ? */
13811393
if (params->user_workload) {
@@ -1385,8 +1397,27 @@ int timerlat_hist_main(int argc, char *argv[])
13851397
}
13861398
}
13871399
}
1388-
} else
1389-
timerlat_bpf_wait(-1);
1400+
} else {
1401+
while (!stop_tracing) {
1402+
timerlat_bpf_wait(-1);
1403+
1404+
if (!stop_tracing) {
1405+
/* Threshold overflow, perform actions on threshold */
1406+
actions_perform(&params->actions);
1407+
1408+
if (!params->actions.continue_flag)
1409+
/* continue flag not set, break */
1410+
break;
1411+
1412+
/* continue action reached, re-enable tracing */
1413+
if (params->actions.present[ACTION_TRACE_OUTPUT])
1414+
trace_instance_start(&record->trace);
1415+
if (!params->no_aa)
1416+
trace_instance_start(&aa->trace);
1417+
timerlat_bpf_restart_tracing();
1418+
}
1419+
}
1420+
}
13901421

13911422
if (params->mode != TRACING_MODE_TRACEFS) {
13921423
timerlat_bpf_detach();
@@ -1412,7 +1443,6 @@ int timerlat_hist_main(int argc, char *argv[])
14121443
if (!params->no_aa)
14131444
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
14141445

1415-
actions_perform(&params->actions);
14161446
return_value = FAILED;
14171447
}
14181448

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ timerlat_top_set_signals(struct timerlat_params *params)
906906
static int
907907
timerlat_top_main_loop(struct osnoise_tool *top,
908908
struct osnoise_tool *record,
909+
struct osnoise_tool *aa,
909910
struct timerlat_params *params,
910911
struct timerlat_u_params *params_u)
911912
{
@@ -932,8 +933,20 @@ timerlat_top_main_loop(struct osnoise_tool *top,
932933
if (!params->quiet)
933934
timerlat_print_stats(params, top);
934935

935-
if (osnoise_trace_is_off(top, record))
936-
break;
936+
if (osnoise_trace_is_off(top, record)) {
937+
actions_perform(&params->actions);
938+
939+
if (!params->actions.continue_flag)
940+
/* continue flag not set, break */
941+
break;
942+
943+
/* continue action reached, re-enable tracing */
944+
if (params->actions.present[ACTION_TRACE_OUTPUT])
945+
trace_instance_start(&record->trace);
946+
if (!params->no_aa)
947+
trace_instance_start(&aa->trace);
948+
trace_instance_start(trace);
949+
}
937950

938951
/* is there still any user-threads ? */
939952
if (params->user_workload) {
@@ -953,6 +966,7 @@ timerlat_top_main_loop(struct osnoise_tool *top,
953966
static int
954967
timerlat_top_bpf_main_loop(struct osnoise_tool *top,
955968
struct osnoise_tool *record,
969+
struct osnoise_tool *aa,
956970
struct timerlat_params *params,
957971
struct timerlat_u_params *params_u)
958972
{
@@ -964,34 +978,34 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *top,
964978
return 0;
965979
}
966980

967-
if (params->quiet) {
968-
/* Quiet mode: wait for stop and then, print results */
969-
timerlat_bpf_wait(-1);
970-
971-
retval = timerlat_top_bpf_pull_data(top);
972-
if (retval) {
973-
err_msg("Error pulling BPF data\n");
974-
return retval;
975-
}
976-
977-
return 0;
978-
}
979-
980981
/* Pull and display data in a loop */
981982
while (!stop_tracing) {
982-
wait_retval = timerlat_bpf_wait(params->sleep_time);
983+
wait_retval = timerlat_bpf_wait(params->quiet ? -1 : params->sleep_time);
983984

984985
retval = timerlat_top_bpf_pull_data(top);
985986
if (retval) {
986987
err_msg("Error pulling BPF data\n");
987988
return retval;
988989
}
989990

990-
timerlat_print_stats(params, top);
991+
if (!params->quiet)
992+
timerlat_print_stats(params, top);
991993

992-
if (wait_retval == 1)
994+
if (wait_retval == 1) {
993995
/* Stopping requested by tracer */
994-
break;
996+
actions_perform(&params->actions);
997+
998+
if (!params->actions.continue_flag)
999+
/* continue flag not set, break */
1000+
break;
1001+
1002+
/* continue action reached, re-enable tracing */
1003+
if (params->actions.present[ACTION_TRACE_OUTPUT])
1004+
trace_instance_start(&record->trace);
1005+
if (!params->no_aa)
1006+
trace_instance_start(&aa->trace);
1007+
timerlat_bpf_restart_tracing();
1008+
}
9951009

9961010
/* is there still any user-threads ? */
9971011
if (params->user_workload) {
@@ -1205,9 +1219,9 @@ int timerlat_top_main(int argc, char *argv[])
12051219
timerlat_top_set_signals(params);
12061220

12071221
if (params->mode == TRACING_MODE_TRACEFS)
1208-
retval = timerlat_top_main_loop(top, record, params, &params_u);
1222+
retval = timerlat_top_main_loop(top, record, aa, params, &params_u);
12091223
else
1210-
retval = timerlat_top_bpf_main_loop(top, record, params, &params_u);
1224+
retval = timerlat_top_bpf_main_loop(top, record, aa, params, &params_u);
12111225

12121226
if (retval)
12131227
goto out_top;
@@ -1230,7 +1244,6 @@ int timerlat_top_main(int argc, char *argv[])
12301244
if (!params->no_aa)
12311245
timerlat_auto_analysis(params->stop_us, params->stop_total_us);
12321246

1233-
actions_perform(&params->actions);
12341247
return_value = FAILED;
12351248
} else if (params->aa_only) {
12361249
/*

0 commit comments

Comments
 (0)