]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpu/hotplug: Reverse order of iteration in freeze_secondary_cpus()
authorStanislav Spassov <stanspas@amazon.de>
Fri, 24 May 2024 16:04:49 +0000 (16:04 +0000)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 17 Jun 2024 13:17:44 +0000 (15:17 +0200)
Whenever CPU hotplug state callbacks are registered, the startup callback
is invoked on CPUs that have already reached the provided state in order of
ascending CPU IDs.

In freeze_secondary_cpus() the teardown of CPUs happens in the same are
invoked in the same order. This is known to make a difference is the
current implementation of these callbacks in arch/x86/events/intel/uncore.c:

 - uncore_event_cpu_online() designates the first CPU it is invoked for
   on each package as the uncore event collector for that package

 - uncore_event_cpu_offline() if the CPU being offlined is the event
   collector for its package, transfers that responsibility over to
   the next (by ascending CPU id) one in the same package

With the current order of CPU teardowns in freeze_secondary_cpus(), the
latter ends up doing the ownership transfer work on every single CPU.  That
work involves a synchronize_rcu() call, ultimately unnecessarily degrading
the performance of CPU offlining.

To address this make freeze_secondary_cpus() iterate through the CPUs in
reverse order, so that the teardown happens in order of descending CPU IDs.

[ tglx: Massage change log ]

Signed-off-by: Stanislav Spassov <stanspas@amazon.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240524160449.48594-1-stanspas@amazon.de
kernel/cpu.c

index 563877d6c28b65f40a9e5597c865e0afa1200a64..1979a993571986da8ad58ecbcdc321d0ec670529 100644 (file)
@@ -1891,8 +1891,8 @@ int freeze_secondary_cpus(int primary)
        cpumask_clear(frozen_cpus);
 
        pr_info("Disabling non-boot CPUs ...\n");
-       for_each_online_cpu(cpu) {
-               if (cpu == primary)
+       for (cpu = nr_cpu_ids - 1; cpu >= 0; cpu--) {
+               if (!cpu_online(cpu) || cpu == primary)
                        continue;
 
                if (pm_wakeup_pending()) {