Currently while offlining a cpu, we iterate through all the cpus in the
DIE to clear sibling, l2_cache and smallcore maps. However if there are
more number of cores in a DIE, we end up spending more time iterating
through cpus which are completely unrelated.

Optimize this by only iterating through lesser but relevant cpumap.
If shared_cache is set, cpu_l2_cache_map should be relevant else
cpu_sibling_map would be relevant.

Cc: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Cc: LKML <linux-ker...@vger.kernel.org>
Cc: Michael Ellerman <m...@ellerman.id.au>
Cc: Nicholas Piggin <npig...@gmail.com>
Cc: Anton Blanchard <an...@ozlabs.org>
Cc: Oliver O'Halloran <ooh...@gmail.com>
Cc: Nathan Lynch <nath...@linux.ibm.com>
Cc: Michael Neuling <mi...@neuling.org>
Cc: Gautham R Shenoy <e...@linux.vnet.ibm.com>
Cc: Satheesh Rajendran <sathn...@linux.vnet.ibm.com>
Cc: Ingo Molnar <mi...@kernel.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Valentin Schneider <valentin.schnei...@arm.com>
Signed-off-by: Srikar Dronamraju <sri...@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/smp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index d476098fc25c..cde157483abf 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1254,14 +1254,21 @@ static bool update_mask_by_l2(int cpu, struct cpumask 
*(*mask_fn)(int))
 #ifdef CONFIG_HOTPLUG_CPU
 static void remove_cpu_from_masks(int cpu)
 {
+       struct cpumask *(*mask_fn)(int) = cpu_sibling_mask;
        int i;
 
-       for_each_cpu(i, cpu_cpu_mask(cpu)) {
+       if (shared_caches)
+               mask_fn = cpu_l2_cache_mask;
+
+       for_each_cpu(i, mask_fn(cpu)) {
                set_cpus_unrelated(cpu, i, cpu_l2_cache_mask);
                set_cpus_unrelated(cpu, i, cpu_sibling_mask);
                if (has_big_cores)
                        set_cpus_unrelated(cpu, i, cpu_smallcore_mask);
-               if (has_coregroup_support())
+       }
+
+       if (has_coregroup_support()) {
+               for_each_cpu(i, cpu_coregroup_mask(cpu))
                        set_cpus_unrelated(cpu, i, cpu_coregroup_mask);
        }
 }
-- 
2.17.1

Reply via email to