Skip to content

Commit e89d120

Browse files
ionela-voinescuwilldeacon
authored andcommitted
arm64: errata: add detection for AMEVCNTR01 incrementing incorrectly
The AMU counter AMEVCNTR01 (constant counter) should increment at the same rate as the system counter. On affected Cortex-A510 cores, AMEVCNTR01 increments incorrectly giving a significantly higher output value. This results in inaccurate task scheduler utilization tracking and incorrect feedback on CPU frequency. Work around this problem by returning 0 when reading the affected counter in key locations that results in disabling all users of this counter from using it either for frequency invariance or as FFH reference counter. This effect is the same to firmware disabling affected counters. Details on how the two features are affected by this erratum: - AMU counters will not be used for frequency invariance for affected CPUs and CPUs in the same cpufreq policy. AMUs can still be used for frequency invariance for unaffected CPUs in the system. Although unlikely, if no alternative method can be found to support frequency invariance for affected CPUs (cpufreq based or solution based on platform counters) frequency invariance will be disabled. Please check the chapter on frequency invariance at Documentation/scheduler/sched-capacity.rst for details of its effect. - Given that FFH can be used to fetch either the core or constant counter values, restrictions are lifted regarding any of these counters returning a valid (!0) value. Therefore FFH is considered supported if there is a least one CPU that support AMUs, independent of any counters being disabled or affected by this erratum. Clarifying comments are now added to the cpc_ffh_supported(), cpu_read_constcnt() and cpu_read_corecnt() functions. The above is achieved through adding a new erratum: ARM64_ERRATUM_2457168. Signed-off-by: Ionela Voinescu <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Morse <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 2e8cff0 commit e89d120

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

Documentation/arm64/silicon-errata.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ stable kernels.
5252
| Allwinner | A64/R18 | UNKNOWN1 | SUN50I_ERRATUM_UNKNOWN1 |
5353
+----------------+-----------------+-----------------+-----------------------------+
5454
+----------------+-----------------+-----------------+-----------------------------+
55+
| ARM | Cortex-A510 | #2457168 | ARM64_ERRATUM_2457168 |
56+
+----------------+-----------------+-----------------+-----------------------------+
5557
| ARM | Cortex-A510 | #2064142 | ARM64_ERRATUM_2064142 |
5658
+----------------+-----------------+-----------------+-----------------------------+
5759
| ARM | Cortex-A510 | #2038923 | ARM64_ERRATUM_2038923 |

arch/arm64/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,23 @@ config ARM64_ERRATUM_1902691
917917

918918
If unsure, say Y.
919919

920+
config ARM64_ERRATUM_2457168
921+
bool "Cortex-A510: 2457168: workaround for AMEVCNTR01 incrementing incorrectly"
922+
depends on ARM64_AMU_EXTN
923+
default y
924+
help
925+
This option adds the workaround for ARM Cortex-A510 erratum 2457168.
926+
927+
The AMU counter AMEVCNTR01 (constant counter) should increment at the same rate
928+
as the system counter. On affected Cortex-A510 cores AMEVCNTR01 increments
929+
incorrectly giving a significantly higher output value.
930+
931+
Work around this problem by returning 0 when reading the affected counter in
932+
key locations that results in disabling all users of this counter. This effect
933+
is the same to firmware disabling affected counters.
934+
935+
If unsure, say Y.
936+
920937
config CAVIUM_ERRATUM_22375
921938
bool "Cavium erratum 22375, 24313"
922939
default y

arch/arm64/kernel/cpu_errata.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
656656
ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A510, 0, 0, 2)
657657
},
658658
#endif
659+
#ifdef CONFIG_ARM64_ERRATUM_2457168
660+
{
661+
.desc = "ARM erratum 2457168",
662+
.capability = ARM64_WORKAROUND_2457168,
663+
.type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
664+
665+
/* Cortex-A510 r0p0-r1p1 */
666+
CAP_MIDR_RANGE(MIDR_CORTEX_A510, 0, 0, 1, 1)
667+
},
668+
#endif
659669
#ifdef CONFIG_ARM64_ERRATUM_2038923
660670
{
661671
.desc = "ARM erratum 2038923",

arch/arm64/kernel/cpufeature.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,10 @@ static void cpu_amu_enable(struct arm64_cpu_capabilities const *cap)
18701870
pr_info("detected CPU%d: Activity Monitors Unit (AMU)\n",
18711871
smp_processor_id());
18721872
cpumask_set_cpu(smp_processor_id(), &amu_cpus);
1873-
update_freq_counters_refs();
1873+
1874+
/* 0 reference values signal broken/disabled counters */
1875+
if (!this_cpu_has_cap(ARM64_WORKAROUND_2457168))
1876+
update_freq_counters_refs();
18741877
}
18751878
}
18761879

arch/arm64/kernel/topology.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,25 @@ core_initcall(init_amu_fie);
296296

297297
static void cpu_read_corecnt(void *val)
298298
{
299+
/*
300+
* A value of 0 can be returned if the current CPU does not support AMUs
301+
* or if the counter is disabled for this CPU. A return value of 0 at
302+
* counter read is properly handled as an error case by the users of the
303+
* counter.
304+
*/
299305
*(u64 *)val = read_corecnt();
300306
}
301307

302308
static void cpu_read_constcnt(void *val)
303309
{
304-
*(u64 *)val = read_constcnt();
310+
/*
311+
* Return 0 if the current CPU is affected by erratum 2457168. A value
312+
* of 0 is also returned if the current CPU does not support AMUs or if
313+
* the counter is disabled. A return value of 0 at counter read is
314+
* properly handled as an error case by the users of the counter.
315+
*/
316+
*(u64 *)val = this_cpu_has_cap(ARM64_WORKAROUND_2457168) ?
317+
0UL : read_constcnt();
305318
}
306319

307320
static inline
@@ -328,7 +341,22 @@ int counters_read_on_cpu(int cpu, smp_call_func_t func, u64 *val)
328341
*/
329342
bool cpc_ffh_supported(void)
330343
{
331-
return freq_counters_valid(get_cpu_with_amu_feat());
344+
int cpu = get_cpu_with_amu_feat();
345+
346+
/*
347+
* FFH is considered supported if there is at least one present CPU that
348+
* supports AMUs. Using FFH to read core and reference counters for CPUs
349+
* that do not support AMUs, have counters disabled or that are affected
350+
* by errata, will result in a return value of 0.
351+
*
352+
* This is done to allow any enabled and valid counters to be read
353+
* through FFH, knowing that potentially returning 0 as counter value is
354+
* properly handled by the users of these counters.
355+
*/
356+
if ((cpu >= nr_cpu_ids) || !cpumask_test_cpu(cpu, cpu_present_mask))
357+
return false;
358+
359+
return true;
332360
}
333361

334362
int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ WORKAROUND_1902691
6767
WORKAROUND_2038923
6868
WORKAROUND_2064142
6969
WORKAROUND_2077057
70+
WORKAROUND_2457168
7071
WORKAROUND_TRBE_OVERWRITE_FILL_MODE
7172
WORKAROUND_TSB_FLUSH_FAILURE
7273
WORKAROUND_TRBE_WRITE_OUT_OF_RANGE

0 commit comments

Comments
 (0)