Thread (19 messages) flat view 19 messages, 4 authors, 26d ago
COLD26d

[PATCH 2/9] perf thread-stack: Report branch stack hw_idx as not available

From: Amir Ayupov <hidden>
Date: 2026-08-03 09:07:09
Also in: linux-doc, linux-perf-users
Subsystem: performance events subsystem, the rest · Maintainers: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds

thread_stack__br_sample() and thread_stack__br_sample_late() fill a
caller-supplied branch_stack that is typically allocated with zalloc(),
leaving hw_idx as 0. Zero is a valid hardware index, so consumers that
honour PERF_SAMPLE_BRANCH_HW_INDEX see a reconstructed branch stack
claiming to start at LBR TOS entry 0.

These branch stacks are reconstructed from instruction trace and have no
hardware index at all. Set hw_idx to -1ULL, which is the established way
to say "not available" and matches what intel-pt and cs-etm already put
in the branch stacks they synthesise directly.

Signed-off-by: Amir Ayupov <redacted>
---
 tools/perf/util/thread-stack.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index c5ce741b07446..1a3dffa83bde2 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -624,6 +624,7 @@ void thread_stack__br_sample(struct thread *thread, int cpu,
 	unsigned int nr;
 
 	dst->nr = 0;
+	dst->hw_idx = -1ULL;
 
 	if (!ts)
 		return;
@@ -686,6 +687,7 @@ void thread_stack__br_sample_late(struct thread *thread, int cpu,
 	bool start = false;
 
 	dst->nr = 0;
+	dst->hw_idx = -1ULL;
 
 	if (!ts)
 		return;
-- 
2.52.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help