Re: [PATCH v4 1/5] perf: Record sample last_period before updating

From: Ingo Molnar
Date: Wed Apr 09 2025 - 07:41:31 EST



* mark.barnett@xxxxxxx <mark.barnett@xxxxxxx> wrote:

> From: Mark Barnett <mark.barnett@xxxxxxx>
>
> This change alters the PowerPC and x86 driver implementations to record
> the last sample period before the event is updated for the next period.
>
> A common pattern in PMU driver implementations is to have a
> "*_event_set_period" function which takes care of updating the various
> period-related fields in a perf_event structure. In most cases, the
> drivers choose to call this function after initializing a sample data
> structure with perf_sample_data_init. The x86 and PowerPC drivers
> deviate from this, choosing to update the period before initializing the
> sample data. When using an event with an alternate sample period, this
> causes an incorrect period to be written to the sample data that gets
> reported to userspace.
>
> Link: https://lore.kernel.org/r/20240515193610.2350456-4-yabinc@xxxxxxxxxx
> Signed-off-by: Mark Barnett <mark.barnett@xxxxxxx>
> ---
> arch/powerpc/perf/core-book3s.c | 3 ++-
> arch/powerpc/perf/core-fsl-emb.c | 3 ++-
> arch/x86/events/core.c | 4 +++-
> arch/x86/events/intel/core.c | 5 ++++-
> arch/x86/events/intel/knc.c | 4 +++-
> 5 files changed, 14 insertions(+), 5 deletions(-)

I've picked up this patch into tip:perf/core, because I think it makes
sense standalone as well.

Thanks,

Ingo