Re: [RFC PATCH v3 0/6] sched/cpufreq: Make schedutil energy aware

From: Peter Zijlstra
Date: Thu Oct 17 2019 - 10:11:37 EST


On Thu, Oct 17, 2019 at 12:11:16PM +0100, Quentin Perret wrote:
> On Thursday 17 Oct 2019 at 11:50:15 (+0200), Peter Zijlstra wrote:
> > Now, the thing is, we use map_util_freq() in more places, and should we
> > not reflect this increase in C for all of them? That is, why is this
> > patch changing get_next_freq() and not map_util_freq().
> >
> > I don't think that question is answered in the Changelogs.
> >
> > Exactly because it does change the energy consumption (it must) should
> > that not also be reflected in the EAS logic?
>
> Right that shouldn't hurt and keep things consistent. That probably
> won't have a huge impact in practice (the boost should be != 0 only when
> the util signals haven't converged IIUC, which is a case where the EAS
> calculation is already 'wrong' anyway), but that still feels like the
> right thing to do.

It only boosts when 'rq->cfs.avg.util' increases while
'rq->cfs.avg.util_est.enqueued' remains unchanged (and util > util_est
obv).

This condition can be true for select_task_rq_fair(), because that is
ran before we do enqueue_task_fair() (for obvious raisins).

> > I'm still thinking about the exact means you're using to raise C; that
> > is, the 'util - util_est' as cost_margin. It hurts my brain still.
>
> +1 ...

cost_i = capacity_i / power_i ; for the i-th OPP

We then do: 'x = util - util_avg' and use that on the first
OPP >= min_freq:

cost(x) = cost_j + cost_j * x ; freq_j >= min_freq
= cost_j * (1 + x)

And then we find the highest OPP that has:

cost_k <= cost(x)

Now, 'P = C*V^2*f', which under 'V ~ f' turns into 'P ~ f^3'.

(this assumption is important because we don't have V_i, but know that
when f increases, V also increases and the linear relation is the
simplest)

This then gives us:

capacity_i = f_i / f_max
power_i ~ f_i ^ 3
cost_i = capacity_i / power_i
~ (f_i / f_max) / f_i^3
~ 1 / (f_max * f_i^2)

(your changelog already called if efficiency, but then went on calling
it cost; as per the above, you see that higher frequencies have lower
efficiency, as expected)

cost(x) then turns into something like:

cost(x) = cost_j * (1 + x)
~ (1 + x) / (f_max * f_j^2)

We then get the following equation (assuming inf. OPPs):

cost_k = cost(x)

1 / (f_max * f_k^2) = (1 + x) / (f_max * f_j^2)

>From which we can solve f_k:

f_k = f_j / sqrt(1 + x) ; x = util - util_est

Which, given positive 'x' results in f_k < f_j, IOW. we're selecting a
lower frequency.

Given that 'cost' really is efficiency, and we've made the equations
about selecting a higher efficiency, that makes sense in so far that it
would always end up at the knee in the graph (our most efficient OPP).

Is this really what we're wanting to do?