Skip to content

Commit

Permalink
arm64: Utilize for_each_cpu_wrap for reference lookup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Beata Michalska authored and Catalin Marinas committed Feb 21, 2025
1 parent 39b1997 commit 20711ef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions arch/arm64/kernel/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int arch_freq_get_on_cpu(int cpu)
if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
int ref_cpu = cpu;
int ref_cpu;

if (!policy)
return -EINVAL;
Expand All @@ -265,11 +265,15 @@ int arch_freq_get_on_cpu(int cpu)
return -EOPNOTSUPP;
}

do {
ref_cpu = cpumask_next_wrap(ref_cpu, policy->cpus,
start_cpu, true);

} while (ref_cpu < nr_cpu_ids && idle_cpu(ref_cpu));
for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
if (ref_cpu == start_cpu) {
/* Prevent verifying same CPU twice */
ref_cpu = nr_cpu_ids;
break;
}
if (!idle_cpu(ref_cpu))
break;
}

cpufreq_cpu_put(policy);

Expand Down

0 comments on commit 20711ef

Please sign in to comment.