[PATCH 19/20 v3] sched/fair: Take into account slice in EAS

From: Vincent Guittot

Date: Fri Nov 06 2026 - 10:24:01 EST


When the cost is the same, take into account the slice of a task to try to
select a CPU where is will run first.

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

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ea117c3d0dd7..da9c4416f1b5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9885,13 +9885,22 @@ static bool update_best_cpu(struct energy_cpu_stat *target,
int prev, struct sched_domain *sd,
struct task_struct *p)
{
+ unsigned long task_slice = p->se.slice;
bool target_idle = choose_idle_cpu(target->cpu, p);
bool min_idle = choose_idle_cpu(min->cpu, p);
+ bool target_first, min_first;

/* Select the one which is idle */
if (target_idle != min_idle)
return target_idle;

+ target_first = task_slice < get_rq_min_slice(cpu_rq(target->cpu));
+ min_first = task_slice < get_rq_min_slice(cpu_rq(min->cpu));
+
+ /* Select the one where you can run first */
+ if (target_first != min_first)
+ return target_first;
+
/* Favor previous CPU */
if (target->cpu == prev)
return true;
@@ -10055,7 +10064,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
*/
if (target_perf < min_stat.min_perf)
find_pd_cost(pd->em_pd, target_perf, &target_stat);
- else if (!update_best_cpu(&target_stat, &min_stat, prev_cpu, sd))
+ else if (!update_best_cpu(&target_stat, &min_stat, prev_cpu, sd, p))
continue;

/* Save the new most efficient CPU of the PD */
--
2.53.0