Re: [PATCH v1] perf/core: Replace perf_event_header__init_id with full header init
From: Peter Zijlstra
Date: Thu Oct 01 2026 - 03:08:39 EST
On Tue, Sep 29, 2026 at 03:23:32PM -0700, Ian Rogers wrote:
> Rather than splitting header initialization between callers and output
> callbacks and saving/restoring mutated header fields, replace
> perf_event_header__init_id() with
> perf_event_header__init_header_and_id(), which initializes header->type,
> header->misc, and header->size alongside the sample_id fields on each
> invocation.
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 33210aff3ee6..c1b2d0c9b2af 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8119,13 +8119,18 @@ static void __perf_event_header__init_id(struct perf_sample_data *data,
> }
> }
>
> -void perf_event_header__init_id(struct perf_event_header *header,
> - struct perf_sample_data *data,
> - struct perf_event *event)
> +void perf_event_header__init_header_and_id(struct perf_event_header *header,
> + struct perf_sample_data *data,
> + u32 type, u16 misc, u16 size,
> + struct perf_event *event)
> {
> + header->type = type;
> + header->misc = misc;
> if (event->attr.sample_id_all) {
> - header->size += event->id_header_size;
> + header->size = size + event->id_header_size;
> __perf_event_header__init_id(data, event, event->attr.sample_type);
> + } else {
> + header->size = size;
> }
> }
I've renamed the thing to perf_event_header__init(). Also, I've done:
header->size = size;
and restored the:
header->size += event->id_header_size;
and lost the else :-)
But yes, this is better. Thanks!