Re: [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util
From: Li kunyu
Date: Thu Nov 26 2026 - 05:50:16 EST
Hi Qais,
On 2026/11/26 13:14, Qais Yousef wrote:
> +
> +/*
> + * Approximate the required amount of runtime in us required to reach @util.
> + */
> +u64 approximate_runtime(unsigned long util)
> +{
> + struct sched_avg sa = {};
> + u64 delta = 1024; // period = 1024 = ~1ms
Would it be clearer to name this period as the base unit? A delta of 1024
corresponds to one full period:
u64 period = 1024; /* one period = 1024 delta units */
> + u64 runtime = 0;
> +
> + if (unlikely(!util))
> + return runtime;
> +
> + if (unlikely(WARN_ON_ONCE(util > SCHED_CAPACITY_SCALE)))
> + util = SCHED_CAPACITY_SCALE;
> +
> + while (sa.util_avg < util) {
> + accumulate_sum(delta, &sa, 1, 0, 1);
accumulate_sum(period, &sa, 1, 0, 1);
> + ___update_load_avg(&sa, 0);
> + runtime++;
> + }
> +
> + return runtime * 1024;
return runtime * period;
> +}
Would the overall effect be better this way? Or is my understanding somewhat off?
--
thanks,
kunyu