Re: [PATCH] perf/core: Use the elapsed period for frequency-mode period adjustment

From: Ingo Molnar

Date: Fri Nov 27 2026 - 04:40:53 EST



* Gregg Leventhal <gleventhal@xxxxxxxxxxxxxx> wrote:

> From: Jay Hilton <jahilton@xxxxxxxxxxxxxx>
>
> In frequency mode, __perf_event_account_interrupt() estimates the event
> rate from hwc->last_period and the time since the previous overflow,
> and passes it to perf_adjust_period().
>
> The PMU drivers re-arm the counter before they call
> perf_event_overflow(), and re-arming sets hwc->last_period to the
> period of the next interval. The estimator therefore divides the next
> period by the time the previous one took. While the period ramps up
> from its initial value, each period is much larger than the previous
> one, so the rate is overestimated by that ratio and the period
> overshoots its target.
>
> On an AMD EPYC 9655P running v7.3, sampling user-mode cycles at 11 Hz,
> the period jumped from 21.9M to 2.3G cycles, 5.6x the target, and the
> next sample arrived after 544 ms instead of 91 ms. When the overshoot
> exceeds 8x, the next tick's perf_adjust_period() resets period_left,
> and the cycles counted before the reset are not attributed to any
> sample (145M in that run). Intel and AMD IBS show the same overshoot.
> On Intel, intel_pmu_freq_start_period() hides it for the default
> hardware events, but not for raw events.
>
> Since commit 1734d98fbcce ("perf/arch: Record sample last_period before
> updating on the x86 and PowerPC platforms"), the PMU drivers record the
> elapsed period in data->period before re-arming. Pass that to the
> estimator instead of hwc->last_period. perf_event_account_interrupt(),
> which has no sample data, keeps using hwc->last_period.

Thank you - I've applied this fix to tip:perf/urgent for a v7.4 merge,
with a Cc: stable tag.

> The Intel PEBS error path runs before re-arming and
> is fine. We haven't measured the IBS discard case; if it's worth
> fixing, those callers could pass the elapsed period too, in a
> follow-up.

Yeah, I think it's worth fixing, even if the effect is minor.

Note that I merged your post-commit description with the commit
message, both are interesting & relevant.

Thanks,

Ingo