[PATCH] sched/topology: optimize sched_numa_find_nth_cpu()
From: Yury Norov
Date: Thu Mar 19 2026 - 13:30:48 EST
The binary search callback hop_cmp() uses cpumask_weight_and() on each
iteration. Switch it to cpumask_nth_and() as it returns earlier, as
soon as the required number of CPUs is found.
Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
---
kernel/sched/topology.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 32dcddaead82..0437f5ded37b 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2267,7 +2267,7 @@ static int hop_cmp(const void *a, const void *b)
struct cpumask **prev_hop, **cur_hop = *(struct cpumask ***)b;
struct __cmp_key *k = (struct __cmp_key *)a;
- if (cpumask_weight_and(k->cpus, cur_hop[k->node]) <= k->cpu)
+ if (cpumask_nth_and(k->cpu, k->cpus, cur_hop[k->node]) >= nr_cpu_ids)
return 1;
if (b == k->masks) {
--
2.43.0