Re: [PATCH 05/18 v2] sched/eevdf: Add min slice check when selecting CPU
From: Kayra Cizmeci
Date: Sun Oct 04 2026 - 15:18:26 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 run.
There's a typo. 'run'
> @@ -8771,10 +8771,11 @@ static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int t
> * comparing the average scan cost (tracked in sd->avg_scan_cost) against the
> * average idle time for this rq (as found in rq->avg_idle).
> */
> -static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool has_idle_core, int target)
> +static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool has_idle_core, int *best)
> {
> struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
> - int i, cpu, idle_cpu = -1, nr = INT_MAX;
> + int i, cpu, idle_cpu = -1, slice_cpu = -1, target = *best, nr = INT_MAX;
> + unsigned long task_slice;
>
> if (sched_feat(SIS_UTIL) && sd->shared) {
> /*
> @@ -8795,6 +8796,8 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
> if (!cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr))
> return -1;
>
> + task_slice = p->se.slice;
> +
> if (static_branch_unlikely(&sched_cluster_active)) {
> struct sched_group *sg = sd->groups;
>
> @@ -8814,6 +8817,10 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
> if ((unsigned int)idle_cpu < nr_cpumask_bits)
> return idle_cpu;
> }
> +
> + if (slice_cpu == -1 &&
> + task_slice < get_rq_min_slice(cpu_rq(cpu)))
> + slice_cpu = cpu;
> }
> cpumask_andnot(cpus, cpus, sched_group_span(sg));
> }
> @@ -8832,11 +8839,18 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
> if ((unsigned int)idle_cpu < nr_cpumask_bits)
> break;
> }
> +
> + if (slice_cpu == -1 &&
> + task_slice < get_rq_min_slice(cpu_rq(cpu)))
> + slice_cpu = cpu;
> }
>
> if (has_idle_core)
> set_idle_cores(target, false);
>
> + if (slice_cpu != -1)
> + *best = slice_cpu;
> +
> return idle_cpu;
> }
Also,
Scene:
Let's say that in our domain there are 8 CPU's and has_idle_core is false. And nr equals 4.
And sched_cluster_active is true. select_idle_cpu() enters the for_each_cpu_wrap block
and the else branch. Because nr decrases each time, and if there are not any idle_cpu's
even if we found any slice_cpu it's not set to best. We just leave the loop after checking 3 CPU's.
The same thing a bit differently happens below on the main loop too.
But I don't think is more important than typos. Typos is the reason we're here. They are the or nevermind.
This is a joke btw. (that, destroyed my masterpiece and created a new one. Saying a joke is a joke because it is,
is one thing while saying a joke is a joke as a joke is one thing. I wanna go on with this but it'll be to long. :<)
I could be getting something wrong tho. (No one is perfect, but I'm not perfect at all so ya know.)
Thanks,
Kayra