]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
powerpc/xmon: simplify xmon_batch_next_cpu()
authorYury Norov <yury.norov@gmail.com>
Tue, 28 Jan 2025 16:46:33 +0000 (11:46 -0500)
committerYury Norov <yury.norov@gmail.com>
Mon, 24 Feb 2025 21:37:22 +0000 (16:37 -0500)
The function opencodes for_each_cpu_wrap() macro. As a loop termination
condition it uses cpumask_empty(), which is O(N), and it makes the whole
algorithm O(N^2). Switching to for_each_cpu_wrap() simplifies the logic,
and makes the algorithm linear.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
arch/powerpc/xmon/xmon.c

index 268859e4df8706d95e8b78cda9e4a836413f30ad..1acb53aab252d22ff55f0780ed2a68603e24c974 100644 (file)
@@ -1271,11 +1271,7 @@ static int xmon_batch_next_cpu(void)
 {
        unsigned long cpu;
 
-       while (!cpumask_empty(&xmon_batch_cpus)) {
-               cpu = cpumask_next_wrap(smp_processor_id(), &xmon_batch_cpus,
-                                       xmon_batch_start_cpu, true);
-               if (cpu >= nr_cpu_ids)
-                       break;
+       for_each_cpu_wrap(cpu, &xmon_batch_cpus, xmon_batch_start_cpu) {
                if (xmon_batch_start_cpu == -1)
                        xmon_batch_start_cpu = cpu;
                if (xmon_switch_cpu(cpu))