Re: [PATCH v2 2/2] cpufreq: CPPC: Dont read counters for idle CPUs

From: Beata Michalska
Date: Thu Jul 03 2025 - 05:30:51 EST


Hi Prashant,
On Wed, Jul 02, 2025 at 11:38:11AM -0700, Prashant Malani wrote:
> Hi All,
>
> Ionela, Beata, could you kindly review ?
>
I've totally missed that - apologies for that. Will try to have a look within
next day or two.

---
BR
Beata
> On Fri, 27 Jun 2025 at 10:07, Prashant Malani <pmalani@xxxxxxxxxx> wrote:
> >
> > Hi Jie,
> >
> > On Fri, 27 Jun 2025 at 00:55, Jie Zhan <zhanjie9@xxxxxxxxxxxxx> wrote:
> > >
> > >
> > > Hi Prashant,
> > >
> > > Sorry for a late reply as I'm busy on other stuff and this doesn't seem to
> > > be an easy issue to solve.
> > >
> >
> > No worries, the ping was in general to all the people in the thread :)
> >
> > > For the latest kernel, [1] provides a new 'cpuinfo_avg_freq' sysfs file to
> > > reflect the frequency base on AMUs, which is supposed to be more stable.
> > > Though it usually shows 'Resource temporarily unavailable' on my platform
> > > at the moment and looks a bit buggy.
> > >
> > > Most of the related discussions can be found in the reference links in [1].
> > > [1] https://lore.kernel.org/linux-pm/20250131162439.3843071-1-beata.michalska@xxxxxxx/
> > >
> > > As reported, the current frequency sampling method may show an large error
> > > on 1) 100% load, 2) high memory access pressure, 3) idle cpus in your case.
> > >
> > > AFAICS, they may all come from the unstable latency accessing remote AMUs
> > > for 4 times but delaying a fixed 2us sampling window.
> >
> > I tried applying [1] which consolidates the ref and del register reads
> > into 1 IPI, but that did not make a difference. The values still
> > fluctuate wildly.
> >
> > >
> > > Increase the sampling windows seems to help but also increase the time
> > > overhead, so that's not favoured by people.
> > >
> >
> > This experiment did not appear to help in our case. It's a point in
> > the direction that this method is inherently inaccurate during idle
> > situations.
> >
> > > On 20/06/2025 13:07, Prashant Malani wrote:
> > > > Hi Jie,
> > > > On Thu, 19 Jun 2025 at 20:53, Jie Zhan <zhanjie9@xxxxxxxxxxxxx> wrote:
> > > >> On 19/06/2025 08:09, Prashant Malani wrote:
> > > >>> t0: ref=899127636, del=3012458473
> > > >>> t1: ref=899129626, del=3012466509
> > > >>> perf=40
> > > >>
> > > >> In this case, the target cpu is mostly idle but not fully idle during the
> > > >> sampling window since the counter grows a little bit.
> > > >> Perhaps some interrupts happen to run on the cpu shortly.
> > >
> > > Check back here again, I don't think it 'mostly idle'.
> > > Diff of ref counters is around 2000, and I guess the ref counter freq is
> > > 1GHz on your platform? That's exactly 2us, so the target cpu is mostly
> > > busy.
>
> I think it is pertinent to note: the actual act of reading the CPPC counters
> will (at least for ACPI_ADR_SPACE_FIXED_HARDWARE counters)
> wake the CPU up, so even if a CPU *was* idle, the reading of the counters
> calls cpc_read_ffh() [1] which does an IPI on the target CPU [2] thus waking
> it up from WFI.
>
> And that brings us back to the original assertion made in this patch:
> the counter values are quite unreliable when the CPU is in this
> idle (or rather I should correct that to, waking from WFI) state.
>
> This work around probably hits more types of implementations, but
> I can't see another way to limit it to only ARM FFH. Open to suggestions!
>
> [1] https://elixir.bootlin.com/linux/v6.15.4/source/arch/arm64/kernel/topology.c#L482
> [2] https://elixir.bootlin.com/linux/v6.15.4/source/arch/arm64/kernel/topology.c#L453
>
> Best regards,
>
> -Prashant
>
>
> --
> -Prashant