Re: [PATCH v3 03/10] sched/pelt: Add a new function to approximate runtime to reach given util

From: Qais Yousef

Date: Mon Nov 30 2026 - 19:35:56 EST


On 11/26/26 18:50, Li kunyu wrote:
> 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

Yeah period might be a better name. Delta is the usual input to
accumulate_sum().

> 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;

I kept it a literal so that compiler hopefully would turn this into << 10.

I guess it can still see the variable is constant and do that.

>
> > +}
>
> Would the overall effect be better this way? Or is my understanding somewhat off?

Valid suggestion. I'll take it into account.

Thanks!