From: Christian Loehle <christian.loehle@arm.com>
To: Beata Michalska <beata.michalska@arm.com>,
linux-arm-kernel@lists.infradead.org
Cc: 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 v2 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling
Date: Thu, 12 Nov 2026 21:02:06 +0000 [thread overview]
Message-ID: <45c2bb0c-5b5f-4290-9265-ed02a2c241d4@arm.com> (raw)
In-Reply-To: <20261112191211.3336725-4-beata.michalska@arm.com>
On 11/12/26 19:12, 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
> one and can skew the result.
>
> Read both counters in succession if none is actually affected by HW
> errata.
>
> And while at it, update the comments to be more accurate (or less
> inaccurate).
>
> Signed-off-by: Beata Michalska <beata.michalska@arm.com>
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
Testing this via the sysfs cpuinfo_cur_freq on orion o6 A520 (not
affected, both counters work) I get a p99 sampling error of:
Reader / target workload Before Patch
-------------------------------------------------------------
Remote big CPU / idle 11.11 0.17
Remote big CPU / busy 2.22 0.22
Another little CPU / busy 2.06 0.22
Local / busy 13.56 1.17
Nice!
Tested-by: Christian Loehle <christian.loehle@arm.com>
> ---
> arch/arm64/kernel/topology.c | 38 ++++++++++++++++++++++--------------
> 1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index 30a52659f15c..d00aec6354e4 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -384,10 +384,10 @@ enum cpc_ffh_ctr_id {
> static 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.
> + * Return 0 if the current CPU is affected by a HW erratum.
> + * Otherwise, return the AMU counter value.
> + *
> + * A counter value of 0 is treated as an error by callers.
> */
> *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT) ?
> 0UL : read_corecnt();
> @@ -397,10 +397,9 @@ static void cpu_read_constcnt(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.
> + * Otherwise, return the AMU counter value.
> + *
> + * A counter value of 0 is treated as an error by callers.
> */
> *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT) ?
> 0UL : read_constcnt();
> @@ -460,15 +459,24 @@ bool cpc_ffh_supported(void)
> static void amu_read_core_const_ctrs(void *val)
> {
> struct amu_ffh_ctrs *ctrs = val;
> -
> + bool corecntr_broken =
> + this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT);
> + bool constcntr_broken =
> + this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT);
> +
> + if (!corecntr_broken && !constcntr_broken) {
> + ctrs->corecnt = read_corecnt();
> + ctrs->constcnt = read_constcnt();
> + return;
> + }
> /*
> - * 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.
> + * Otherwise, return the AMU counter value.
> + *
> + * A counter value of 0 is treated as an error by callers.
> */
> - cpu_read_constcnt(&ctrs->constcnt);
> - cpu_read_corecnt(&ctrs->corecnt);
> + ctrs->corecnt = corecntr_broken ? 0UL : read_corecnt();
> + ctrs->constcnt = constcntr_broken ? 0UL : read_constcnt();
> }
>
> static bool cpc_ffh_reg_valid(const struct cpc_reg *reg)
next prev parent reply other threads:[~2026-11-12 21:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 19:12 [PATCH v2 0/3] arm64: errata: Update AMU workarounds Beata Michalska
2026-11-12 19:12 ` [PATCH v2 1/3] arm64: errata: Extend the workaround for broken AMEVCNTR01 counter Beata Michalska
2026-11-12 19:12 ` [PATCH v2 2/3] arm64: errata: Add Cortex-A715/A720 AMU core counter workaround Beata Michalska
2026-11-12 19:12 ` [PATCH v2 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling Beata Michalska
2026-11-12 21:02 ` Christian Loehle [this message]
2026-11-12 19:50 ` (subset) [PATCH v2 0/3] arm64: errata: Update AMU workarounds Catalin Marinas
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=45c2bb0c-5b5f-4290-9265-ed02a2c241d4@arm.com \
--to=christian.loehle@arm.com \
--cc=Vladimir.Murzin@arm.com \
--cc=beata.michalska@arm.com \
--cc=catalin.marinas@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®