[PATCH v2 06/17] sched/fair: Select preferred CPU at wakeup when possible

Shrikanth Hegde
2026-04-07T19:21:20Z

Update available_idle_cpu to consider preferred CPUs. This takes care of
lot of decisions at wakeup to use only preferred CPUs. There is no need to
put those explicit checks everywhere.

Only other place where prev_cpu was not preferred and could possibly return
was sched_balance_find_dst_cpu. Put the check there.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
kernel/sched/fair.c | 3 ++-
kernel/sched/sched.h | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 86ef9ce39b61..22010afb4c1d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7698,7 +7698,8 @@ static inline int sched_balance_find_dst_cpu(struct sched_domain *sd, struct tas
{
int new_cpu = cpu;

- if (!cpumask_intersects(sched_domain_span(sd), p->cpus_ptr))
+ if (!cpumask_intersects(sched_domain_span(sd), p->cpus_ptr) &&
+ cpu_preferred(prev_cpu))
return prev_cpu;

/*
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 7271af2ca64f..4c45092b2fce 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1412,6 +1412,9 @@ static inline bool available_idle_cpu(int cpu)
if (!idle_rq(cpu_rq(cpu)))
return 0;

+ if (!cpu_preferred(cpu))
+ return 0;
+
if (vcpu_is_preempted(cpu))
return 0;

--
2.47.3