sched/fair.c: Fix the calculation method of 'lag' to ensure that the vlag of the task after placement is the same as before.
PATCH 1/1 sched/fair.c: Fix the calculation method of 'lag' to ensure that the vlag of the task after placement is the same as before.
From: hupu <[email protected]>
I think the 'lag' calculation here is inaccurate.
Assume that delta needs to be subtracted from v_i to ensure that the vlag of task i after placement is the same as before. At this time, the vlag of task i after placement should be:
vl'_i = V' - (v_i - delta)
From the above formula, we know that vl'_i should be:
vl'_i = (vl_i * W)/(W + w_i)
That is to say:
V' - (v_i - delta) = (vl_i * W)/(W + w_i)
For a newly added entity, generally set v_i to V', and the above formula can be converted into:
V' - (V' - delta) = (vl_i * W)/(W + w_i)
Therefore the value of delta should be as follows, where delta is the 'lag' in the code.
delta = (vl_i * W)/(W + w_i)
--- kernel/sched/fair.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/sched/fair.c +4 -1
@@ -5239,9 +5239,12 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)if (curr && curr->on_rq) load +=scale_load_down (curr->load.weight); - lag *= load +scale_load_down (se->load.weight); + lag *= load; + + load +=scale_load_down (se->load.weight);if (WARN_ON_ONCE (!load)) load =1 ; + lag =div_s64 (lag, load); }
Signature · 1 line
2.17.1
Peter Zijlstra
maintainerQuoted 6 lines · On Tue, Apr 23, 2024 at 07:44:16PM +0800, [email protected] wrote:
From: hupu <[email protected]>
I think the 'lag' calculation here is inaccurate.
Assume that delta needs to be subtracted from
v_ito ensure that the vlag of task i after placement is the same as before.
Why ?!? v_i is the unkown, it makes no sense to complicate things by adding extra unknowns.
Quoted 3 lines
At this time, the
vlag of task i after placement should be:
vl'_i = V' - (v_i- delta)
But but but, you can't have V' without knowing v_i.
Quoted 25 lines
From the above formula, we know that vl'_i should be:
vl'_i = (vl_i* W)/(W +w_i)That is to say:
V' - (v_i- delta) = (vl_i* W)/(W +w_i)For a newly added entity, generally set
v_ito V', and the above formula can be converted into:
V' - (V' - delta) = (vl_i* W)/(W +w_i)Therefore the value of delta should be as follows, where delta is the 'lag' in the code.
delta = (vl_i* W)/(W +w_i)Signed-off-by hupu <[email protected]>--- kernel/sched/fair.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)kernel/sched/fair.c +0
-0@@ -5239,9 +5239,12 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)if (curr && curr->on_rq)
kernel/sched/fair.c place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) · line 5248
Quoted 10 lines
kernel/sched/fair.c +4
-1load +=scale_load_down (curr->load.weight); - lag *= load +scale_load_down (se->load.weight); + lag *= load; + + load +=scale_load_down (se->load.weight);if (WARN_ON_ONCE (!load)) load =1 ; + lag =div_s64 (lag, load);
You're making it:
v_i = V - (W * vl_i) / (W + w_i)
In direct contradiction to the giant comment right above this that explains why the code is as it is.
Quoted 5 lines
kernel/sched/fair.c +0
-0}Signature · 1 line
2.17.1
Peter Zijlstra
maintainerRe: [PATCH] sched/fair.c: Fix the calculation method of 'lag'
Quoted 14 lines · On Thu, Apr 25, 2024 at 07:44:59PM +0800, [email protected] wrote:
Quoted 14 lines
Quoted 6 lines
From: hupu <[email protected]>
I think the 'lag' calculation here is inaccurate.
Assume that delta needs to be subtracted from
v_ito ensure that the vlag of task i after placement is the same as before.Why ?!?
v_iis the unkown, it makes no sense to complicate things by adding extra unknowns.Quoted 3 lines
At this time, the
vlag of task i after placement should be:
vl'_i = V' - (v_i- delta)
Quoted 6 lines
Quoted 2 lines
But but but, you can't have V' without knowing
v_i.Thank you for your patient guidance. I overlooked a important fact that
v_iis unknown in the process of proof. Below is the complete proof process, and it turns out that you are correct.
*phew*, thanks for checking!