powerpc/smp: Optimize update_coregroup_mask
authorSrikar Dronamraju <srikar@linux.vnet.ibm.com>
Mon, 21 Sep 2020 09:56:53 +0000 (15:26 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 6 Oct 2020 12:22:27 +0000 (23:22 +1100)
All threads of a SMT4/SMT8 core can either be part of CPU's coregroup
mask or outside the coregroup. Use this relation to reduce the
number of iterations needed to find all the CPUs that share the same
coregroup

Use a temporary mask to iterate through the CPUs that may share
coregroup mask. Also instead of setting one CPU at a time into
cpu_coregroup_mask, copy the SMT4/SMT8/submask at one shot.

Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200921095653.9701-12-srikar@linux.vnet.ibm.com
arch/powerpc/kernel/smp.c

index 45619433c43aec4808ee01f96c70a4bd2ed23a71..0dc1b8591cc886d6e141b939f1f65a57f84a06a3 100644 (file)
@@ -1339,19 +1339,33 @@ static inline void add_cpu_to_smallcore_masks(int cpu)
 
 static void update_coregroup_mask(int cpu)
 {
-       int first_thread = cpu_first_thread_sibling(cpu);
+       struct cpumask *(*submask_fn)(int) = cpu_sibling_mask;
+       cpumask_var_t mask;
        int coregroup_id = cpu_to_coregroup_id(cpu);
        int i;
 
-       cpumask_set_cpu(cpu, cpu_coregroup_mask(cpu));
-       for_each_cpu_and(i, cpu_online_mask, cpu_cpu_mask(cpu)) {
-               int fcpu = cpu_first_thread_sibling(i);
+       alloc_cpumask_var_node(&mask, GFP_KERNEL, cpu_to_node(cpu));
+       cpumask_and(mask, cpu_online_mask, cpu_cpu_mask(cpu));
+
+       if (shared_caches)
+               submask_fn = cpu_l2_cache_mask;
+
+       /* Update coregroup mask with all the CPUs that are part of submask */
+       or_cpumasks_related(cpu, cpu, submask_fn, cpu_coregroup_mask);
+
+       /* Skip all CPUs already part of coregroup mask */
+       cpumask_andnot(mask, mask, cpu_coregroup_mask(cpu));
 
-               if (fcpu == first_thread)
-                       set_cpus_related(cpu, i, cpu_coregroup_mask);
-               else if (coregroup_id == cpu_to_coregroup_id(i))
-                       set_cpus_related(cpu, i, cpu_coregroup_mask);
+       for_each_cpu(i, mask) {
+               /* Skip all CPUs not part of this coregroup */
+               if (coregroup_id == cpu_to_coregroup_id(i)) {
+                       or_cpumasks_related(cpu, i, submask_fn, cpu_coregroup_mask);
+                       cpumask_andnot(mask, mask, submask_fn(i));
+               } else {
+                       cpumask_andnot(mask, mask, cpu_coregroup_mask(i));
+               }
        }
+       free_cpumask_var(mask);
 }
 
 static void add_cpu_to_masks(int cpu)