Re: [PATCH] x86/aperfmperf: Don't disable scheduler APERF/MPERF on bad samples
From: Andi Kleen
Date: Thu Dec 04 2025 - 16:16:39 EST
On Thu, Dec 04, 2025 at 08:02:09PM +0000, Andrew Cooper wrote:
> > However this can happen without any malfunction when there is
> > a long enough interruption between the two MSR reads, for
> > example due to an unlucky NMI or SMI or other system event
> > causing delays.
>
> The list of problems is even longer under virt. The vCPU can lose it's
> timeslice (-> arbitrary delay), or be scheduled onto a different CPU
> between the A and M reads (-> calculate the wrong ratio, and not in a
> way you could exclude it as a bad sample).
You could avoid that in the hypervisor by saving/restoring the counts (the
MSRs are writable), but it's likely rare and harmless enough that
it's not worth the performance overhead.
-Andi