[PATCH] sched/fair: Don't force smt balancing when CPU has spare capacity

From: Tim Chen
Date: Fri Oct 06 2023 - 18:58:56 EST


Currently group_smt_balance is picked whenever there are more
than two tasks on a core with two SMT. However, the utilization
of those tasks may be low and do not warrant a task
migration to a CPU of lower priority.

Adjust sched group clssification and sibling_imbalance()
to reflect this consideration. Use sibling_imbalance() to
compute imbalance in calculate_imbalance() for the group_smt_balance
case.

Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>

---
kernel/sched/fair.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ef7490c4b8b4..7dd7c2d2367a 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9460,14 +9460,15 @@ group_type group_classify(unsigned int imbalance_pc=
t,
if (sgs->group_asym_packing)
return group_asym_packing;
=20
- if (sgs->group_smt_balance)
- return group_smt_balance;
-
if (sgs->group_misfit_task_load)
return group_misfit_task;
=20
- if (!group_has_capacity(imbalance_pct, sgs))
- return group_fully_busy;
+ if (!group_has_capacity(imbalance_pct, sgs)) {
+ if (sgs->group_smt_balance)
+ return group_smt_balance;
+ else
+ return group_fully_busy;
+ }
=20
return group_has_spare;
}
@@ -9573,6 +9574,11 @@ static inline long sibling_imbalance(struct lb_env *=
env,
if (env->idle =3D=3D CPU_NOT_IDLE || !busiest->sum_nr_running)
return 0;
=20
+ /* Do not pull tasks off preferred group with spare capacity */
+ if (busiest->group_type =3D=3D group_has_spare &&
+ sched_asym_prefer(sds->busiest->asym_prefer_cpu, env->dst_cpu))
+ return 0;
+
ncores_busiest =3D sds->busiest->cores;
ncores_local =3D sds->local->cores;
=20
@@ -10411,13 +10417,6 @@ static inline void calculate_imbalance(struct lb_e=
nv *env, struct sd_lb_stats *s
return;
}
=20
- if (busiest->group_type =3D=3D group_smt_balance) {
- /* Reduce number of tasks sharing CPU capacity */
- env->migration_type =3D migrate_task;
- env->imbalance =3D 1;
- return;
- }
-
if (busiest->group_type =3D=3D group_imbalanced) {
/*
* In the group_imb case we cannot rely on group-wide averages
--=20
2.32.0