Skip to contentSkip to conversation

sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()

PATCH RESEND Applied Yury Norov (NVIDIA) 2 participants 2 messages Dec 7, 2025 – Jan 12 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sched/fair: use cpumask_weight_and() in sched_balance_find_dst_group()

In the group_has_spare case, the function creates a temporary cpumask to just calculate weight of (p->cpus_ptr & sched_group_span(local)).

We've got a dedicated helper for it.

---
Rebased and re-tested on top of master. Original patch:
https://lore.kernel.org/all/[email protected]/

 kernel/sched/fair.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/sched/fair.c +3 -4
index 3ead55e4b8a5..e04f94233cda 100644
@@ -10972,10 +10972,9 @@ sched_balance_find_dst_group(struct sched_domain *sd, struct task_struct *p, int
 			 * take care of it.
 			 */
 			if (p->nr_cpus_allowed != NR_CPUS) {
-				struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
-
-				cpumask_and(cpus, sched_group_span(local), p->cpus_ptr);
-				imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr);
+				unsigned int w = cpumask_weight_and(p->cpus_ptr,
+								sched_group_span(local));
+				imb_numa_nr = min(w, sd->imb_numa_nr);
 			}
 
 			imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus);
Signature · 1 line
2.43.0
#1 lore raw

[tip: sched/core] sched/fair: Use cpumask_weight_and() in sched_balance_find_dst_group()

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     55b39b0cf183b9c682717a55a2fba06da69bba6b
Gitweb:        https://git.kernel.org/tip/55b39b0cf183b9c682717a55a2fba06da69bba6b
Author:        Yury Norov (NVIDIA) <[email protected]>
AuthorDate:    Sat, 06 Dec 2025 22:42:47 -05:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 08 Jan 2026 12:43:56 +01:00

sched/fair: Use cpumask_weight_and() in sched_balance_find_dst_group()

In the group_has_spare case, the function creates a temporary cpumask to just calculate weight of (p->cpus_ptr & sched_group_span(local)).

We've got a dedicated helper for it.

---
 kernel/sched/fair.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/sched/fair.c +3 -4
index 842a0f2..ebee20f 100644
@@ -10974,10 +10974,9 @@ sched_balance_find_dst_group(struct sched_domain *sd, struct task_struct *p, int
 			 * take care of it.
 			 */
 			if (p->nr_cpus_allowed != NR_CPUS) {
-				struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
-
-				cpumask_and(cpus, sched_group_span(local), p->cpus_ptr);
-				imb_numa_nr = min(cpumask_weight(cpus), sd->imb_numa_nr);
+				unsigned int w = cpumask_weight_and(p->cpus_ptr,
+								sched_group_span(local));
+				imb_numa_nr = min(w, sd->imb_numa_nr);
 			}
 
 			imbalance = abs(local_sgs.idle_cpus - idlest_sgs.idle_cpus);