Re: [PATCH v5 06/15] sched/core: uclamp: enforce last task UCLAMP_MAX

From: Peter Zijlstra
Date: Sun Nov 11 2018 - 12:09:06 EST


On Mon, Oct 29, 2018 at 06:33:01PM +0000, Patrick Bellasi wrote:
> When a util_max clamped task sleeps, its clamp constraints are removed
> from the CPU. However, the blocked utilization on that CPU can still be
> higher than the max clamp value enforced while that task was running.
>
> The release of a util_max clamp when a CPU is going to be idle could
> thus allow unwanted CPU frequency increases while tasks are not
> running. This can happen, for example, when a frequency update is
> triggered from another CPU of the same frequency domain.
> In this case, when we aggregate the utilization of all the CPUs in a
> shared frequency domain, schedutil can still see the full not clamped
> blocked utilization of all the CPUs and thus, eventually, increase the
> frequency.

> @@ -810,6 +811,28 @@ static inline void uclamp_cpu_update(struct rq *rq, unsigned int clamp_id)
> if (max_value >= SCHED_CAPACITY_SCALE)
> break;
> }
> +
> + /*
> + * Just for the UCLAMP_MAX value, in case there are no RUNNABLE
> + * task, we want to keep the CPU clamped to the last task's clamp
> + * value. This is to avoid frequency spikes to MAX when one CPU, with
> + * an high blocked utilization, sleeps and another CPU, in the same
> + * frequency domain, do not see anymore the clamp on the first CPU.
> + *
> + * The UCLAMP_FLAG_IDLE is set whenever we detect, from the above
> + * loop, that there are no more RUNNABLE taks on that CPU.
> + * In this case we enforce the CPU util_max to that of the last
> + * dequeued task.
> + */
> + if (max_value < 0) {
> + if (clamp_id == UCLAMP_MAX) {
> + rq->uclamp.flags |= UCLAMP_FLAG_IDLE;
> + max_value = last_clamp_value;
> + } else {
> + max_value = uclamp_none(UCLAMP_MIN);
> + }
> + }
> +
> rq->uclamp.value[clamp_id] = max_value;
> }

*groan*, so it could be jet-lag, but I find the comment really hard to
understand.

Would not something like:

/*
* Avoid blocked utilization pushing up the frequency when we go
* idle (which drops the max-clamp) by retaining the last known
* max-clamp.
*/

Be more clear?