* [PATCH] tracing: Don't use TRACE_BRANCH_BIT as a mask
@ 2026-11-29 0:06 Karl Mehltretter
0 siblings, 0 replies; only message in thread
From: Karl Mehltretter @ 2026-11-29 0:06 UTC (permalink / raw)
To: Steven Rostedt, Masami Hiramatsu
Cc: Karl Mehltretter, Mathieu Desnoyers, linux-trace-kernel, linux-kernel
TRACE_BRANCH_BIT is a bit number, but the branch tracer uses it as a
mask on current->trace_recursion. Instead of its own bit, the branch
tracer tests, sets and clears bits that function tracing uses for its
own recursion protection.
While a function tracing callback holds one of these bits, the current
task's branch events are lost. This includes events in an interrupt that
arrives during the callback.
Use the trace_recursion_*() helpers, which take a bit number.
Fixes: 6224beb12e19 ("tracing: Have branch tracer use recursive field of task struct")
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Assisted by an LLM.
In mainline, the mask only covered unused bits until v5.7, when commit
5412e0b763e0 ("tracing: Remove unused TRACE_BUFFER bits") moved the
function tracing bits to 0-3. TRACE_BRANCH_BIT is now 15 (bits 0-3) in
mainline and 6.1.y to 7.3.y, and 10 (bits 1 and 3) in 5.10.y and 5.15.y.
Tested on v7.4-rc2 with PREEMPT and PROVE_LOCKING in an arm64 KVM guest
on a Raspberry Pi 500+. I ran function and function_graph with the
branch option set while forking processes. Test-only counters recorded
skips that were not due to recursion.
Share of non-recursive branch events skipped, three boots each:
v7.4-rc2 + this patch
function function_graph (both tracers)
hardirq 7.5-18.8% 10.6-11.0% 0
softirq 4.0-5.4% 6.3-7.3% 0
task 0.1% 0.4% 0
The branch tracer alone shows 0 on both kernels. Recursion is still
caught with the patch. These are debug kernels with test counters, so
other setups will show different rates. NMIs and other architectures are
untested.
kernel/trace/trace_branch.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index d8e97ad798f0..ed19e69f9294 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -38,7 +38,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)
unsigned int trace_ctx;
const char *p;
- if (current->trace_recursion & TRACE_BRANCH_BIT)
+ if (trace_recursion_test(TRACE_BRANCH_BIT))
return;
/*
@@ -52,7 +52,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)
return;
raw_local_irq_save(flags);
- current->trace_recursion |= TRACE_BRANCH_BIT;
+ trace_recursion_set(TRACE_BRANCH_BIT);
if (!tracer_tracing_is_on_cpu(tr, raw_smp_processor_id()))
goto out;
@@ -80,7 +80,7 @@ probe_likely_condition(struct ftrace_likely_data *f, int val, int expect)
trace_buffer_unlock_commit_nostack(buffer, event);
out:
- current->trace_recursion &= ~TRACE_BRANCH_BIT;
+ trace_recursion_clear(TRACE_BRANCH_BIT);
raw_local_irq_restore(flags);
}
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.39.5
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-29 0:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 0:06 [PATCH] tracing: Don't use TRACE_BRANCH_BIT as a mask Karl Mehltretter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®