Skip to content

Commit 20711ef

Browse files
bea-armctmarinas
authored andcommitted
arm64: Utilize for_each_cpu_wrap for reference lookup
While searching for a reference CPU within a given policy, arch_freq_get_on_cpu relies on cpumask_next_wrap to iterate over all available CPUs and to ensure each is verified only once. Recent changes to cpumask_next_wrap will handle the latter no more, so switching to for_each_cpu_wrap, which preserves expected behavior while ensuring compatibility with the updates. Not to mention that when iterating over each CPU, using a dedicated iterator is preferable to an open-coded loop. Fixes: 16d1e27 ("arm64: Provide an AMU-based version of arch_freq_get_on_cpu") Signed-off-by: Beata Michalska <beata.michalska@arm.com> Link: https://lore.kernel.org/r/20250220091015.2319901-1-beata.michalska@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 39b1997 commit 20711ef

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

arch/arm64/kernel/topology.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ int arch_freq_get_on_cpu(int cpu)
254254
if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
255255
time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
256256
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
257-
int ref_cpu = cpu;
257+
int ref_cpu;
258258

259259
if (!policy)
260260
return -EINVAL;
@@ -265,11 +265,15 @@ int arch_freq_get_on_cpu(int cpu)
265265
return -EOPNOTSUPP;
266266
}
267267

268-
do {
269-
ref_cpu = cpumask_next_wrap(ref_cpu, policy->cpus,
270-
start_cpu, true);
271-
272-
} while (ref_cpu < nr_cpu_ids && idle_cpu(ref_cpu));
268+
for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
269+
if (ref_cpu == start_cpu) {
270+
/* Prevent verifying same CPU twice */
271+
ref_cpu = nr_cpu_ids;
272+
break;
273+
}
274+
if (!idle_cpu(ref_cpu))
275+
break;
276+
}
273277

274278
cpufreq_cpu_put(policy);
275279

0 commit comments

Comments
 (0)