From: Tomas Glozar <tglozar@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Crystal Wood <crwood@redhat.com>, John Kacur <jkacur@redhat.com>,
Luis Goncalves <lgoncalv@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux Trace Kernel <linux-trace-kernel@vger.kernel.org>,
Tomas Glozar <tglozar@redhat.com>
Subject: [RFC PATCH 2/3] rtla/timerlat_bpf: Filter samples unseen by tracer
Date: Fri, 23 Jan 2026 16:25:33 +0100 [thread overview]
Message-ID: <20260123152534.1036533-3-tglozar@redhat.com> (raw)
In-Reply-To: <20260123152534.1036533-1-tglozar@redhat.com>
If both BPF and tracefs sample collection are used (mixed mode), drop
samples seen by BPF program when the count of timerlat instances that
are both registered and have tracing on does not match the expected value.
This ensures that there are no samples seen by BPF that are not included
in auto-analysis or trace output.
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
tools/tracing/rtla/src/timerlat.bpf.c | 9 +++++++++
tools/tracing/rtla/src/timerlat.c | 18 +++++++++++++++++-
tools/tracing/rtla/src/timerlat.h | 2 ++
tools/tracing/rtla/src/timerlat_bpf.c | 8 ++++++++
4 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/tools/tracing/rtla/src/timerlat.bpf.c b/tools/tracing/rtla/src/timerlat.bpf.c
index 549d2d2191d2..2724a9bfea4e 100644
--- a/tools/tracing/rtla/src/timerlat.bpf.c
+++ b/tools/tracing/rtla/src/timerlat.bpf.c
@@ -12,6 +12,8 @@ char LICENSE[] SEC("license") = "GPL";
struct trace_event_raw_timerlat_sample {
unsigned long long timer_latency;
int context;
+ int instances_registered;
+ int instances_on;
} __attribute__((preserve_access_index));
struct {
@@ -58,6 +60,8 @@ const volatile int entries = 256;
const volatile int irq_threshold;
const volatile int thread_threshold;
const volatile bool aa_only;
+const volatile int instances_registered = -1;
+const volatile int instances_on = -1;
nosubprog unsigned long long map_get(void *map,
unsigned int key)
@@ -143,6 +147,11 @@ int handle_timerlat_sample(struct trace_event_raw_timerlat_sample *tp_args)
unsigned long long latency, latency_us;
int bucket;
+ if ((instances_registered != -1 && tp_args->instances_registered != instances_registered)
+ || (instances_on != -1 && tp_args->instances_on != instances_on))
+ /* This sample is not seen by all trace instances, filter it out */
+ return 0;
+
if (map_get(&stop_tracing, 0))
return 0;
diff --git a/tools/tracing/rtla/src/timerlat.c b/tools/tracing/rtla/src/timerlat.c
index 8f8811f7a13b..069f916100e7 100644
--- a/tools/tracing/rtla/src/timerlat.c
+++ b/tools/tracing/rtla/src/timerlat.c
@@ -28,6 +28,7 @@ int
timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
{
int retval;
+ struct tep_event *event = NULL;
/*
* Try to enable BPF, unless disabled explicitly.
@@ -36,10 +37,25 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
if (getenv("RTLA_NO_BPF") && strncmp(getenv("RTLA_NO_BPF"), "1", 2) == 0) {
debug_msg("RTLA_NO_BPF set, disabling BPF\n");
params->mode = TRACING_MODE_TRACEFS;
- } else if (!tep_find_event_by_name(tool->trace.tep, "osnoise", "timerlat_sample")) {
+ } else if (!(event = tep_find_event_by_name(tool->trace.tep, "osnoise", "timerlat_sample"))) {
debug_msg("osnoise:timerlat_sample missing, disabling BPF\n");
params->mode = TRACING_MODE_TRACEFS;
+ }
+
+ if (event && tep_find_field(event, "instances_registered") &&
+ tep_find_field(event, "instances_on")) {
+ params->has_instance_count_fields = true;
+
+ if (!params->no_aa)
+ params->instances_on++;
+ if (params->common.threshold_actions.present[ACTION_TRACE_OUTPUT] ||
+ params->common.end_actions.present[ACTION_TRACE_OUTPUT])
+ params->instances_on++;
} else {
+ params->has_instance_count_fields = false;
+ }
+
+ if (params->mode != TRACING_MODE_TRACEFS) {
retval = timerlat_bpf_init(params);
if (retval) {
debug_msg("Could not enable BPF\n");
diff --git a/tools/tracing/rtla/src/timerlat.h b/tools/tracing/rtla/src/timerlat.h
index 8dd5d134ce08..ef97e545c7ff 100644
--- a/tools/tracing/rtla/src/timerlat.h
+++ b/tools/tracing/rtla/src/timerlat.h
@@ -28,6 +28,8 @@ struct timerlat_params {
int deepest_idle_state;
enum timerlat_tracing_mode mode;
const char *bpf_action_program;
+ bool has_instance_count_fields;
+ int instances_on;
};
#define to_timerlat_params(ptr) container_of(ptr, struct timerlat_params, common)
diff --git a/tools/tracing/rtla/src/timerlat_bpf.c b/tools/tracing/rtla/src/timerlat_bpf.c
index 05adf18303df..80801796bbf0 100644
--- a/tools/tracing/rtla/src/timerlat_bpf.c
+++ b/tools/tracing/rtla/src/timerlat_bpf.c
@@ -53,6 +53,14 @@ int timerlat_bpf_init(struct timerlat_params *params)
bpf_map__set_autocreate(bpf->maps.summary_user, false);
}
+ if (params->mode == TRACING_MODE_MIXED && params->has_instance_count_fields) {
+ bpf->rodata->instances_on = params->instances_on;
+ bpf->rodata->instances_registered = params->instances_on + 1; /* +1 for the main instance */
+ } else {
+ bpf->rodata->instances_registered = -1;
+ bpf->rodata->instances_on = -1;
+ }
+
/* Load and verify BPF program */
err = timerlat_bpf__load(bpf);
if (err) {
--
2.52.0
next prev parent reply other threads:[~2026-01-23 15:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 15:25 [RFC PATCH 0/3] rtla: Synchronize sample collection methods Tomas Glozar
2026-01-23 15:25 ` [RFC PATCH 1/3] tracing/osnoise: Record timerlat instance counts Tomas Glozar
2026-01-23 15:25 ` Tomas Glozar [this message]
2026-01-23 15:25 ` [RFC PATCH 3/3] rtla/timerlat: Attach BPF program before tracers Tomas Glozar
2026-01-24 18:50 ` [RFC PATCH 0/3] rtla: Synchronize sample collection methods Steven Rostedt
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=20260123152534.1036533-3-tglozar@redhat.com \
--to=tglozar@redhat.com \
--cc=crwood@redhat.com \
--cc=jkacur@redhat.com \
--cc=lgoncalv@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/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