* [PATCH v2 0/3] arm64: errata: Update AMU workarounds
@ 2026-11-12 19:12 Beata Michalska
2026-11-12 19:12 ` [PATCH v2 1/3] arm64: errata: Extend the workaround for broken AMEVCNTR01 counter Beata Michalska
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Beata Michalska @ 2026-11-12 19:12 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Vladimir.Murzin, catalin.marinas, will, christian.loehle,
suzuki.poulose, xuewen.yan94, linux-kernel
Hi All,
This short series updates errata for AMU core & const counters.
The last patch in the series tries to optimize a bit the paired
readings of both counters, so that the workaround checks do not
skew the results. It is also intentionally the last one, as it
will not apply on older stable kernels.
---
v2:
- Reorganised the amu_read_core_const_ctrs as suggested by Chris
- Rephrased the comments to be more accurate
Beata Michalska (3):
arm64: errata: Extend the workaround for broken AMEVCNTR01 counter
arm64: errata: Add Cortex-A715/A720 AMU core counter workaround
arm64: topology: Reduce the skew for AMU feedback counter sampling
Documentation/arch/arm64/silicon-errata.rst | 12 ++++++
arch/arm64/Kconfig | 44 +++++++++++++++++++--
arch/arm64/kernel/cpu_errata.c | 29 ++++++++++++++
arch/arm64/kernel/cpufeature.c | 3 +-
arch/arm64/kernel/topology.c | 43 ++++++++++++--------
arch/arm64/tools/cpucaps | 1 +
6 files changed, 111 insertions(+), 21 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] arm64: errata: Extend the workaround for broken AMEVCNTR01 counter
2026-11-12 19:12 [PATCH v2 0/3] arm64: errata: Update AMU workarounds Beata Michalska
@ 2026-11-12 19:12 ` Beata Michalska
2026-11-12 19:12 ` [PATCH v2 2/3] arm64: errata: Add Cortex-A715/A720 AMU core counter workaround Beata Michalska
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Beata Michalska @ 2026-11-12 19:12 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Vladimir.Murzin, catalin.marinas, will, christian.loehle,
suzuki.poulose, xuewen.yan94, linux-kernel
The erratum causing significant inaccuracies in the AMU CNT_CYCLES
counter due to WFI/WFE has been identified in additional
microarchitectures.
Extend the existing workaround to cover these implementations,
which are affected by the following errata:
- ARM Cortex-A725 erratum 3821522 (SDEN-2832921)
- ARM Cortex-A720 erratum 4689339 (SDEN-2439421)
- ARM Cortex-A720AE erratum 4689340 (SDEN-3090091)
- ARM Neoverse N3 erratum 4689341 (SDEN-3050973)
- ARM C1-Pro erratum 4689344 (SDEN-3273080)
Cc: stable@vger.kernel.org
Signed-off-by: Beata Michalska <beata.michalska@arm.com>
---
Documentation/arch/arm64/silicon-errata.rst | 8 ++++++++
arch/arm64/Kconfig | 12 +++++++++---
arch/arm64/kernel/cpu_errata.c | 9 +++++++++
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Documentation/arch/arm64/silicon-errata.rst b/Documentation/arch/arm64/silicon-errata.rst
index afe109afe692..09fe032e1aea 100644
--- a/Documentation/arch/arm64/silicon-errata.rst
+++ b/Documentation/arch/arm64/silicon-errata.rst
@@ -175,6 +175,10 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A720 | #3456091 | ARM64_ERRATUM_3194386 |
+----------------+-----------------+-----------------+-----------------------------+
+| ARM | Cortex-A720 | #4689339 | ARM64_ERRATUM_3821522 |
++----------------+-----------------+-----------------+-----------------------------+
+| ARM | Cortex-A720AE | #4689340 | ARM64_ERRATUM_3821522 |
++----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A725 | #3456106 | ARM64_ERRATUM_3194386 |
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A725 | #3821522 | ARM64_ERRATUM_3821522 |
@@ -233,6 +237,8 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Neoverse-N3 | #3456111 | ARM64_ERRATUM_3194386 |
+----------------+-----------------+-----------------+-----------------------------+
+| ARM | Neoverse-N3 | #4689341 | ARM64_ERRATUM_3821522 |
++----------------+-----------------+-----------------+-----------------------------+
| ARM | Neoverse-V1 | #1619801 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Neoverse-V1 | #3324341 | ARM64_ERRATUM_3194386 |
@@ -257,6 +263,8 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| ARM | C1-Pro | #4193714 | ARM64_ERRATUM_4193714 |
+----------------+-----------------+-----------------+-----------------------------+
+| ARM | C1-Pro | #4689344 | ARM64_ERRATUM_3821522 |
++----------------+-----------------+-----------------+-----------------------------+
| ARM | C1-Ultra | #3683289 | N/A |
+----------------+-----------------+-----------------+-----------------------------+
| ARM | C1-Ultra | #4193780 | ARM64_ERRATUM_4118414 |
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 1075bc661833..cf50f3051edc 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1086,14 +1086,20 @@ config ARM64_ERRATUM_2645198
If unsure, say Y.
config ARM64_ERRATUM_3821522
- bool "Cortex-A725: 3821522: workaround for possible CNT_CYCLES increment error due to WFE/WFI"
+ bool "Cortex-*/Neoverse-*/C1-*: workaround for possible CNT_CYCLES increment error due to WFE/WFI"
depends on ARM64_AMU_EXTN
select ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
default y
help
- This option adds the workaround for ARM Cortex-A725 erratum 3821522.
+ This option adds the workaround for the following errata:
+
+ * ARM Cortex-A725 erratum 3821522
+ * ARM Cortex-A720 erratum 4689339
+ * ARM Cortex-A720AE erratum 4689340
+ * ARM Neoverse N3 erratum 4689341
+ * ARM C1-Pro erratum 4689344
- On affected A725 cores, the CNT_CYCLES event may incur a significant
+ On affected cores, the CNT_CYCLES event may incur a significant
increment error when entering and subsequently exiting WFx.
As a result, the CNT_CYCLES may diverge from the system counter
frequency at which it is expected to increment.
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 38abd123c740..b20da8b24be3 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -420,8 +420,17 @@ static const struct midr_range workaround_amu_constcnt_list[] = {
MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1),
#endif
#ifdef CONFIG_ARM64_ERRATUM_3821522
+ /* Cortex-A720 r0p0 - r0p2 */
+ MIDR_RANGE(MIDR_CORTEX_A720, 0, 0, 0, 2),
+ /* Cortex-A720AE r0p0 - r0p1 */
+ MIDR_RANGE(MIDR_CORTEX_A720AE, 0, 0, 0, 1),
/* Cortex-A725 r0p0 - r0p2 */
MIDR_RANGE(MIDR_CORTEX_A725, 0, 0, 0, 2),
+ /* Neoverse N3 r0p0 - r0p1 */
+ MIDR_RANGE(MIDR_NEOVERSE_N3, 0, 0, 0, 1),
+ /* C1-Pro r0p0 - r1p3 */
+ MIDR_RANGE(MIDR_C1_PRO, 0, 0, 1, 3),
+
#endif
{}
};
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] arm64: errata: Add Cortex-A715/A720 AMU core counter workaround
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 ` 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 19:50 ` (subset) [PATCH v2 0/3] arm64: errata: Update AMU workarounds Catalin Marinas
3 siblings, 0 replies; 6+ messages in thread
From: Beata Michalska @ 2026-11-12 19:12 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Vladimir.Murzin, catalin.marinas, will, christian.loehle,
suzuki.poulose, xuewen.yan94, linux-kernel
On Cortex-A715 (erratum 2738462) and Cortex-A720 (erratum 2738461),
the AMEVCNTR00 counter may continue incrementing while the core
remains in WFE with the clocks being enabled. The resulting core
cycle count may become unreliable.
Add a workaround that effectively treats the AMU counter
as unavailable.
Cc: stable@vger.kernel.org
Signed-off-by: Beata Michalska <beata.michalska@arm.com>
---
Documentation/arch/arm64/silicon-errata.rst | 4 +++
arch/arm64/Kconfig | 32 +++++++++++++++++++++
arch/arm64/kernel/cpu_errata.c | 20 +++++++++++++
arch/arm64/kernel/cpufeature.c | 3 +-
arch/arm64/kernel/topology.c | 3 +-
arch/arm64/tools/cpucaps | 1 +
6 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/Documentation/arch/arm64/silicon-errata.rst b/Documentation/arch/arm64/silicon-errata.rst
index 09fe032e1aea..5801597a387c 100644
--- a/Documentation/arch/arm64/silicon-errata.rst
+++ b/Documentation/arch/arm64/silicon-errata.rst
@@ -171,8 +171,12 @@ stable kernels.
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A715 | #2645198 | ARM64_ERRATUM_2645198 |
+----------------+-----------------+-----------------+-----------------------------+
+| ARM | Cortex-A715 | #2738462 | ARM64_ERRATUM_2738461 |
++----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A715 | #3456084 | ARM64_ERRATUM_3194386 |
+----------------+-----------------+-----------------+-----------------------------+
+| ARM | Cortex-A720 | #2738461 | ARM64_ERRATUM_2738461 |
++----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A720 | #3456091 | ARM64_ERRATUM_3194386 |
+----------------+-----------------+-----------------+-----------------------------+
| ARM | Cortex-A720 | #4689339 | ARM64_ERRATUM_3821522 |
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index cf50f3051edc..afc6226689be 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1051,6 +1051,38 @@ config ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT
# making it unreliable. As a result, AMU users should treat it as
# unavailable rather than relying on misleading counter values.
+config ARM64_WORKAROUND_BROKEN_AMU_CORECNT
+ bool
+ # Targeting errata affecting AMEVCNTR00, the AMU core cycle counter.
+ # On affected CPUs the counter may continue incrementing while core
+ # remains in WFE with the clocks enabled.
+ # This may lead to readings of said counter being unreliable.
+ # How much though depends on the sampling intervals.
+
+config ARM64_ERRATUM_2738461
+ bool "Cortex-A715/Cortex-A720: workaround for AMEVCNTR00 incrementing incorrectly"
+ depends on ARM64_AMU_EXTN
+ select ARM64_WORKAROUND_BROKEN_AMU_CORECNT
+ default y
+ help
+ This option adds the workaround for the following errata:
+
+ * ARM Cortex-A715 erratum 2738462
+ * ARM Cortex-A720 erratum 2738461
+
+ On affected cores the AMEVCNTR00 counter (AMU core frequency cycles
+ counter) may continue incrementing while the core remains in WFE
+ with the clocks being enabled.
+ This may result in inaccurate counter readings, with the magnitude
+ of the discrepancy depending on the sampling interval.
+
+ With this workaround, reads of the affected counter return 0 in
+ the relevant paths. This causes users of the counter to treat it
+ as unavailable and is functionally equivalent to firmware disabling
+ the affected counter.
+
+ If unsure, say Y.
+
config ARM64_ERRATUM_2457168
bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly"
depends on ARM64_AMU_EXTN
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index b20da8b24be3..957917cfab70 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -436,6 +436,18 @@ static const struct midr_range workaround_amu_constcnt_list[] = {
};
#endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT */
+#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT
+static const struct midr_range workaround_amu_corecnt_list[] = {
+#ifdef CONFIG_ARM64_ERRATUM_2738461
+ /* Cortex-A715 r0p0 - r1p3 */
+ MIDR_RANGE(MIDR_CORTEX_A715, 0, 0, 1, 3),
+ /* Cortex-A720 r0p0 - r0p1 */
+ MIDR_RANGE(MIDR_CORTEX_A720, 0, 0, 0, 1),
+#endif
+ {}
+};
+#endif /* CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT */
+
#ifdef CONFIG_CAVIUM_ERRATUM_23154
static const struct midr_range cavium_erratum_23154_cpus[] = {
MIDR_ALL_VERSIONS(MIDR_THUNDERX),
@@ -979,6 +991,14 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
CAP_MIDR_RANGE_LIST(workaround_amu_constcnt_list)
},
#endif
+#ifdef CONFIG_ARM64_WORKAROUND_BROKEN_AMU_CORECNT
+ {
+ .desc = "Broken AMU AMEVCNTR00 (core cycle counter)",
+ .capability = ARM64_WORKAROUND_BROKEN_AMU_CORECNT,
+ .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
+ CAP_MIDR_RANGE_LIST(workaround_amu_corecnt_list)
+ },
+#endif
#ifdef CONFIG_ARM64_ERRATUM_2038923
{
.desc = "ARM erratum 2038923",
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
index 34c5c03c0c9b..0e8a9aedb84b 100644
--- a/arch/arm64/kernel/cpufeature.c
+++ b/arch/arm64/kernel/cpufeature.c
@@ -1938,7 +1938,8 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap)
cpumask_set_cpu(smp_processor_id(), &amu_cpus);
/* 0 reference values signal broken/disabled counters */
- if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT))
+ if (!this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CONSTCNT)
+ && !this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT))
update_freq_counters_refs();
}
}
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 44305b997a02..30a52659f15c 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -389,7 +389,8 @@ static void cpu_read_corecnt(void *val)
* counter read is properly handled as an error case by the users of the
* counter.
*/
- *(u64 *)val = read_corecnt();
+ *(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_BROKEN_AMU_CORECNT) ?
+ 0UL : read_corecnt();
}
static void cpu_read_constcnt(void *val)
diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps
index 20cc185649f9..3125695122a0 100644
--- a/arch/arm64/tools/cpucaps
+++ b/arch/arm64/tools/cpucaps
@@ -133,3 +133,4 @@ WORKAROUND_SPECULATIVE_AT
WORKAROUND_SPECULATIVE_SSBS
WORKAROUND_SPECULATIVE_UNPRIV_LOAD
WORKAROUND_BROKEN_AMU_CONSTCNT
+WORKAROUND_BROKEN_AMU_CORECNT
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling
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 ` Beata Michalska
2026-11-12 21:02 ` Christian Loehle
2026-11-12 19:50 ` (subset) [PATCH v2 0/3] arm64: errata: Update AMU workarounds Catalin Marinas
3 siblings, 1 reply; 6+ messages in thread
From: Beata Michalska @ 2026-11-12 19:12 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Vladimir.Murzin, catalin.marinas, will, christian.loehle,
suzuki.poulose, xuewen.yan94, linux-kernel
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>
---
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)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: (subset) [PATCH v2 0/3] arm64: errata: Update AMU workarounds
2026-11-12 19:12 [PATCH v2 0/3] arm64: errata: Update AMU workarounds Beata Michalska
` (2 preceding siblings ...)
2026-11-12 19:12 ` [PATCH v2 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling Beata Michalska
@ 2026-11-12 19:50 ` Catalin Marinas
3 siblings, 0 replies; 6+ messages in thread
From: Catalin Marinas @ 2026-11-12 19:50 UTC (permalink / raw)
To: linux-arm-kernel, Beata Michalska
Cc: Will Deacon, Vladimir.Murzin, christian.loehle, suzuki.poulose,
xuewen.yan94, linux-kernel
On Thu, 12 Nov 2026 20:12:06 +0100, Beata Michalska wrote:
> This short series updates errata for AMU core & const counters.
> The last patch in the series tries to optimize a bit the paired
> readings of both counters, so that the workaround checks do not
> skew the results. It is also intentionally the last one, as it
> will not apply on older stable kernels.
Applied to arm64 (for-next/fixes), thanks!
[1/3] arm64: errata: Extend the workaround for broken AMEVCNTR01 counter
https://git.kernel.org/arm64/c/139a9b7d5a07
[2/3] arm64: errata: Add Cortex-A715/A720 AMU core counter workaround
https://git.kernel.org/arm64/c/be7771458582
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 3/3] arm64: topology: Reduce the skew for AMU feedback counter sampling
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
0 siblings, 0 replies; 6+ messages in thread
From: Christian Loehle @ 2026-11-12 21:02 UTC (permalink / raw)
To: Beata Michalska, linux-arm-kernel
Cc: Vladimir.Murzin, catalin.marinas, will, suzuki.poulose,
xuewen.yan94, linux-kernel
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)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-12 21:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2026-11-12 19:50 ` (subset) [PATCH v2 0/3] arm64: errata: Update AMU workarounds Catalin Marinas
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®