* [PATCH] perf/core: Preserve the hardware index field for missing branch stacks
@ 2026-11-23 5:07 Thaumy Cheng
2026-11-23 5:13 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Thaumy Cheng @ 2026-11-23 5:07 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, James Clark
Cc: linux-perf-users, linux-kernel, Thaumy Cheng
PERF_SAMPLE_BRANCH_HW_INDEX selects a branch-stack layout containing a
hardware index after nr, including when nr is zero. The generic fallback
for a missing branch stack currently emits only nr, unlike the non-NULL
stack path and the layout expected by perf's sample parser.
Emit an unknown hardware index (-1ULL) when the field is requested and
account for it when preparing the sample. Events without HW_INDEX and
samples with a supplied branch stack retain their existing layout.
This makes the fallback consistent with the ABI; no reproducer for reaching
this fallback with HW_INDEX enabled is claimed here.
Signed-off-by: Thaumy Cheng <thaumy.love@gmail.com>
---
kernel/events/core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index e870f12c3ad8..9c51c7a1ae80 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8499,11 +8499,16 @@ void perf_output_sample(struct perf_output_handle *handle,
perf_output_copy(handle, data->br_stack_cntr, size);
}
} else {
+ u64 nr = 0;
+ u64 hw_idx = -1ULL;
+
/*
* we always store at least the value of nr
*/
- u64 nr = 0;
perf_output_put(handle, nr);
+
+ if (branch_sample_hw_index(event))
+ perf_output_put(handle, hw_idx);
}
}
@@ -8837,6 +8842,8 @@ void perf_prepare_sample(struct perf_sample_data *data,
if (filtered_sample_type & PERF_SAMPLE_BRANCH_STACK) {
data->br_stack = NULL;
data->dyn_size += sizeof(u64);
+ if (branch_sample_hw_index(event))
+ data->dyn_size += sizeof(u64);
data->sample_flags |= PERF_SAMPLE_BRANCH_STACK;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 5:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 5:07 [PATCH] perf/core: Preserve the hardware index field for missing branch stacks Thaumy Cheng
2026-11-23 5:13 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox