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

tools/rtla: Fix --on-threshold always triggering

Commit 8d933d5c89e8 ("rtla/timerlat: Add continue action") moved the
code performing on-threshold actions (enabled through --on-threshold
option) to inside the RTLA main loop.

The condition in the loop does not check whether the threshold was
actually exceeded or if stop tracing was requested by the user through
SIGINT or duration. This leads to a bug where on-threshold actions are
always performed, even when the threshold was not hit.

(BPF mode is not affected, since it uses a different condition in the
while loop.)

Add a condition that checks for !stop_tracing before executing the
actions. Also, fix incorrect brackets in hist_main_loop to match the
semantics of top_main_loop.

Fixes: 8d933d5c89e8 ("rtla/timerlat: Add continue action")
Fixes: 2f3172f9dd58 ("tools/rtla: Consolidate code between osnoise/timerlat and hist/top")
Reviewed-by: Crystal Wood <crwood@redhat.com>
Reviewed-by: Wander Lairson Costa <wander@redhat.com>
Link: https://lore.kernel.org/r/20251007095341.186923-1-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>

+15 -9
+15 -9
tools/tracing/rtla/src/common.c
··· 268 268 tool->ops->print_stats(tool); 269 269 270 270 if (osnoise_trace_is_off(tool, record)) { 271 + if (stop_tracing) 272 + /* stop tracing requested, do not perform actions */ 273 + return 0; 274 + 271 275 actions_perform(&params->threshold_actions); 272 276 273 277 if (!params->threshold_actions.continue_flag) ··· 319 315 } 320 316 321 317 if (osnoise_trace_is_off(tool, tool->record)) { 318 + if (stop_tracing) 319 + /* stop tracing requested, do not perform actions */ 320 + break; 321 + 322 322 actions_perform(&params->threshold_actions); 323 323 324 - if (!params->threshold_actions.continue_flag) { 324 + if (!params->threshold_actions.continue_flag) 325 325 /* continue flag not set, break */ 326 326 break; 327 327 328 - /* continue action reached, re-enable tracing */ 329 - if (tool->record) 330 - trace_instance_start(&tool->record->trace); 331 - if (tool->aa) 332 - trace_instance_start(&tool->aa->trace); 333 - trace_instance_start(&tool->trace); 334 - } 335 - break; 328 + /* continue action reached, re-enable tracing */ 329 + if (tool->record) 330 + trace_instance_start(&tool->record->trace); 331 + if (tool->aa) 332 + trace_instance_start(&tool->aa->trace); 333 + trace_instance_start(&tool->trace); 336 334 } 337 335 338 336 /* is there still any user-threads ? */