Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rtla: Introduce common_threshold_handler() helper

Several functions duplicate the logic for handling threshold actions.
When a threshold is reached, these functions stop the trace, perform
configured actions, and restart the trace if --on-threshold continue
is set.

Create common_threshold_handler() to centralize this shared logic and
avoid code duplication. The function executes the configured threshold
actions and restarts the necessary trace instances when appropriate.

Also add should_continue_tracing() helper to encapsulate the check
for whether tracing should continue after a threshold event, improving
code readability at call sites.

In timerlat_top_bpf_main_loop(), use common_params directly instead
of casting through timerlat_params when only common fields are needed.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20260309195040.1019085-5-wander@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>

authored by

Wander Lairson Costa and committed by
Tomas Glozar
a50c5388 989e5b8f

+86 -44
+43 -18
tools/tracing/rtla/src/common.c
··· 207 207 } 208 208 209 209 210 + /** 211 + * common_threshold_handler - handle latency threshold overflow 212 + * @tool: pointer to the osnoise_tool instance containing trace contexts 213 + * 214 + * Executes the configured threshold actions (e.g., saving trace, printing, 215 + * sending signals). If the continue flag is set (--on-threshold continue), 216 + * restarts the auxiliary trace instances to continue monitoring. 217 + * 218 + * Return: 0 for success, -1 for error. 219 + */ 220 + int 221 + common_threshold_handler(const struct osnoise_tool *tool) 222 + { 223 + actions_perform(&tool->params->threshold_actions); 224 + 225 + if (!should_continue_tracing(tool->params)) 226 + /* continue flag not set, break */ 227 + return 0; 228 + 229 + /* continue action reached, re-enable tracing */ 230 + if (tool->record && trace_instance_start(&tool->record->trace)) 231 + goto err; 232 + if (tool->aa && trace_instance_start(&tool->aa->trace)) 233 + goto err; 234 + 235 + return 0; 236 + 237 + err: 238 + err_msg("Error restarting trace\n"); 239 + return -1; 240 + } 241 + 210 242 int run_tool(struct tool_ops *ops, int argc, char *argv[]) 211 243 { 212 244 struct common_params *params; ··· 417 385 /* stop tracing requested, do not perform actions */ 418 386 return 0; 419 387 420 - actions_perform(&params->threshold_actions); 388 + retval = common_threshold_handler(tool); 389 + if (retval) 390 + return retval; 421 391 422 - if (!params->threshold_actions.continue_flag) 423 - /* continue flag not set, break */ 392 + 393 + if (!should_continue_tracing(params)) 424 394 return 0; 425 395 426 - /* continue action reached, re-enable tracing */ 427 - if (record) 428 - trace_instance_start(&record->trace); 429 - if (tool->aa) 430 - trace_instance_start(&tool->aa->trace); 431 396 trace_instance_start(trace); 432 397 } 433 398 ··· 465 436 /* stop tracing requested, do not perform actions */ 466 437 break; 467 438 468 - actions_perform(&params->threshold_actions); 439 + retval = common_threshold_handler(tool); 440 + if (retval) 441 + return retval; 469 442 470 - if (!params->threshold_actions.continue_flag) 471 - /* continue flag not set, break */ 472 - break; 443 + if (!should_continue_tracing(params)) 444 + return 0; 473 445 474 - /* continue action reached, re-enable tracing */ 475 - if (tool->record) 476 - trace_instance_start(&tool->record->trace); 477 - if (tool->aa) 478 - trace_instance_start(&tool->aa->trace); 479 - trace_instance_start(&tool->trace); 446 + trace_instance_start(trace); 480 447 } 481 448 482 449 /* is there still any user-threads ? */
+18
tools/tracing/rtla/src/common.h
··· 146 146 void (*free)(struct osnoise_tool *tool); 147 147 }; 148 148 149 + /** 150 + * should_continue_tracing - check if tracing should continue after threshold 151 + * @params: pointer to the common parameters structure 152 + * 153 + * Returns true if the continue action was configured (--on-threshold continue), 154 + * indicating that tracing should be restarted after handling the threshold event. 155 + * 156 + * Return: 1 if tracing should continue, 0 otherwise. 157 + */ 158 + static inline int 159 + should_continue_tracing(const struct common_params *params) 160 + { 161 + return params->threshold_actions.continue_flag; 162 + } 163 + 164 + int 165 + common_threshold_handler(const struct osnoise_tool *tool); 166 + 149 167 int osnoise_set_cpus(struct osnoise_context *context, char *cpus); 150 168 void osnoise_restore_cpus(struct osnoise_context *context); 151 169
+9 -10
tools/tracing/rtla/src/timerlat_hist.c
··· 17 17 #include "timerlat.h" 18 18 #include "timerlat_aa.h" 19 19 #include "timerlat_bpf.h" 20 + #include "common.h" 20 21 21 22 struct timerlat_hist_cpu { 22 23 int *irq; ··· 1048 1047 1049 1048 static int timerlat_hist_bpf_main_loop(struct osnoise_tool *tool) 1050 1049 { 1051 - struct timerlat_params *params = to_timerlat_params(tool->params); 1052 1050 int retval; 1053 1051 1054 1052 while (!stop_tracing) { ··· 1055 1055 1056 1056 if (!stop_tracing) { 1057 1057 /* Threshold overflow, perform actions on threshold */ 1058 - actions_perform(&params->common.threshold_actions); 1058 + retval = common_threshold_handler(tool); 1059 + if (retval) 1060 + return retval; 1059 1061 1060 - if (!params->common.threshold_actions.continue_flag) 1061 - /* continue flag not set, break */ 1062 + if (!should_continue_tracing(tool->params)) 1062 1063 break; 1063 1064 1064 - /* continue action reached, re-enable tracing */ 1065 - if (tool->record) 1066 - trace_instance_start(&tool->record->trace); 1067 - if (tool->aa) 1068 - trace_instance_start(&tool->aa->trace); 1069 - timerlat_bpf_restart_tracing(); 1065 + if (timerlat_bpf_restart_tracing()) { 1066 + err_msg("Error restarting BPF trace\n"); 1067 + return -1; 1068 + } 1070 1069 } 1071 1070 } 1072 1071 timerlat_bpf_detach();
+16 -16
tools/tracing/rtla/src/timerlat_top.c
··· 17 17 #include "timerlat.h" 18 18 #include "timerlat_aa.h" 19 19 #include "timerlat_bpf.h" 20 + #include "common.h" 20 21 21 22 struct timerlat_top_cpu { 22 23 unsigned long long irq_count; ··· 796 795 static int 797 796 timerlat_top_bpf_main_loop(struct osnoise_tool *tool) 798 797 { 799 - struct timerlat_params *params = to_timerlat_params(tool->params); 798 + const struct common_params *params = tool->params; 800 799 int retval, wait_retval; 801 800 802 - if (params->common.aa_only) { 801 + if (params->aa_only) { 803 802 /* Auto-analysis only, just wait for stop tracing */ 804 803 timerlat_bpf_wait(-1); 805 804 return 0; ··· 807 806 808 807 /* Pull and display data in a loop */ 809 808 while (!stop_tracing) { 810 - wait_retval = timerlat_bpf_wait(params->common.quiet ? -1 : 811 - params->common.sleep_time); 809 + wait_retval = timerlat_bpf_wait(params->quiet ? -1 : 810 + params->sleep_time); 812 811 813 812 retval = timerlat_top_bpf_pull_data(tool); 814 813 if (retval) { ··· 816 815 return retval; 817 816 } 818 817 819 - if (!params->common.quiet) 818 + if (!params->quiet) 820 819 timerlat_print_stats(tool); 821 820 822 821 if (wait_retval != 0) { 823 822 /* Stopping requested by tracer */ 824 - actions_perform(&params->common.threshold_actions); 823 + retval = common_threshold_handler(tool); 824 + if (retval) 825 + return retval; 825 826 826 - if (!params->common.threshold_actions.continue_flag) 827 - /* continue flag not set, break */ 827 + if (!should_continue_tracing(tool->params)) 828 828 break; 829 829 830 - /* continue action reached, re-enable tracing */ 831 - if (tool->record) 832 - trace_instance_start(&tool->record->trace); 833 - if (tool->aa) 834 - trace_instance_start(&tool->aa->trace); 835 - timerlat_bpf_restart_tracing(); 830 + if (timerlat_bpf_restart_tracing()) { 831 + err_msg("Error restarting BPF trace\n"); 832 + return -1; 833 + } 836 834 } 837 835 838 836 /* is there still any user-threads ? */ 839 - if (params->common.user_workload) { 840 - if (params->common.user.stopped_running) { 837 + if (params->user_workload) { 838 + if (params->user.stopped_running) { 841 839 debug_msg("timerlat user space threads stopped!\n"); 842 840 break; 843 841 }