From: Tomas Glozar <tglozar@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>, Tomas Glozar <tglozar@redhat.com>
Cc: John Kacur <jkacur@redhat.com>,
Luis Goncalves <lgoncalv@redhat.com>,
Crystal Wood <crwood@redhat.com>,
Costa Shulyupin <costa.shul@redhat.com>,
Wander Lairson Costa <wander@redhat.com>,
linux-trace-kernel <linux-trace-kernel@vger.kernel.org>
Subject: [RFC PATCH 01/10] rtla: Support auto-analysis as an action
Date: Fri, 27 Nov 2026 16:31:57 +0100 [thread overview]
Message-ID: <20261127153206.134322-2-tglozar@redhat.com> (raw)
In-Reply-To: <20261127153206.134322-1-tglozar@redhat.com>
rtla currently performs auto-analysis of a latency spike at the end of
the measurement, after the results (top/hist) are printed, in case
tracing was stopped with -i/--irq, -T/--thread, -s/--stop,
-S/--stop-total, or -a/--auto, and was not resumed with --on-threshold
continue.
This has multiple disadvantages:
- The user is not able to make auto-analysis run before other actions,
e.g. trace output.
- The user is not able to make auto-analysis run conditionally depending
on the result of the previous actions.
- Auto-analysis can only be used to analyze a latency that stops tracing
without resuming, thus, only one latency spike can be analyzed per
rtla run.
To provide more flexibility, add an option to run auto-analysis as an
action (--on-threshold aa, --on-end aa). The default behavior of
auto-analyzing at the end of the measurement stays unchanged.
If the auto-analysis action is present, the default auto-analysis at the
end is skipped to avoid analyzing twice.
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
tools/tracing/rtla/src/actions.c | 39 +++++++++++---
tools/tracing/rtla/src/actions.h | 8 ++-
tools/tracing/rtla/src/cli.c | 6 +++
tools/tracing/rtla/src/common.c | 21 +++++---
tools/tracing/rtla/src/common.h | 7 +++
tools/tracing/rtla/src/timerlat_aa.c | 67 +++++++++++++++++++++++++
tools/tracing/rtla/src/trace.c | 8 +++
tools/tracing/rtla/src/trace.h | 1 +
tools/tracing/rtla/tests/unit/actions.c | 10 ++--
9 files changed, 147 insertions(+), 20 deletions(-)
diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/actions.c
index bf13d9d68f169..a554539a522c6 100644
--- a/tools/tracing/rtla/src/actions.c
+++ b/tools/tracing/rtla/src/actions.c
@@ -4,9 +4,7 @@
#include <signal.h>
#include <unistd.h>
-#include "actions.h"
-#include "trace.h"
-#include "utils.h"
+#include "common.h"
/*
* actions_init - initialize struct actions
@@ -20,7 +18,7 @@ actions_init(struct actions *self)
self->continue_flag = false;
/* This has to be set by the user */
- self->trace_output_inst = NULL;
+ self->tool = NULL;
}
/*
@@ -111,6 +109,17 @@ actions_add_continue(struct actions *self)
action->type = ACTION_CONTINUE;
}
+/*
+ * actions_add_aa - add an action to perform auto-analysis
+ */
+void actions_add_aa(struct actions *self)
+{
+ struct action *action = actions_new(self);
+
+ self->present[ACTION_AA] = true;
+ action->type = ACTION_AA;
+}
+
static inline const char *__extract_arg(const char *token, const char *opt, size_t opt_len)
{
const size_t tok_len = strlen(token);
@@ -164,6 +173,8 @@ actions_parse(struct actions *self, const char *trigger, const char *tracefn)
type = ACTION_SHELL;
else if (strcmp(token, "continue") == 0)
type = ACTION_CONTINUE;
+ else if (strcmp(token, "aa") == 0)
+ type = ACTION_AA;
else
/* Invalid trigger type */
return -1;
@@ -231,6 +242,12 @@ actions_parse(struct actions *self, const char *trigger, const char *tracefn)
return -1;
actions_add_continue(self);
break;
+ case ACTION_AA:
+ /* Takes no argument */
+ if (token != NULL)
+ return -1;
+ actions_add_aa(self);
+ break;
default:
return -1;
}
@@ -240,9 +257,12 @@ actions_parse(struct actions *self, const char *trigger, const char *tracefn)
/*
* actions_perform - perform all actions
+ * @stopped: Whether tracing was stopped on a latency threshold.
+ *
+ * Returns 0 if all actions succeeded, or an error code if an action failed.
*/
int
-actions_perform(struct actions *self)
+actions_perform(struct actions *self, bool stopped)
{
int pid, retval;
const struct action *action;
@@ -252,7 +272,8 @@ actions_perform(struct actions *self)
for_each_action(self, action) {
switch (action->type) {
case ACTION_TRACE_OUTPUT:
- retval = save_trace_to_file(self->trace_output_inst, action->trace_output);
+ retval = save_trace_to_file(self->tool->record->trace.inst,
+ action->trace_output);
if (retval) {
err_msg("Error saving trace\n");
return retval;
@@ -277,6 +298,12 @@ actions_perform(struct actions *self)
case ACTION_CONTINUE:
self->continue_flag = true;
return 0;
+ case ACTION_AA:
+ if (self->tool->ops->analyze)
+ self->tool->ops->analyze(self->tool, stopped);
+ /* Ensure correct ordering with respect to shell command output */
+ fflush(stdout);
+ break;
default:
break;
}
diff --git a/tools/tracing/rtla/src/actions.h b/tools/tracing/rtla/src/actions.h
index 034048682fefb..2688f22bae90d 100644
--- a/tools/tracing/rtla/src/actions.h
+++ b/tools/tracing/rtla/src/actions.h
@@ -2,12 +2,15 @@
#include <tracefs.h>
#include <stdbool.h>
+struct osnoise_tool;
+
enum action_type {
ACTION_NONE = 0,
ACTION_TRACE_OUTPUT,
ACTION_SIGNAL,
ACTION_SHELL,
ACTION_CONTINUE,
+ ACTION_AA,
ACTION_FIELD_N
};
@@ -39,7 +42,7 @@ struct actions {
bool continue_flag;
/* External dependencies */
- struct tracefs_instance *trace_output_inst;
+ struct osnoise_tool *tool;
};
#define for_each_action(actions, action) \
@@ -53,5 +56,6 @@ void actions_add_trace_output(struct actions *self, const char *trace_output);
void actions_add_signal(struct actions *self, int signal, int pid);
void actions_add_shell(struct actions *self, const char *command);
void actions_add_continue(struct actions *self);
+void actions_add_aa(struct actions *self);
int actions_parse(struct actions *self, const char *trigger, const char *tracefn);
-int actions_perform(struct actions *self);
+int actions_perform(struct actions *self, bool stopped);
diff --git a/tools/tracing/rtla/src/cli.c b/tools/tracing/rtla/src/cli.c
index 8c02b94ce4321..9742c70485e5b 100644
--- a/tools/tracing/rtla/src/cli.c
+++ b/tools/tracing/rtla/src/cli.c
@@ -128,6 +128,9 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
if (geteuid() && !in_unit_test)
fatal("osnoise needs root permission");
+ if (aa_action_present(¶ms->common))
+ fatal("auto-analysis action is not supported with osnoise tools");
+
return ¶ms->common;
}
@@ -210,6 +213,9 @@ struct common_params *osnoise_hist_parse_args(int argc, char **argv)
if (geteuid() && !in_unit_test)
fatal("rtla needs root permission");
+ if (aa_action_present(¶ms->common))
+ fatal("auto-analysis action is not supported with osnoise tools");
+
if (params->common.hist.no_index && !params->common.hist.with_zeros)
fatal("no-index set and with-zeros not set - it does not make sense");
diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/common.c
index ac4172bcc4444..e085eb6c8f13f 100644
--- a/tools/tracing/rtla/src/common.c
+++ b/tools/tracing/rtla/src/common.c
@@ -138,7 +138,7 @@ common_apply_config(struct osnoise_tool *tool, struct common_params *params)
int
common_threshold_handler(const struct osnoise_tool *tool)
{
- actions_perform(&tool->params->threshold_actions);
+ actions_perform(&tool->params->threshold_actions, true);
if (!should_continue_tracing(tool->params))
/* continue flag not set, break */
@@ -147,7 +147,8 @@ common_threshold_handler(const struct osnoise_tool *tool)
/* 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))
+ if (tool->aa && (trace_instance_clear(&tool->aa->trace) ||
+ trace_instance_start(&tool->aa->trace)))
goto err;
return 0;
@@ -197,6 +198,13 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
*/
trace_tool = tool;
+ /*
+ * Expose the tool to actions, so they can access the trace output
+ * instance and auto-analysis callback.
+ */
+ params->threshold_actions.tool = tool;
+ params->end_actions.tool = tool;
+
retval = ops->apply_config(tool);
if (retval) {
err_msg("Could not apply config\n");
@@ -233,8 +241,6 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
err_msg("Failed to enable the trace instance\n");
goto out_free;
}
- params->threshold_actions.trace_output_inst = tool->record->trace.inst;
- params->end_actions.trace_output_inst = tool->record->trace.inst;
if (params->events) {
retval = trace_events_enable(&tool->record->trace, params->events);
@@ -290,17 +296,18 @@ int run_tool(struct tool_ops *ops, int argc, char *argv[])
ops->print_stats(tool);
- actions_perform(¶ms->end_actions);
-
return_value = PASSED;
stopped = osnoise_trace_is_off(tool, tool->record) && !stop_tracing;
+
+ actions_perform(¶ms->end_actions, stopped);
+
if (stopped) {
printf("%s hit stop tracing\n", ops->tracer);
return_value = FAILED;
}
- if (ops->analyze)
+ if (ops->analyze && !aa_action_present(params))
ops->analyze(tool, stopped);
out_signals:
diff --git a/tools/tracing/rtla/src/common.h b/tools/tracing/rtla/src/common.h
index ec2f6f86ec3a0..ed0e318d8e151 100644
--- a/tools/tracing/rtla/src/common.h
+++ b/tools/tracing/rtla/src/common.h
@@ -166,6 +166,13 @@ should_continue_tracing(const struct common_params *params)
return params->threshold_actions.continue_flag;
}
+static inline bool
+aa_action_present(const struct common_params *params)
+{
+ return params->threshold_actions.present[ACTION_AA] ||
+ params->end_actions.present[ACTION_AA];
+}
+
int
common_threshold_handler(const struct osnoise_tool *tool);
diff --git a/tools/tracing/rtla/src/timerlat_aa.c b/tools/tracing/rtla/src/timerlat_aa.c
index a121ff9d2c571..11ddceab208ac 100644
--- a/tools/tracing/rtla/src/timerlat_aa.c
+++ b/tools/tracing/rtla/src/timerlat_aa.c
@@ -740,6 +740,70 @@ static int timerlat_auto_analysis_collect_trace(struct timerlat_aa_context *taa_
return 1;
}
+/*
+ * timerlat_aa_reset - Clear old data to prepare for analysis
+ */
+static void timerlat_aa_reset(struct timerlat_aa_context *taa_ctx)
+{
+ struct timerlat_aa_data *taa_data;
+ int cpu;
+
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ taa_data = &taa_ctx->taa_data[cpu];
+
+ /* Current CPU state */
+ taa_data->curr_state = TIMERLAT_INIT;
+
+ /* timerlat IRQ latency */
+ taa_data->tlat_irq_seqnum = 0;
+ taa_data->tlat_irq_latency = 0;
+ taa_data->tlat_irq_timstamp = 0;
+
+ /* timerlat Thread latency */
+ taa_data->tlat_thread_seqnum = 0;
+ taa_data->tlat_thread_latency = 0;
+ taa_data->tlat_thread_timstamp = 0;
+
+ /* Thread running when the IRQ arrived */
+ taa_data->run_thread_pid = 0;
+ memset(taa_data->run_thread_comm, 0, MAX_COMM);
+ taa_data->thread_blocking_duration = 0;
+ taa_data->max_exit_idle_latency = 0;
+
+ /* Information about the timerlat timer irq */
+ taa_data->timer_irq_start_time = 0;
+ taa_data->timer_irq_start_delay = 0;
+ taa_data->timer_irq_duration = 0;
+ taa_data->timer_exit_from_idle = 0;
+
+ /* Last IRQ before the timerlat irq arrived */
+ taa_data->prev_irq_duration = 0;
+ taa_data->prev_irq_timstamp = 0;
+
+ /* Interference sum */
+ taa_data->thread_nmi_sum = 0;
+ taa_data->thread_irq_sum = 0;
+ taa_data->thread_softirq_sum = 0;
+ taa_data->thread_thread_sum = 0;
+
+ /* Interference task information */
+ trace_seq_reset(taa_data->prev_irqs_seq);
+ trace_seq_reset(taa_data->nmi_seq);
+ trace_seq_reset(taa_data->irqs_seq);
+ trace_seq_reset(taa_data->softirqs_seq);
+ trace_seq_reset(taa_data->threads_seq);
+ trace_seq_reset(taa_data->stack_seq);
+
+ /* Current thread */
+ memset(taa_data->current_comm, 0, MAX_COMM);
+ taa_data->current_pid = 0;
+
+ /* Is the system running a kworker? */
+ taa_data->kworker = 0;
+ taa_data->kworker_func = 0;
+ }
+}
+
/**
* timerlat_auto_analysis - Analyze the collected data
*/
@@ -752,6 +816,9 @@ void timerlat_auto_analysis(int irq_thresh, int thread_thresh)
struct tep_handle *tep;
int cpu;
+ /* reset any data left over from previous run */
+ timerlat_aa_reset(taa_ctx);
+
timerlat_auto_analysis_collect_trace(taa_ctx);
/* bring stop tracing to the ns scale */
diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c
index 4b5f4d033d8b4..c608393533494 100644
--- a/tools/tracing/rtla/src/trace.c
+++ b/tools/tracing/rtla/src/trace.c
@@ -267,6 +267,14 @@ int trace_instance_stop(struct trace_instance *trace)
return tracefs_trace_off(trace->inst);
}
+/*
+ * trace_instance_clear - clear all samples of a given rtla instance
+ */
+int trace_instance_clear(struct trace_instance *trace)
+{
+ return tracefs_instance_file_write(trace->inst, "trace", "");
+}
+
/*
* trace_events_free - free a list of trace events
*/
diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h
index 94e4510db2d19..b3a626b676b3d 100644
--- a/tools/tracing/rtla/src/trace.h
+++ b/tools/tracing/rtla/src/trace.h
@@ -26,6 +26,7 @@ struct trace_instance {
int trace_instance_init(struct trace_instance *trace, char *tool_name);
int trace_instance_start(struct trace_instance *trace);
int trace_instance_stop(struct trace_instance *trace);
+int trace_instance_clear(struct trace_instance *trace);
void trace_instance_destroy(struct trace_instance *trace);
struct trace_seq *get_trace_seq(void);
diff --git a/tools/tracing/rtla/tests/unit/actions.c b/tools/tracing/rtla/tests/unit/actions.c
index 94ad5ad42774b..6d91ad698a925 100644
--- a/tools/tracing/rtla/tests/unit/actions.c
+++ b/tools/tracing/rtla/tests/unit/actions.c
@@ -27,7 +27,7 @@ START_TEST(test_actions_init)
ck_assert_int_eq(actions.len, 0);
ck_assert_int_eq(actions.size, action_default_size);
ck_assert(!actions.continue_flag);
- ck_assert_ptr_eq(actions.trace_output_inst, NULL);
+ ck_assert_ptr_eq(actions.tool, NULL);
}
END_TEST
@@ -302,7 +302,7 @@ END_TEST
START_TEST(test_actions_perform_continue)
{
actions_add_continue(&actions_fixture);
- ck_assert_int_eq(actions_perform(&actions_fixture), 0);
+ ck_assert_int_eq(actions_perform(&actions_fixture, true), 0);
ck_assert(actions_fixture.continue_flag);
}
@@ -312,7 +312,7 @@ START_TEST(test_actions_perform_continue_after_successful_shell_command)
{
actions_add_shell(&actions_fixture, "exit 0");
actions_add_continue(&actions_fixture);
- ck_assert_int_eq(actions_perform(&actions_fixture), 0 << 8);
+ ck_assert_int_eq(actions_perform(&actions_fixture, true), 0 << 8);
ck_assert(actions_fixture.continue_flag);
}
@@ -322,7 +322,7 @@ START_TEST(test_actions_perform_continue_after_failed_shell_command)
{
actions_add_shell(&actions_fixture, "exit 1");
actions_add_continue(&actions_fixture);
- ck_assert_int_eq(actions_perform(&actions_fixture), 1 << 8);
+ ck_assert_int_eq(actions_perform(&actions_fixture, true), 1 << 8);
ck_assert(!actions_fixture.continue_flag);
}
@@ -334,7 +334,7 @@ START_TEST(test_actions_perform_continue_unset_flag)
actions_add_shell(&actions_fixture, "exit 1");
actions_add_continue(&actions_fixture);
- ck_assert_int_eq(actions_perform(&actions_fixture), 1 << 8);
+ ck_assert_int_eq(actions_perform(&actions_fixture, true), 1 << 8);
ck_assert(!actions_fixture.continue_flag);
}
--
2.56.1
next prev parent reply other threads:[~2026-11-27 15:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:31 [RFC PATCH 00/10] rtla/timerlat: Add auto-analysis action and report spike timestamps Tomas Glozar
2026-11-27 15:31 ` Tomas Glozar [this message]
2026-11-27 15:31 ` [RFC PATCH 02/10] rtla/tests: Add unit tests for aa action Tomas Glozar
2026-11-27 15:31 ` [RFC PATCH 03/10] rtla/tests: Add runtime " Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 04/10] Documentation/rtla: Document " Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 05/10] rtla/trace: Add helper to read "now ts" stats field Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 06/10] rtla/trace: Add helper to gather "now ts" over a CPU set Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 07/10] rtla/trace: Allow storing start clock value of tracefs instances Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 08/10] rtla/timerlat: Save the trace clock at measurement start Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 09/10] rtla/timerlat_aa: Print time offset and seqnum of the spike Tomas Glozar
2026-11-27 15:32 ` [RFC PATCH 10/10] Documentation/rtla: Document auto-analysis timestamps Tomas Glozar
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=20261127153206.134322-2-tglozar@redhat.com \
--to=tglozar@redhat.com \
--cc=costa.shul@redhat.com \
--cc=crwood@redhat.com \
--cc=jkacur@redhat.com \
--cc=lgoncalv@redhat.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=wander@redhat.com \
/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