Re: [PATCH 3/3] sched/fair: Consider uclamp for "task fits capacity" checks

From: Quentin Perret
Date: Thu Nov 21 2019 - 08:30:51 EST


On Thursday 21 Nov 2019 at 12:56:39 (+0000), Valentin Schneider wrote:
> > @@ -6274,6 +6274,15 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
> > if (!fits_capacity(util, cpu_cap))
> > continue;
> >
> > + /*
> > + * Skip CPUs that don't satisfy uclamp requests. Note
> > + * that the above already ensures the CPU has enough
> > + * spare capacity for the task; this is only really for
> > + * uclamp restrictions.
> > + */
> > + if (!task_fits_capacity(p, capacity_orig_of(cpu)))
> > + continue;
>
> This is partly redundant with the above, I think. What we really want here
> is just
>
> fits_capacity(uclamp_eff_value(p, UCLAMP_MIN), capacity_orig_of(cpu))
>
> but this would require some inline #ifdeffery.

This suggested change lacks the UCLAMP_MAX part, which is a shame
because this is precisely in the EAS path that we should try and
down-migrate tasks if they have an appropriate max_clamp. So, your first
proposal made sense, IMO.

Another option to avoid the redundancy would be to do something along
the lines of the totally untested diff below.

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 69a81a5709ff..38cb5fe7ba65 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6372,9 +6372,12 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
if (!cpumask_test_cpu(cpu, p->cpus_ptr))
continue;

- /* Skip CPUs that will be overutilized. */
util = cpu_util_next(cpu, p, cpu);
cpu_cap = capacity_of(cpu);
+ spare_cap = cpu_cap - util;
+ util = uclamp_util_with(cpu_rq(cpu), util, p);
+
+ /* Skip CPUs that will be overutilized. */
if (!fits_capacity(util, cpu_cap))
continue;

@@ -6389,7 +6392,6 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
* Find the CPU with the maximum spare capacity in
* the performance domain
*/
- spare_cap = cpu_cap - util;
if (spare_cap > max_spare_cap) {
max_spare_cap = spare_cap;
max_spare_cap_cpu = cpu;

Thoughts ?

Thanks,
Quentin