Re: [RFC PATCH 2/7] sched/pelt: Add a new function to approximate runtime to reach given util

From: Dietmar Eggemann
Date: Wed Sep 06 2023 - 16:44:26 EST


On 06/09/2023 14:56, Dietmar Eggemann wrote:
> On 28/08/2023 01:31, Qais Yousef wrote:
>> It is basically the ramp-up time from 0 to a given value. Will be used
>> later to implement new tunable to control response time for schedutil.
>>
>> Signed-off-by: Qais Yousef (Google) <qyousef@xxxxxxxxxxx>
>> ---
>> kernel/sched/pelt.c | 21 +++++++++++++++++++++
>> kernel/sched/sched.h | 1 +
>> 2 files changed, 22 insertions(+)
>>
>> diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c
>> index 50322005a0ae..f673b9ab92dc 100644
>> --- a/kernel/sched/pelt.c
>> +++ b/kernel/sched/pelt.c
>> @@ -487,3 +487,24 @@ unsigned long approximate_util_avg(unsigned long util, u64 delta)
>>
>> return sa.util_avg;
>> }
>> +
>> +/*
>> + * Approximate the required amount of runtime in ms required to reach @util.
>> + */
>> +u64 approximate_runtime(unsigned long util)
>> +{
>> + struct sched_avg sa = {};
>> + u64 delta = 1024; // period = 1024 = ~1ms
>> + u64 runtime = 0;
>> +
>> + if (unlikely(!util))
>> + return runtime;
>> +
>> + while (sa.util_avg < util) {
>> + accumulate_sum(delta, &sa, 0, 0, 1);
>> + ___update_load_avg(&sa, 0);
>> + runtime++;
>> + }
>> +
>> + return runtime;
>> +}
>
> S_n = S_inv * (1 - 0.5^(t/hl))
>
> t = hl * ln(1 - Sn/S_inv)/ln(0.5)
>
> (1) for a little CPU (capacity_orig = 446)
>
> t = 32ms * ln(1 - 446/1024)/ln(0.5)
>
> t = 26ms
>
> (2) for a big CPU (capacity = 1023 (*instead of 1024 since ln(0) not
> defined
>
> t = 32ms * ln(1 - 1023/1024)/ln(0.5)
>
> t = 320ms

Forgot half of what I wanted to ask:

And you want to be able to have a schedutil interface:

/sys/devices/system/cpu/cpufreq/policy*/schedutil/response_time_ms

in which by default we have 26ms for a CPU with the capacity_orig of 446.

I.e. you want to have a time-based interface there? Which the user can
overwrite, say with 52ms and this then will lower the return value of
get_next_freq() so the system will respond slower?

And the time based interface is more intuitive than staying in the
capacity world of [0-1024]?