From: Peng Wang <rocking@linux.alibaba.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] sched/eevdf: Improve the clarity of the lag-based placement comments
Date: Fri, 16 Aug 2024 18:17:30 +0800 [thread overview]
Message-ID: <4c99af2c8d9b35ccdab66163c3ac256e3e95d5c0.1723802710.git.rocking@linux.alibaba.com> (raw)
In the original comments, the derivation starts with preserving v_i to
calculate V' and uses the equation v_i = V - vl_i. However, tasks might
have migrated from other queues, which means that the relationship with
this queue's V does not necessarily hold.
The new derivation is based on keeping vl_i unchanged and derives from the
post-enqueue perspective, thereby avoiding the previous assumption.
Signed-off-by: Peng Wang <rocking@linux.alibaba.com>
---
kernel/sched/fair.c | 56 +++++++++++++++------------------------------
1 file changed, 19 insertions(+), 37 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 9057584ec06d..2bfae2ca2bb6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5196,56 +5196,38 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
lag = se->vlag;
/*
- * If we want to place a task and preserve lag, we have to
+ * If we want to place a task i 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:
+ * Avg-Load VRuntime Avg-VRuntime Vlag
+ * before W v_i V vl_i
+ * after W+w_i v_i' V' vl_i
*
- * lag_i = S - s_i = w_i * (V - v_i)
+ * We want to preserve lag, so vl_i wil not change:
*
- * 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 (1)
*
- * vl_i = V - v_i <=> v_i = V - vl_i
+ * We take V' to be the weighted average of all v'
*
- * And we take V to be the weighted average of all v:
+ * V' = (W*V + w_i*v_i') / (W + w_i)
+ * ==> (W + w_i)*V' = W*V + w_i*v_i' (2)
*
- * V = (\Sum w_j*v_j) / W
+ * by using (1) & (2) we obtain:
*
- * Where W is: \Sum w_j
+ * (W + w_i)*V' = W*V + w_i*(V' - vl_i)
+ * ==> W*V' = W*V -w_i*vl_i
+ * ==> V' = V - w_i*vl_i/W (3)
*
- * Then, the weighted average after adding an entity with lag
- * vl_i is given by:
+ * by using (1) & (3) we obtain:
*
- * 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)
+ * v_i' = V - w_i*vl_i/W - vl_i
+ * = V - (w_i*vl_i/W + vl_i)
+ * = V - (w_i*vl_i + W*vl_i)/W
+ * = V - vl_i*(w_i + W)/W
*
- * 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
- * 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
*/
load = cfs_rq->avg_load;
if (curr && curr->on_rq)
--
2.27.0
reply other threads:[~2024-08-16 10:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4c99af2c8d9b35ccdab66163c3ac256e3e95d5c0.1723802710.git.rocking@linux.alibaba.com \
--to=rocking@linux.alibaba.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®