[PATCH v2 2/6] sched/fair: Only count group weight for allowed CPUs when looking for dst group

From: Adam Li
Date: Thu Jul 17 2025 - 02:21:58 EST


A task may not use all the CPUs in a schedule group due to CPU affinity.
If group weight includes CPUs not allowed to run, group classification
may be incorrect.

Signed-off-by: Adam Li <adamli@xxxxxxxxxxxxxxxxxxxxxx>
---
kernel/sched/fair.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 78a3d9b78e07..452e2df961b9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10722,7 +10722,9 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,

sgs->group_capacity = group->sgc->capacity;

- sgs->group_weight = group->group_weight;
+ /* Only count group_weight if p can run on these cpus */
+ sgs->group_weight = cpumask_weight_and(sched_group_span(group),
+ p->cpus_ptr);

sgs->group_type = group_classify(sd->imbalance_pct, group, sgs);

--
2.34.1