mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Leo Yan <leo.yan@linux.dev>, Dmitry Vyukov <dvyukov@google.com>,
	"Steinar H . Gunderson" <sesse@google.com>,
	Stephen Brennan <stephen.s.brennan@oracle.com>,
	Thomas Falcon <thomas.falcon@intel.com>,
	linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI
Date: Wed, 25 Nov 2026 13:59:22 -0800	[thread overview]
Message-ID: <awdaOldoL7p1Y_Sz@google.com> (raw)
In-Reply-To: <CAP-5=fU-tWJM7brF=YJGfX0fbdivH-oFDo0s=PCt-UcQcqEEfA@mail.gmail.com>

On Tue, Nov 24, 2026 at 01:00:06PM -0800, Ian Rogers wrote:
> On Tue, Nov 24, 2026 at 2:36 AM Athira Rajeev <atrajeev@linux.ibm.com> wrote:
> >
> >
> >
> > > On 16 Nov 2026, at 1:13 PM, Ian Rogers <irogers@google.com> wrote:
> > >
> > > Introduce PERF_SAMPLE_BUILD_ID_OFFSET and
> > > PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET in enum perf_event_sample_format.
> > >
> > > For PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET (and
> > > PERF_RECORD_CALLCHAIN_DEFERRED when PERF_RECORD_MISC_MMAP_BUILD_ID is
> > > set), encode a deduplicated table of variable-length build IDs
> > > (u32 nr_build_ids, u32 nr_offsets, followed by packed { u8 size;
> > > u8 data[size]; } entries padded to 8-byte alignment) and an array of
> > > 64-bit offsets whose top 8 bits encode the 1-based build ID index (or
> > > 0x00 for unresolved user addresses and 0xff for kernel/context entries).
> > > In common cases where multiple callchain frames belong to the same
> > > binary, each unique build ID is encoded only once.
> > >
> > > Suggested-by: Namhyung Kim <namhyung@kernel.org>
> > > Signed-off-by: Ian Rogers <irogers@google.com>
> > > ---
> > > include/uapi/linux/perf_event.h | 59 ++++++++++++++++++++++++++++++---
> > > 1 file changed, 54 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
> > > index deb7c42d109b..775420ed9aee 100644
> > > --- a/include/uapi/linux/perf_event.h
> > > +++ b/include/uapi/linux/perf_event.h
> > > @@ -165,8 +165,10 @@ enum perf_event_sample_format {
> > > PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22,
> > > PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23,
> > > PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24,
> > > + PERF_SAMPLE_BUILD_ID_OFFSET = 1U << 25,
> > > + PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET = 1U << 26,
> > >
> > > - PERF_SAMPLE_MAX = 1U << 25, /* non-ABI */
> > > + PERF_SAMPLE_MAX = 1U << 27, /* non-ABI */
> > > };
> > >
> > > #define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
> > > @@ -840,7 +842,8 @@ struct perf_event_mmap_page {
> > >  *
> > >  *   PERF_RECORD_MISC_EXACT_IP           - PERF_RECORD_SAMPLE of precise events
> > >  *   PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
> > > - *   PERF_RECORD_MISC_MMAP_BUILD_ID      - PERF_RECORD_MMAP2 event
> > > + *   PERF_RECORD_MISC_MMAP_BUILD_ID      - PERF_RECORD_MMAP2 and
> > > + *                                         PERF_RECORD_CALLCHAIN_DEFERRED events
> > >  *
> > >  *
> > >  * PERF_RECORD_MISC_EXACT_IP:
> > > @@ -852,7 +855,7 @@ struct perf_event_mmap_page {
> > >  *   Indicates that thread was preempted in TASK_RUNNING state.
> > >  *
> > >  * PERF_RECORD_MISC_MMAP_BUILD_ID:
> > > - *   Indicates that mmap2 event carries build ID data.
> > > + *   Indicates that mmap2 or deferred callchain event carries build ID data.
> > >  */
> > > #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
> > > #define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
> > > @@ -1095,6 +1098,38 @@ enum perf_event_type {
> > > * { u64 code_page_size;} && PERF_SAMPLE_CODE_PAGE_SIZE
> > > * { u64 size;
> > > *  char data[size]; } && PERF_SAMPLE_AUX
> > > + * { union {
> > > + * struct {
> > > + * struct perf_build_id bid;
> > > + * u64 offset;
> > > + * };
> > > + * struct {
> > > + * u64 zero;
> > > + * u64 context;
> > > + * u64 cookie;
> > > + * u64 ip;
> > > + * }; && attr.defer_callchain
> > > + *  }; } && PERF_SAMPLE_BUILD_ID_OFFSET
> > > + * { u32 nr_build_ids;
> > > + *  u32 nr_offsets;
> > > + *  struct {
> > > + * u8 size;
> > > + * u8 data[size];
> > > + *  }[nr_build_ids];
> > > + *  u8 pad[];
> > > + *  u64 offsets[nr_offsets];
> > > + *  #
> > > + *  # Entries in offsets[] include PERF_CONTEXT_* markers (which
> > > + *  # have top 8 bits 0xff). Kernel/hypervisor entries (after
> > > + *  # PERF_CONTEXT_KERNEL, PERF_CONTEXT_HV, PERF_CONTEXT_GUEST,
> > > + *  # or PERF_CONTEXT_GUEST_KERNEL) and the cookie word following
> > > + *  # PERF_CONTEXT_USER_DEFERRED are raw 64-bit values. User
> > > + *  # entries (after PERF_CONTEXT_USER or PERF_CONTEXT_GUEST_USER,
> > > + *  # or in PERF_RECORD_CALLCHAIN_DEFERRED) use the top 8 bits to
> > > + *  # encode a 1-based index (1..254) into the build_ids table and
> > > + *  # the lower 56 bits for the DSO file offset, or 0x00 for an
> > > + *  # unresolved user virtual address.
> >
> > Hi Ian,
> >
> > On PERF_SAMPLE_BUILD_ID_OFFSET, the layout comment doesn't say what is
> > written in the non-resolved cases. For PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET
> > it is clear: kernel entries are raw 64-bit values, unresolved user entries
> > have 0x00 in the top byte, and resolved user entries carry the table index
> > and the 56-bit file offset.
> >
> > For the PERF_SAMPLE_BUILD_ID_OFFSET form, could the comment state:
> >
> >  - What is written for a kernel IP? (e.g. bid.size == 0 and offset == raw IP?)
> >  - What is written for an unresolved user IP? If bid.size == 0, does
> >    “offset” hold the raw virtual address?
> 
> Yes, in both non-user (e.g. kernel/hypervisor) and unresolved user IP
> cases, bid is zeroed (bid.size == 0) and offset holds the raw
> instruction pointer / virtual address. When attr.defer_callchain
> defers a user IP, the union carries zero == 0 (so bid.size == 0),
> context == PERF_CONTEXT_USER_DEFERRED, the stitching cookie, and the
> raw user IP.

Theoretically kernel IPs can have a build-ID as in /sys/kernel/notes.
But I don't know if we have a way to lookup module address ranges and
build-IDs easily.  Once that's available, it'd cover kernel IPs.

Thanks,
Namhyung


  parent reply	other threads:[~2026-11-25 21:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  7:43 [PATCH v3 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Ian Rogers
2026-11-16  7:43 ` [PATCH v3 01/19] perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler() Ian Rogers
2026-11-16  7:43 ` [PATCH v3 02/19] perf/uapi: Factor perf_build_id out into its own top-level struct Ian Rogers
2026-11-16  7:43 ` [PATCH v3 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI Ian Rogers
2026-11-24  0:52   ` Namhyung Kim
2026-11-24 19:53     ` Ian Rogers
2026-11-24 10:35   ` Athira Rajeev
2026-11-24 21:00     ` Ian Rogers
2026-11-25  4:34       ` Athira Rajeev
2026-11-25 21:59       ` Namhyung Kim [this message]
2026-11-16  7:43 ` [PATCH v3 04/19] bpf: Export stack_map_get_build_id_offset() for perf events Ian Rogers
2026-11-16  7:44 ` [PATCH v3 05/19] perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample types Ian Rogers
2026-11-24 17:32   ` Athira Rajeev
2026-11-24 21:29     ` Ian Rogers
2026-11-25  4:33       ` Athira Rajeev
2026-11-16  7:44 ` [PATCH v3 06/19] perf/core: Support deferred unwinding for BUILD_ID_OFFSET " Ian Rogers
2026-11-16  7:44 ` [PATCH v3 07/19] perf inject: Set ordered_events and ordering_requires_timestamps for --aslr Ian Rogers
2026-11-16  7:44 ` [PATCH v3 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples Ian Rogers
2026-11-16  7:44 ` [PATCH v3 09/19] perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample() Ian Rogers
2026-11-16  7:44 ` [PATCH v3 10/19] tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id Ian Rogers
2026-11-16  7:44 ` [PATCH v3 11/19] tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET Ian Rogers
2026-11-16  7:44 ` [PATCH v3 12/19] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-11-16  7:44 ` [PATCH v3 13/19] perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id() Ian Rogers
2026-11-16  7:44 ` [PATCH v3 14/19] perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types Ian Rogers
2026-11-16  7:44 ` [PATCH v3 15/19] perf symbol: Resolve symbols and callchains using build ID and offset Ian Rogers
2026-11-16  7:44 ` [PATCH v3 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset Ian Rogers
2026-11-16  7:44 ` [PATCH v3 17/19] perf record: Add --buildid-offset option Ian Rogers
2026-11-16  7:44 ` [PATCH v3 18/19] perf test: Add BUILD_ID_OFFSET C unit tests Ian Rogers
2026-11-16  7:44 ` [PATCH v3 19/19] perf test: Add inject --sample-buildids and record --buildid-offset shell tests Ian Rogers

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=awdaOldoL7p1Y_Sz@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=atrajeev@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dvyukov@google.com \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=leo.yan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@linux.dev \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sesse@google.com \
    --cc=song@kernel.org \
    --cc=stephen.s.brennan@oracle.com \
    --cc=thomas.falcon@intel.com \
    --cc=yonghong.song@linux.dev \
    /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®