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

From: Dietmar Eggemann
Date: Thu Sep 07 2023 - 14:22:00 EST


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. 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.
>>
>>> + ___update_load_avg(&sa, 0);
>>> +
>>> + return sa.util_avg;
>>> +}
>>
>> We already discussed something similar like this in Nov 22, the so
>> called UTIL_EST_FASTER thing.
>>
>> https://lkml.kernel.org/r/Y2kLA8x40IiBEPYg@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>> +/*
>> + * Compute a pelt util_avg assuming no history and @delta runtime.
>> + */
>> +unsigned long faster_est_approx(u64 delta)
>> +{
>> + unsigned long contrib = (unsigned long)delta; /* p == 0 -> delta < 1024 */
>> + u64 periods = delta / 1024;
>> +
>> + if (periods) {
>> + delta %= 1024;
>> + contrib = __accumulate_pelt_segments(periods, 1024, delta);
>> + }
>> +
>> + return (contrib << SCHED_CAPACITY_SHIFT) / PELT_MIN_DIVIDER;
>> +}
>> +
>
> I could look at using this version instead. This misses the decay part though?

__accumulate_pelt_segments(periods, ...) decays the periods. But
obviously not the util you pass into approximate_util_avg().