From: Beata Michalska <beata.michalska@arm.com>
To: Christian Loehle <christian.loehle@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, Vladimir.Murzin@arm.com,
catalin.marinas@arm.com, will@kernel.org, suzuki.poulose@arm.com,
xuewen.yan94@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling
Date: Wed, 11 Nov 2026 19:42:16 +0100 [thread overview]
Message-ID: <avS3CJI82z3xDQQT@arm.com> (raw)
In-Reply-To: <1493f335-a808-471f-932a-393aaa390d25@arm.com>
On Wed, Nov 11, 2026 at 02:08:11PM +0000, Christian Loehle wrote:
> On 11/11/26 12:39, Beata Michalska wrote:
> > With the FFH support for CPPC, the AMU feedback counters, core and const
> > counter, are being sampled to measure CPU performance. Checking for errata
> > (which can affect both counters) between the reads delays the second
> > sample and can skew the result.
> >
> > Take both samples in succession, then discard values from affected
> > counters. This narrows the sampling interval used for CPPC feedback.
> >
> > Signed-off-by: Beata Michalska <beata.michalska@arm.com>
> > ---
> > arch/arm64/kernel/topology.c | 76 +++++++++++++++++++++++-------------
> > 1 file changed, 49 insertions(+), 27 deletions(-)
> >
> > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> > index 66ac67bd025e..c968fa5b0c88 100644
> > --- a/arch/arm64/kernel/topology.c
> > +++ b/arch/arm64/kernel/topology.c
> > @@ -381,29 +381,45 @@ enum cpc_ffh_ctr_id {
> > CPC_FFH_CTR_CONST = 0x1,
> > };
> >
> > -static void cpu_read_corecnt(void *val)
> > +static inline void cpu_read_corecnt(void *val)
> > {
> > - /*
> > - * A value of 0 can be returned if the current CPU does not support AMUs
> > - * or if the counter is disabled for this CPU. A return value of 0 at
> > - * counter read is properly handled as an error case by the users of the
> > - * counter.
> > - */
> > - *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT) ?
> > - 0UL : read_corecnt();
> > + *(u64 *)val = read_corecnt();
> > }
> >
> > -static void cpu_read_constcnt(void *val)
> > +static void cpu_try_read_corecnt(void *val)
> > {
> > - /*
> > - * Return 0 if the current CPU is affected by a HW erratum.
> > - * A value of 0 is also returned if the current CPU does not
> > - * support AMUs or if the counter is disabled. A return
> > - * value of 0 at counter read is properly handled as an error
> > - * case by the users of the counter.
>
> Since you're moving this comment around, AFAICT it's not actually true?
> cpu_has_amu_feat() is checked (which will return -EOPNOTSUPP) before
> landing here, right?
>
Not entirely, no.
`cpu_has_amu_feat()` verifies the support for AMUs, the extension itself
(ID_AA64PFR0_EL1). Workarounds are applied on top of it.
---
BR
Beata
>
> > - */
> > - *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT) ?
> > - 0UL : read_constcnt();
> > + if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT)) {
> > + cpu_read_corecnt(val);
> > + } else {
> > + /*
> > + * A value of 0 can be returned if the current CPU does not support AMUs
> > + * or if the counter is disabled for this CPU. A return value of 0 at
> > + * counter read is properly handled as an error case by the users of the
> > + * counter.
> > + */
> > + *(u64 *)val = 0UL;
> > + }
> > +}
> > +
> > +static inline void cpu_read_constcnt(void *val)
> > +{
> > + *(u64 *)val = read_constcnt();
> > +}
> > +
> > +static void cpu_try_read_constcnt(void *val)
> > +{
> > + if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT)) {
> > + cpu_read_constcnt(val);
> > + } else {
> > + /*
> > + * Return 0 if the current CPU is affected by a HW erratum.
> > + * A value of 0 is also returned if the current CPU does not
> > + * support AMUs or if the counter is disabled. A return
> > + * value of 0 at counter read is properly handled as an error
> > + * case by the users of the counter.
> > + */
> > + *(u64 *)val = 0UL;
> > + }
> > }
> >
> > static inline
> > @@ -461,14 +477,20 @@ static void amu_read_core_const_ctrs(void *val)
> > {
> > struct amu_ffh_ctrs *ctrs = val;
> >
> > + cpu_read_corecnt(&ctrs->corecnt);
> > + cpu_read_constcnt(&ctrs->constcnt);
> > +
> > /*
> > - * cpu_read_constcnt() incurs slight latency due to the
> > - * ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT check.
> > - * Read it first to minimize the sampling skew between the const
> > - * and core counters.
> > + * Return 0 if the current CPU is affected by a HW erratum.
> > + * A value of 0 is also returned if the current CPU does not
> > + * support AMUs or if the counter is disabled. A return
> > + * value of 0 at counter read is properly handled as an error
> > + * case by the users of the counter.
> > */
> > - cpu_read_constcnt(&ctrs->constcnt);
> > - cpu_read_corecnt(&ctrs->corecnt);
> > + if (this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT))
> > + ctrs->corecnt = 0UL;
> > + if (this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT))
> > + ctrs->constcnt = 0UL;
> > }
> >
> > static bool cpc_ffh_reg_valid(const struct cpc_reg *reg)
> > @@ -543,10 +565,10 @@ int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)
> >
> > switch ((u64)reg->address) {
> > case CPC_FFH_CTR_CORE:
> > - ret = counters_read_on_cpu(cpu, cpu_read_corecnt, val);
> > + ret = counters_read_on_cpu(cpu, cpu_try_read_corecnt, val);
> > break;
> > case CPC_FFH_CTR_CONST:
> > - ret = counters_read_on_cpu(cpu, cpu_read_constcnt, val);
> > + ret = counters_read_on_cpu(cpu, cpu_try_read_constcnt, val);
> > break;
> > }
> >
>
prev parent reply other threads:[~2026-11-11 18:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:39 [PATCH 0/3] arm64: errata: Update AMU workarounds Beata Michalska
2026-11-11 12:39 ` [PATCH 1/3] arm64: errata: Extend the workaround for broken AMEVCNTR01 counter Beata Michalska
2026-11-11 12:39 ` [PATCH 2/3] arm64: errata: Add Cortex-A715/A720 AMU core counter workaround Beata Michalska
2026-11-11 12:39 ` [PATCH 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling Beata Michalska
2026-11-11 13:56 ` Christian Loehle
2026-11-11 18:38 ` Beata Michalska
2026-11-11 14:08 ` Christian Loehle
2026-11-11 18:42 ` Beata Michalska [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=avS3CJI82z3xDQQT@arm.com \
--to=beata.michalska@arm.com \
--cc=Vladimir.Murzin@arm.com \
--cc=catalin.marinas@arm.com \
--cc=christian.loehle@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=xuewen.yan94@gmail.com \
/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
all inboxes | Powered by JetHome®