All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair.c: Fix the calculation method of 'lag' to ensure  that the vlag of the task after placement is the same as before.
@ 2024-04-23 11:44 hupu
  2024-04-25 11:44   ` [PATCH] sched/fair.c: Fix the calculation method of 'lag' hupu
  0 siblings, 1 reply; 4+ messages in thread
From: hupu @ 2024-04-23 11:44 UTC (permalink / raw)
  To: peterz, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel
  Cc: hupu

From: hupu <hupu@oppo.com>

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)

Signed-off-by: hupu <hupu@oppo.com>
---
 kernel/sched/fair.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 03be0d1330a6..c5f74f753be8 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -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);
 	}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-25 11:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23 11:44 [PATCH] sched/fair.c: Fix the calculation method of 'lag' to ensure that the vlag of the task after placement is the same as before hupu
2024-04-24  8:55 ` Peter Zijlstra
2024-04-25 11:44   ` [PATCH] sched/fair.c: Fix the calculation method of 'lag' hupu
2024-04-25 11:51   ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.