From: Andi Kleen <ak@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
ggherdovich@suse.cz, rafael.j.wysocki@intel.com
Subject: Re: [PATCH] x86/aperfmperf: Don't disable scheduler APERF/MPERF on bad samples
Date: Sun, 7 Dec 2025 12:38:20 -0800 [thread overview]
Message-ID: <aTXlvIhWd6RkWhyY@tassilo> (raw)
In-Reply-To: <20251205161052.GH2528459@noisy.programming.kicks-ass.net>
On Fri, Dec 05, 2025 at 05:10:52PM +0100, Peter Zijlstra wrote:
> On Thu, Dec 04, 2025 at 10:09:14AM -0800, Andi Kleen wrote:
> > The APERF and MPERF MSRs get read together and the ratio
> > between the two is used to scale the scheduler capacity with frequency.
> >
> > Since e2b0d619b400 when there is ever an over/underflow of
> > the APERF/MPERF computation the sampling gets completely
> > disabled, under the assumption that there is a problem with
> > the hardware.
> >
> > 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. We saw it when a delay resulted in
> > Acnt_Delta << Mcnt_Delta (about ~4k for acnt_delta and
> > 2M for MCnt_Delta)
> >
> > In this case the ratio computation underflows, which is detected,
> > but then APERF/MPERF usage gets incorrectly disabled forever.
> >
> > Remove the code to completely disable APERF/MPERF on
> > a bad sample. Instead when any over/underflow happens
> > return the fallback full capacity.
>
> So what systems are actually showing this bad behaviour and what are we
> doing to cure the problem rather than fight the symptom?
We saw it with an artificial stress test on an Intel internal system,
but like I (and Andrew) explained it is unavoidable and general:
Delays can always happen due to many reasons on any system: NMIs, SMIs,
virtualization, other random system issues.
> Also, a system where this is systematically buggered would really be
> better off disabling it, no?
The particular failure case here if it was common (lots of very long
execution delays) would make the system fairly unusable anyways.
The scheduler doing a slightly worse job is the least of your troubles
in such a case.
For other failures I'm not aware of a system (perhaps short of a
hypervisor that doesn't save/restore when switching underlying cpus)
that actually has broken APERF/MPERF. So breaking good systems
just for a hypothetical bad case doesn't seem like a good trade off.
The main difference to the old strategy is that if there is a really
bad case but it results in bad samples that don't under/overflow
they would still be used, while the old one would stop on any
bad sample.But any attempt to handle this without impacting
good cases would either need complexity or magic threshold numbers.
So it seems better to not even try.
-Andi
prev parent reply other threads:[~2025-12-07 20:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 18:09 [PATCH] x86/aperfmperf: Don't disable scheduler APERF/MPERF on bad samples Andi Kleen
2025-12-04 20:02 ` Andrew Cooper
2025-12-04 21:16 ` Andi Kleen
2025-12-04 22:37 ` kernel test robot
2025-12-05 16:10 ` Peter Zijlstra
2025-12-07 20:38 ` Andi Kleen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aTXlvIhWd6RkWhyY@tassilo \
--to=ak@linux.intel.com \
--cc=ggherdovich@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox