Re: [PATCH] sched/pelt: sync util/runnable_sum with PELT window when propagating

From: Dietmar Eggemann
Date: Fri Apr 24 2020 - 05:06:43 EST




On 24/04/2020 10:54, Vincent Guittot wrote:
> On Fri, 24 Apr 2020 at 10:41, Dietmar Eggemann <dietmar.eggemann@xxxxxxx> wrote:
>>
>> On 24/04/2020 09:37, Vincent Guittot wrote:
>>> On Thu, 23 Apr 2020 at 21:29, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>>>>
>>>> On Wed, Apr 22, 2020 at 05:14:01PM +0200, Vincent Guittot wrote:

[...]

>>>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>>>>> index 02f323b85b6d..ca6aa89c88f2 100644
>>>>> --- a/kernel/sched/fair.c
>>>>> +++ b/kernel/sched/fair.c
>>>>> @@ -3441,52 +3441,38 @@ static inline void
>>>>> update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq)
>>>>> {
>>>>> long delta = gcfs_rq->avg.util_avg - se->avg.util_avg;
>>>>> + u32 divider = LOAD_AVG_MAX - 1024 + cfs_rq->avg.period_contrib;
>>>>>
>>>>> /* Nothing to update */
>>>>> if (!delta)
>>>>> return;
>>>>>
>>>>> - /*
>>>>> - * The relation between sum and avg is:
>>>>> - *
>>>>> - * LOAD_AVG_MAX - 1024 + sa->period_contrib
>>>>> - *
>>>>> - * however, the PELT windows are not aligned between grq and gse.
>>>>> - */
>>>>
>>>> Instead of deleting this, could we perhaps extend it?
>>>
>>> In fact, this is not the only place in fair.c that uses this rule to
>>> align _avg and _sum but others don't have any special comment.
>>>
>>> I can add a more detailed description of this relation for
>>> ___update_load_avg() in pelt.c and make a ref to this in all places in
>>> fair.c that use this rule which are :
>>> - update_tg_cfs_util
>>> - update_tg_cfs_runnable
>>> - update_cfs_rq_load_avg
>>> - attach_entity_load_avg
>>> - reweight_entity
>>
>> But IMHO the
>>
>> "* however, the PELT windows are not aligned between grq and gse."
>>
>> should only apply to update_tg_cfs_util() and update_tg_cfs_runnable().
>> And attach_entity_load_avg() (for cfs_rq and se).
>>
>> They seem to be special since we derive divider from a cfs_rq PELT value
>> and use it for a se PELT value.
>
> hmmm... There is nothing special here.
>
> When se is attached to cfs_rq, they both have the same divider because
> they use the same clock.

That's true.

But exactly this might deserve this comment. Otherwise people might
wonder why you can do a

u32 divider = LOAD_AVG_MAX - 1024 + *cfs_rq*->avg.period_contrib;

and use it for instance in:

*se*->avg.util_sum = se->avg.util_avg * divider;

In update_cfs_rq_load_avg() and reweight_entity() we derive 'divider'
from the same 'sched_avg' we use it on later.

u32 divider = LOAD_AVG_MAX - 1024 + sa->period_contrib;

sub_positive(&sa->load_sum, r * divider);

[...]