Re: [PATCH v2 03/13] sched/pelt: Add a new function to approximate runtime to reach given util
From: Vincent Guittot
Date: Thu Jun 04 2026 - 05:03:56 EST
On Mon, 4 May 2026 at 04:00, Qais Yousef <qyousef@xxxxxxxxxxx> 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 <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 5a8f4dc99ffc..dbd450798b03 100644
> --- a/kernel/sched/pelt.c
> +++ b/kernel/sched/pelt.c
> @@ -508,3 +508,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.
Why ms when we use us or ns everywhere else
> + */
> +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, 1, 0, 1);
> + ___update_load_avg(&sa, 0);
> + runtime++;
> + }
> +
> + return runtime;
> +}
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 190515b50dc8..a445add5cc3a 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3528,6 +3528,7 @@ unsigned long sugov_effective_cpu_perf(int cpu, unsigned long actual,
> unsigned long max);
>
> unsigned long approximate_util_avg(unsigned long util, u64 delta);
> +u64 approximate_runtime(unsigned long util);
>
> /*
> * Verify the fitness of task @p to run on @cpu taking into account the
> --
> 2.34.1
>