From 4dc85eb58a1ab972392b53eb8e999e72263bc708 Mon Sep 17 00:00:00 2001 From: Valentin Schneider Date: Wed, 2 Sep 2026 14:39:35 +0200 Subject: [PATCH] rtla: Enable and disable events in the user-defined order Events are processed in LIFO order for ease of internal processing, but this is can be confusing to users if the processing ordering is exposed to them. A following commit will do just that by making it so the last-defined event options (filters/triggers) overrides any previous options for that same event. Thus, process the events in the user-defined order. Signed-off-by: Valentin Schneider Link: https://lore.kernel.org/r/20260902123942.695822-7-vschneid@redhat.com Signed-off-by: Tomas Glozar --- tools/tracing/rtla/src/trace.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 1c3e2b098ba8..05201745d898 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -447,6 +447,21 @@ static void trace_event_disable_trigger(struct trace_instance *instance, tevent->event ? : "*", tevent->trigger); } +static inline struct trace_events *trace_events_tail(struct trace_events *tevent) +{ + while (tevent && tevent->next) + tevent = tevent->next; + + return tevent; +} + +/* + * Events are stashed in LIFO order; flip that to FIFO to process them in the + * same order as they are defined by the user on the command line. + */ +#define for_each_trace_event(tevent) \ + for (tevent = trace_events_tail(tevent); tevent; tevent = tevent->prev) + /* * trace_events_disable - disable all trace events */ @@ -458,7 +473,7 @@ void trace_events_disable(struct trace_instance *instance, if (!events) return; - while (tevent) { + for_each_trace_event(tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); if (tevent->enabled) { trace_event_disable_filter(instance, tevent); @@ -467,7 +482,6 @@ void trace_events_disable(struct trace_instance *instance, } tevent->enabled = 0; - tevent = tevent->next; } } @@ -551,7 +565,10 @@ int trace_events_enable(struct trace_instance *instance, struct trace_events *tevent = events; int retval; - while (tevent) { + if (!events) + return 0; + + for_each_trace_event(tevent) { debug_msg("Enabling event %s:%s\n", tevent->system, tevent->event ? : "*"); retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event); if (retval < 0) { @@ -569,7 +586,6 @@ int trace_events_enable(struct trace_instance *instance, return 1; tevent->enabled = 1; - tevent = tevent->next; } return 0;