[PATCH 8/8] sched/eevdf: Add min slice check when selecting CPU

From: Vincent Guittot

Date: Mon Sep 21 2026 - 13:18:44 EST


Add a new level for selecting CPU when select_task_rq_fair() fails to find
an idle CPU. This last level will compare the slice to select a CPU where
the task could run 1st.
This helps a waking task to select a CPU where a longer slice runs
instead of one where a task with the same or shorter slice already runs.

Signed-off-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
---
kernel/sched/fair.c | 63 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 452da94289fe..5c9add3e853c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9023,6 +9023,59 @@ static inline bool asym_fits_cpu(unsigned long util,
return true;
}

+static int select_slice_cpu(struct task_struct *p, struct sched_domain *sd, int target)
+{
+ unsigned long task_util, util_min, util_max;
+ int cpu, nr = INT_MAX;
+ u64 slice = p->se.slice;
+ struct cpumask *cpus;
+
+ if (sched_feat(SIS_UTIL) && sd->shared) {
+ /*
+ * Same nr_idle_scan hint as select_idle_cpu(), nr only limits
+ * the scan when not preferring an idle core.
+ */
+ nr = READ_ONCE(sd->shared->nr_idle_scan) + 1;
+ /* overloaded domain is unlikely to have idle cpu/core */
+ if (nr == 1)
+ return -1;
+ }
+
+ cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
+ cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
+
+ if (sched_asym_cpucap_active()) {
+ task_util = task_util_est(p);
+ util_min = uclamp_eff_value(p, UCLAMP_MIN);
+ util_max = uclamp_eff_value(p, UCLAMP_MAX);
+ }
+
+ /* Those CPUs have been tested not being idle and fiting */
+ for_each_cpu_wrap(cpu, cpus, target) {
+ /*
+ * Stop when the nr_idle_scan is exhausted (mirrors
+ * select_idle_cpu() logic).
+ */
+ if (--nr <= 0)
+ return -1;
+
+ if (slice >= get_rq_min_slice(cpu_rq(cpu)))
+ continue;
+
+ if (sched_asym_cpucap_active()) {
+ int fits = util_fits_cpu(task_util, util_min, util_max, cpu);
+
+ /* Perfect fit: capacity satisfies util + uclamp */
+ if (fits > 0)
+ return cpu;
+ } else {
+ return cpu;
+ }
+ }
+
+ return -1;
+}
+
/*
* Try and locate an idle core/thread in the LLC cache domain.
*/
@@ -9117,7 +9170,10 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
*/
if (sd) {
i = select_idle_capacity(p, sd, target);
- return ((unsigned)i < nr_cpumask_bits) ? i : target;
+ if ((unsigned int)i < nr_cpumask_bits)
+ return i;
+
+ goto select_slice;
}
}

@@ -9150,6 +9206,11 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
if ((unsigned int)recent_used_cpu < nr_cpumask_bits)
return recent_used_cpu;

+select_slice:
+ i = select_slice_cpu(p, sd, target);
+ if ((unsigned int)i < nr_cpumask_bits)
+ return i;
+
return target;
}

--
2.53.0