From: Wander Lairson Costa <wander@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Tomas Glozar <tglozar@redhat.com>,
Wander Lairson Costa <wander@redhat.com>,
Ivan Pravdin <ipravdin.official@gmail.com>,
Crystal Wood <crwood@redhat.com>,
Costa Shulyupin <costa.shul@redhat.com>,
John Kacur <jkacur@redhat.com>,
Tiezhu Yang <yangtiezhu@loongson.cn>,
Daniel Wagner <dwagner@suse.de>,
Daniel Bristot de Oliveira <bristot@kernel.org>,
linux-trace-kernel@vger.kernel.org (open list:Real-time Linux
Analysis (RTLA) tools),
linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis
(RTLA) tools),
bpf@vger.kernel.org (open list:BPF
[MISC]:Keyword:(?:\b|_)bpf(?:\b|_))
Subject: [PATCH v3 04/18] rtla: Introduce common_threshold_handler() helper
Date: Thu, 15 Jan 2026 13:31:47 -0300 [thread overview]
Message-ID: <20260115163650.118910-5-wander@redhat.com> (raw)
In-Reply-To: <20260115163650.118910-1-wander@redhat.com>
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>
---
tools/tracing/rtla/src/common.c | 61 ++++++++++++++++++--------
tools/tracing/rtla/src/common.h | 18 ++++++++
tools/tracing/rtla/src/timerlat_hist.c | 19 ++++----
tools/tracing/rtla/src/timerlat_top.c | 32 +++++++-------
4 files changed, 86 insertions(+), 44 deletions(-)
diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/common.c
index ceff76a62a30b..cbc207fa58707 100644
--- a/tools/tracing/rtla/src/common.c
+++ b/tools/tracing/rtla/src/common.c
@@ -175,6 +175,38 @@ common_apply_config(struct osnoise_tool *tool, struct common_params *params)
}
+/**
+ * common_threshold_handler - handle latency threshold overflow
+ * @tool: pointer to the osnoise_tool instance containing trace contexts
+ *
+ * Executes the configured threshold actions (e.g., saving trace, printing,
+ * sending signals). If the continue flag is set (--on-threshold continue),
+ * restarts the auxiliary trace instances to continue monitoring.
+ *
+ * Return: 0 for success, -1 for error.
+ */
+int
+common_threshold_handler(const struct osnoise_tool *tool)
+{
+ actions_perform(&tool->params->threshold_actions);
+
+ if (!should_continue_tracing(tool->params))
+ /* continue flag not set, break */
+ return 0;
+
+ /* continue action reached, re-enable tracing */
+ if (tool->record && trace_instance_start(&tool->record->trace))
+ goto err;
+ if (tool->aa && trace_instance_start(&tool->aa->trace))
+ goto err;
+
+ return 0;
+
+err:
+ err_msg("Error restarting trace\n");
+ return -1;
+}
+
int run_tool(struct tool_ops *ops, int argc, char *argv[])
{
struct common_params *params;
@@ -352,17 +384,14 @@ int top_main_loop(struct osnoise_tool *tool)
/* stop tracing requested, do not perform actions */
return 0;
- actions_perform(¶ms->threshold_actions);
+ retval = common_threshold_handler(tool);
+ if (retval)
+ return retval;
+
- if (!params->threshold_actions.continue_flag)
- /* continue flag not set, break */
+ if (!should_continue_tracing(params))
return 0;
- /* continue action reached, re-enable tracing */
- if (record)
- trace_instance_start(&record->trace);
- if (tool->aa)
- trace_instance_start(&tool->aa->trace);
trace_instance_start(trace);
}
@@ -403,18 +432,14 @@ int hist_main_loop(struct osnoise_tool *tool)
/* stop tracing requested, do not perform actions */
break;
- actions_perform(¶ms->threshold_actions);
+ retval = common_threshold_handler(tool);
+ if (retval)
+ return retval;
- if (!params->threshold_actions.continue_flag)
- /* continue flag not set, break */
- break;
+ if (!should_continue_tracing(params))
+ return 0;
- /* continue action reached, re-enable tracing */
- if (tool->record)
- trace_instance_start(&tool->record->trace);
- if (tool->aa)
- trace_instance_start(&tool->aa->trace);
- trace_instance_start(&tool->trace);
+ trace_instance_start(trace);
}
/* is there still any user-threads ? */
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index 7602c5593ef5d..c548decd3c40f 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -143,6 +143,24 @@ struct tool_ops {
void (*free)(struct osnoise_tool *tool);
};
+/**
+ * should_continue_tracing - check if tracing should continue after threshold
+ * @params: pointer to the common parameters structure
+ *
+ * Returns true if the continue action was configured (--on-threshold continue),
+ * indicating that tracing should be restarted after handling the threshold event.
+ *
+ * Return: 1 if tracing should continue, 0 otherwise.
+ */
+static inline int
+should_continue_tracing(const struct common_params *params)
+{
+ return params->threshold_actions.continue_flag;
+}
+
+int
+common_threshold_handler(const struct osnoise_tool *tool);
+
int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
void osnoise_restore_cpus(struct osnoise_context *context);
diff --git a/tools/tracing/rtla/src/timerlat_hist.c b/tools/tracing/rtla/src/timerlat_hist.c
index 6ea397421f1c9..6b8eaef8a3a09 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -17,6 +17,7 @@
#include "timerlat.h"
#include "timerlat_aa.h"
#include "timerlat_bpf.h"
+#include "common.h"
struct timerlat_hist_cpu {
int *irq;
@@ -1048,7 +1049,6 @@ static struct osnoise_tool
static int timerlat_hist_bpf_main_loop(struct osnoise_tool *tool)
{
- struct timerlat_params *params = to_timerlat_params(tool->params);
int retval;
while (!stop_tracing) {
@@ -1056,18 +1056,17 @@ static int timerlat_hist_bpf_main_loop(struct osnoise_tool *tool)
if (!stop_tracing) {
/* Threshold overflow, perform actions on threshold */
- actions_perform(¶ms->common.threshold_actions);
+ retval = common_threshold_handler(tool);
+ if (retval)
+ return retval;
- if (!params->common.threshold_actions.continue_flag)
- /* continue flag not set, break */
+ if (!should_continue_tracing(tool->params))
break;
- /* continue action reached, re-enable tracing */
- if (tool->record)
- trace_instance_start(&tool->record->trace);
- if (tool->aa)
- trace_instance_start(&tool->aa->trace);
- timerlat_bpf_restart_tracing();
+ if (timerlat_bpf_restart_tracing()) {
+ err_msg("Error restarting BPF trace\n");
+ return -1;
+ }
}
}
timerlat_bpf_detach();
diff --git a/tools/tracing/rtla/src/timerlat_top.c b/tools/tracing/rtla/src/timerlat_top.c
index dd727cb48b551..c6f6757c3fb6b 100644
--- a/tools/tracing/rtla/src/timerlat_top.c
+++ b/tools/tracing/rtla/src/timerlat_top.c
@@ -17,6 +17,7 @@
#include "timerlat.h"
#include "timerlat_aa.h"
#include "timerlat_bpf.h"
+#include "common.h"
struct timerlat_top_cpu {
unsigned long long irq_count;
@@ -801,10 +802,10 @@ static struct osnoise_tool
static int
timerlat_top_bpf_main_loop(struct osnoise_tool *tool)
{
- struct timerlat_params *params = to_timerlat_params(tool->params);
+ const struct common_params *params = tool->params;
int retval, wait_retval;
- if (params->common.aa_only) {
+ if (params->aa_only) {
/* Auto-analysis only, just wait for stop tracing */
timerlat_bpf_wait(-1);
return 0;
@@ -812,8 +813,8 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool)
/* Pull and display data in a loop */
while (!stop_tracing) {
- wait_retval = timerlat_bpf_wait(params->common.quiet ? -1 :
- params->common.sleep_time);
+ wait_retval = timerlat_bpf_wait(params->quiet ? -1 :
+ params->sleep_time);
retval = timerlat_top_bpf_pull_data(tool);
if (retval) {
@@ -821,28 +822,27 @@ timerlat_top_bpf_main_loop(struct osnoise_tool *tool)
return retval;
}
- if (!params->common.quiet)
+ if (!params->quiet)
timerlat_print_stats(tool);
if (wait_retval != 0) {
/* Stopping requested by tracer */
- actions_perform(¶ms->common.threshold_actions);
+ retval = common_threshold_handler(tool);
+ if (retval)
+ return retval;
- if (!params->common.threshold_actions.continue_flag)
- /* continue flag not set, break */
+ if (!should_continue_tracing(tool->params))
break;
- /* continue action reached, re-enable tracing */
- if (tool->record)
- trace_instance_start(&tool->record->trace);
- if (tool->aa)
- trace_instance_start(&tool->aa->trace);
- timerlat_bpf_restart_tracing();
+ if (timerlat_bpf_restart_tracing()) {
+ err_msg("Error restarting BPF trace\n");
+ return -1;
+ }
}
/* is there still any user-threads ? */
- if (params->common.user_workload) {
- if (params->common.user.stopped_running) {
+ if (params->user_workload) {
+ if (params->user.stopped_running) {
debug_msg("timerlat user space threads stopped!\n");
break;
}
--
2.52.0
next prev parent reply other threads:[~2026-01-15 17:25 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 16:31 [PATCH v3 00/18] rtla: Robustness and code quality improvements Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 01/18] rtla: Exit on memory allocation failures during initialization Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 02/18] rtla: Use strdup() to simplify code Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 03/18] rtla: Simplify argument parsing Wander Lairson Costa
2026-01-15 21:47 ` Costa Shulyupin
2026-01-16 11:38 ` Wander Lairson Costa
2026-03-03 11:58 ` Tomas Glozar
2026-01-15 16:31 ` Wander Lairson Costa [this message]
2026-01-15 16:31 ` [PATCH v3 05/18] rtla: Replace magic number with MAX_PATH Wander Lairson Costa
2026-03-03 12:46 ` Tomas Glozar
2026-01-15 16:31 ` [PATCH v3 06/18] rtla: Simplify code by caching string lengths Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 07/18] rtla: Add strscpy() and replace strncpy() calls Wander Lairson Costa
2026-03-02 14:33 ` Tomas Glozar
2026-03-03 11:02 ` Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 08/18] rtla/timerlat: Add bounds check for softirq vector Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 09/18] rtla: Handle pthread_create() failure properly Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 10/18] rtla: Add str_has_prefix() helper function Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 11/18] rtla: Use str_has_prefix() for prefix checks Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 12/18] rtla: Enforce exact match for time unit suffixes Wander Lairson Costa
2026-03-03 14:27 ` Tomas Glozar
2026-03-09 17:17 ` Wander Lairson Costa
2026-03-04 13:57 ` Tomas Glozar
2026-03-09 17:15 ` Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 13/18] rtla: Use str_has_prefix() for option prefix check Wander Lairson Costa
2026-01-15 16:31 ` [PATCH v3 14/18] rtla/timerlat: Simplify RTLA_NO_BPF environment variable check Wander Lairson Costa
2026-03-03 14:38 ` Tomas Glozar
2026-01-15 16:31 ` [PATCH v3 15/18] rtla/trace: Fix write loop in trace_event_save_hist() Wander Lairson Costa
2026-03-03 14:51 ` Tomas Glozar
2026-01-15 16:31 ` [PATCH v3 16/18] rtla/trace: Fix I/O handling in save_trace_to_file() Wander Lairson Costa
2026-03-04 10:30 ` Tomas Glozar
2026-03-09 16:46 ` Wander Lairson Costa
2026-01-15 16:32 ` [PATCH v3 17/18] rtla/utils: Fix resource leak in set_comm_sched_attr() Wander Lairson Costa
2026-01-15 16:32 ` [PATCH v3 18/18] rtla/utils: Fix loop condition in PID validation Wander Lairson Costa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260115163650.118910-5-wander@redhat.com \
--to=wander@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=bristot@kernel.org \
--cc=costa.shul@redhat.com \
--cc=crwood@redhat.com \
--cc=dwagner@suse.de \
--cc=ipravdin.official@gmail.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox