mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thaumy Cheng <thaumy.love@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Thaumy Cheng <thaumy.love@gmail.com>
Subject: [PATCH] perf/core: Preserve the hardware index field for missing branch stacks
Date: Mon, 23 Nov 2026 13:07:06 +0800	[thread overview]
Message-ID: <20261123050706.18428-1-thaumy.love@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-23  5:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261123050706.18428-1-thaumy.love@gmail.com \
    --to=thaumy.love@gmail.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®