Re: [PATCH v4 3/7] alpha/perf: clear PERF_HES_UPTODATE when an event starts counting

From: Magnus Lindholm

Date: Tue Nov 03 2026 - 02:47:07 EST


Hi Matt,

On Tue, Nov 3, 2026 at 4:02 AM Matt Turner <mattst88@xxxxxxxxx> wrote:
>
> alpha_pmu_add() sets PERF_HES_UPTODATE and maybe_change_configuration()
> then programs and enables the counter, but nothing clears the flag until
> the first alpha_pmu_start(). In that window alpha_pmu_stop() with
> PERF_EF_UPDATE skips the count update, because the flag claims the count
> is current. Since the next reload rewrites the counter, everything
> counted since the event was added is lost.
>
> perf_adjust_freq_unthr_events() does this on the first tick
> after an event in frequency mode is scheduled in, which is the default
> for perf record, and it then sees no count to adjust the period with.
>
> Clear the flag where the event starts counting. alpha_pmu_add() cannot
> do it, since the event is not programmed until the PMU is enabled, and
> stopping it before then must not read the counter.
>
> Fixes: a4eaf7f14675 ("perf: Rework the PMU methods")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
> ---
> arch/alpha/kernel/perf_event.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
> index 70840c05d39b..ecec78c355cd 100644
> --- a/arch/alpha/kernel/perf_event.c
> +++ b/arch/alpha/kernel/perf_event.c
> @@ -456,8 +456,11 @@ static void maybe_change_configuration(struct cpu_hw_events *cpuc)
> cpuc->current_idx[j] = idx;
> }
>
> - if (!(hwc->state & PERF_HES_STOPPED))
> + if (!(hwc->state & PERF_HES_STOPPED)) {
> + /* The counter is live, so hwc->prev_count will go stale. */
> + hwc->state &= ~PERF_HES_UPTODATE;
> cpuc->idx_mask |= (1<<cpuc->current_idx[j]);
> + }
> }
> cpuc->config = cpuc->event[0]->hw.config_base;
> }
>
> --
> 2.55.0
>

Tested on my AlphaServer ES40. On all three CPUs, the cycle count
included the work done before the first stop and reload. Frequency-mode
sampling also passed.

Reviewed-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Tested-by: Magnus Lindholm <linmag7@xxxxxxxxx>