[PATCH v3 3/6] rtla/osnoise: Leverage IPI event filters when tracing a subset of CPUs
From: Valentin Schneider
Date: Wed Jul 15 2026 - 11:56:05 EST
Leverage the kernel event filtering infrastructure to only emit IPI events
if they target CPUs that are being traced, as specified by the -c cmdline
option.
Note that some post-processing is still required for the ipi_send_cpumask
event, as the event being emitted means *some* CPUs targeted by that event
are monitored, but not all of them - userspace has to recompute that
intersection.
Signed-off-by: Valentin Schneider <vschneid@xxxxxxxxxx>
---
tools/tracing/rtla/src/osnoise_top.c | 38 ++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c
index 7b5ae5336cf08..353b435fefcf8 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -302,17 +302,13 @@ osnoise_ipi_cpu_handler(struct trace_seq *s, struct tep_record *record,
struct tep_event *event, void *context)
{
struct osnoise_tool *tool;
- struct osnoise_params *params;
unsigned long long dst_cpu;
struct trace_instance *trace = context;
tool = container_of(trace, struct osnoise_tool, trace);
- params = to_osnoise_params(tool->params);
-
tep_get_field_val(s, event, "cpu", record, &dst_cpu, 1);
- if (CPU_ISSET(dst_cpu, ¶ms->common.monitored_cpus))
- account_ipi(tool, dst_cpu);
+ account_ipi(tool, dst_cpu);
return 0;
}
@@ -346,6 +342,11 @@ osnoise_ipi_cpumask_handler(struct trace_seq *s, struct tep_record *record,
return 0;
}
+ /*
+ * Despite already filtering for such an intersection, we need to compute
+ * the intersection here as the @cpumask field may contain non-monitored
+ * CPUs.
+ */
CPU_AND(&cpumask_tmp_cpus, event_cpus, ¶ms->common.monitored_cpus);
/*
@@ -398,6 +399,33 @@ struct osnoise_tool *osnoise_init_top(struct common_params *params)
goto out_err;
}
+ /*
+ * If tracing on a subset of possible CPUs, leverage the kernel filtering
+ * infrastructure to only generate events on traced CPUs.
+ */
+ if (params->cpus) {
+ char filter[MAX_PATH];
+
+ snprintf(filter, ARRAY_SIZE(filter), "cpu & CPUS{%s}\n", params->cpus);
+ retval = tracefs_event_file_write(tool->trace.inst,
+ "ipi", "ipi_send_cpu", "filter",
+ filter);
+ if (retval < 0) {
+ err_msg("Could not set ipi_send_cpu CPU filter\n");
+ goto out_err;
+ }
+
+
+ snprintf(filter, ARRAY_SIZE(filter), "cpumask & CPUS{%s}\n", params->cpus);
+ retval = tracefs_event_file_write(tool->trace.inst,
+ "ipi", "ipi_send_cpumask", "filter",
+ filter);
+ if (retval < 0) {
+ err_msg("Could not set ipi_send_cpumask CPU filter\n");
+ goto out_err;
+ }
+ }
+
tep_register_event_handler(tool->trace.tep, -1, "ipi", "ipi_send_cpu",
osnoise_ipi_cpu_handler, NULL);
--
2.55.0