perf/core: Preserve the hardware index field for missing branch stacks
PATCH 1/1 perf/core: Preserve the hardware index field for missing branch stacks
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.
--- kernel/events/core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/events/core.c +8 -1
@@ -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
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 5 lines
PERF_SAMPLE_BRANCH_HW_INDEXselects 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.
Quoted 8 lines
Emit an unknown hardware index (-1ULL) when the field is requested and account for it when preparing the sample. Events without
HW_INDEXand 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_INDEXenabled is claimed here.Signed-off-by Thaumy Cheng <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1