Re: [RFC PATCH 1/7] sched/pelt: Add a new function to approximate the future util_avg value

Qais Yousef
2023-09-10T19:58:39Z

On 09/07/23 13:12, Dietmar Eggemann wrote:
> On 06/09/2023 23:19, Qais Yousef wrote:
> > On 09/06/23 14:56, Dietmar Eggemann wrote:
> >> On 28/08/2023 01:31, Qais Yousef wrote:
>
> [...]
>
> >>> +/*
> >>> + * Approximate the new util_avg value assuming an entity has continued to run
> >>> + * for @delta us.
> >>> + */
> >>> +unsigned long approximate_util_avg(unsigned long util, u64 delta)
> >>> +{
> >>> + struct sched_avg sa = {
> >>> + .util_sum = util * PELT_MIN_DIVIDER,
> >>> + .util_avg = util,
> >>> + };
> >>> +
> >>> + if (unlikely(!delta))
> >>> + return util;
> >>> +
> >>> + accumulate_sum(delta, &sa, 0, 0, 1);
> >>
> >> IMHO, you miss the handling of `periods != 0`. load = 0 eclipses this
> >> code in accumulate_sum().
>
> You could call accumulate_sum(delta, &sa, 1, 0, 1);

Yes. I initially thought the load is not necessary, but good catch. I didn't
get a chance to rerun to see the numbers, but hopefully this should fix the
wrong numbers I was seeing. Thanks!

>
> >
> > Yes. For some reason I got blank registered when I saw if this codepath can
> > impact util_avg..
>
> Another thing ... I guess if you call accumulate_sum with delta the PELT
> machinery assumes `delta = now - sa->last_update_time` which means you
> would have to use `clock_pelt + TICK_USEC` as delta.

Right.

The way I understood it is that at TICK we should do update_load_avg() which
would call __update_load_sum() which uses

delta = now - sa->last_update_time

which passes this delta to accumulate_sum()

I can see we are not very accurate since there will be a small additional time
besides TICK_USEC that we are not accounting for. But I can't see how this can
cause a big error.

predicted (assumed) tick time/delta

sa->last_update_time = now
tick_time = TICK_USEC + now

delta = tick_time - sa->last_update_time
delta = TICK_USEC + now - now
delta = TICK_USEC

but actual tick time/delta

sa->last_update_time = now - x
tick_time = TICK_USEC + now

delta = tick_time - sa->last_update_time
delta = TICK_USEC + now - (now - x)
delta = TICK_USEC + x

So the delta I am using might be slightly shorter than it should be.

IIUC, what you're saying that the `x` in my equation above is clock_pelt,
right?

Thanks!

--
Qais Yousef