[PATCH 13/22] x86: smp: move cpumask_weight() out of for-loop in remove_siblinginfo

From: Yury Norov
Date: Tue May 10 2022 - 11:58:01 EST


Because argument of the function is constant inside for_each_cpu()
loop, the cpumask_weight() does the same work O(NR_CPUS) times, while
it may be calculated only once.

This patch moves cpumask_weight() out of the loop and replaces it
with cpumask_weight_eq(). While here, fix comment format.

CC: Balbir Singh <sblbir@xxxxxxxxxx>
CC: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
CC: Borislav Petkov <bp@xxxxxxxxx>
CC: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
CC: H. Peter Anvin <hpa@xxxxxxxxx>
CC: Huang Rui <ray.huang@xxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
CC: Paul E. McKenney <paulmck@xxxxxxxxxx>
CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CC: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
CC: Sean Christopherson <seanjc@xxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
CC: x86@xxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
arch/x86/kernel/smpboot.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 5e7f9532a10d..7d948f79ef31 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1605,13 +1605,14 @@ static void remove_siblinginfo(int cpu)
{
int sibling;
struct cpuinfo_x86 *c = &cpu_data(cpu);
+ bool last_thread_sibling = cpumask_weight_eq(topology_sibling_cpumask(cpu), 1);

for_each_cpu(sibling, topology_core_cpumask(cpu)) {
cpumask_clear_cpu(cpu, topology_core_cpumask(sibling));
- /*/
+ /*
* last thread sibling in this cpu core going down
*/
- if (cpumask_weight(topology_sibling_cpumask(cpu)) == 1)
+ if (last_thread_sibling)
cpu_data(sibling).booted_cores--;
}

--
2.32.0