[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87f1feec-1be5-4d24-a206-e30238072ae1@bytedance.com>
Date: Wed, 11 Oct 2023 20:00:22 +0800
From: Abel Wu <wuyun.abel@...edance.com>
To: Peter Zijlstra <peterz@...radead.org>, mingo@...nel.org,
vincent.guittot@...aro.org
Cc: linux-kernel@...r.kernel.org, juri.lelli@...hat.com,
dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
mgorman@...e.de, bristot@...hat.com, corbet@....net,
qyousef@...alina.io, chris.hyser@...cle.com,
patrick.bellasi@...bug.net, pjt@...gle.com, pavel@....cz,
qperret@...gle.com, tim.c.chen@...ux.intel.com, joshdon@...gle.com,
timj@....org, kprateek.nayak@....com, yu.c.chen@...el.com,
youssefesmat@...omium.org, joel@...lfernandes.org, efault@....de,
tglx@...utronix.de
Subject: Re: [PATCH 03/15] sched/fair: Add lag based placement
On 5/31/23 7:58 PM, Peter Zijlstra Wrote:
> /*
> - * Halve their sleep time's effect, to allow
> - * for a gentler effect of sleepers:
> + * If we want to place a task and preserve lag, we have to
> + * consider the effect of the new entity on the weighted
> + * average and compensate for this, otherwise lag can quickly
> + * evaporate.
> + *
> + * Lag is defined as:
> + *
> + * lag_i = S - s_i = w_i * (V - v_i)
> + *
> + * To avoid the 'w_i' term all over the place, we only track
> + * the virtual lag:
> + *
> + * vl_i = V - v_i <=> v_i = V - vl_i
> + *
> + * And we take V to be the weighted average of all v:
> + *
> + * V = (\Sum w_j*v_j) / W
> + *
> + * Where W is: \Sum w_j
> + *
> + * Then, the weighted average after adding an entity with lag
> + * vl_i is given by:
> + *
> + * V' = (\Sum w_j*v_j + w_i*v_i) / (W + w_i)
> + * = (W*V + w_i*(V - vl_i)) / (W + w_i)
> + * = (W*V + w_i*V - w_i*vl_i) / (W + w_i)
> + * = (V*(W + w_i) - w_i*l) / (W + w_i)
> + * = V - w_i*vl_i / (W + w_i)
> + *
> + * And the actual lag after adding an entity with vl_i is:
> + *
> + * vl'_i = V' - v_i
> + * = V - w_i*vl_i / (W + w_i) - (V - vl_i)
> + * = vl_i - w_i*vl_i / (W + w_i)
> + *
> + * Which is strictly less than vl_i. So in order to preserve lag
Maybe a stupid question, but why vl'_i < vl_i? Since vl_i can be negative.
> + * we should inflate the lag before placement such that the
> + * effective lag after placement comes out right.
> + *
> + * As such, invert the above relation for vl'_i to get the vl_i
> + * we need to use such that the lag after placement is the lag
> + * we computed before dequeue.
> + *
> + * vl'_i = vl_i - w_i*vl_i / (W + w_i)
> + * = ((W + w_i)*vl_i - w_i*vl_i) / (W + w_i)
> + *
> + * (W + w_i)*vl'_i = (W + w_i)*vl_i - w_i*vl_i
> + * = W*vl_i
> + *
> + * vl_i = (W + w_i)*vl'_i / W
> */
> - if (sched_feat(GENTLE_FAIR_SLEEPERS))
> - thresh >>= 1;
> + load = cfs_rq->avg_load;
> + if (curr && curr->on_rq)
> + load += curr->load.weight;
>
> - vruntime -= thresh;
> + lag *= load + se->load.weight;
> + if (WARN_ON_ONCE(!load))
> + load = 1;
> + lag = div_s64(lag, load);
> +
> + vruntime -= lag;
> }
Powered by blists - more mailing lists