* [PATCH 0/2] sched/eevdf: Minor fixes for reweight_entity()
@ 2024-03-04 3:00 Tianchen Ding
2024-03-04 3:00 ` [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting Tianchen Ding
2024-03-04 3:00 ` [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr Tianchen Ding
0 siblings, 2 replies; 7+ messages in thread
From: Tianchen Ding @ 2024-03-04 3:00 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Daniel Bristot de Oliveira, Valentin Schneider, Abel Wu
According to the discussion in [1], fix a calculation bug in
reweight_entity().
[1] https://lore.kernel.org/all/59585184-d13d-46e0-8d68-42838e97a702@bytedance.com/
Tianchen Ding (2):
sched/eevdf: Always update V if se->on_rq when reweighting
sched/eevdf: Fix miscalculation in reweight_entity() when se is not
curr
kernel/sched/fair.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
--
2.39.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting 2024-03-04 3:00 [PATCH 0/2] sched/eevdf: Minor fixes for reweight_entity() Tianchen Ding @ 2024-03-04 3:00 ` Tianchen Ding 2024-03-04 12:06 ` Abel Wu 2024-03-04 3:00 ` [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr Tianchen Ding 1 sibling, 1 reply; 7+ messages in thread From: Tianchen Ding @ 2024-03-04 3:00 UTC (permalink / raw) To: linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider, Abel Wu reweight_eevdf() needs the latest V to do accurate calculation for new ve and vd. So update V unconditionally when se is runnable. Suggested-by: Abel Wu <wuyun.abel@bytedance.com> Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com> --- kernel/sched/fair.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 03be0d1330a6..5551ce2af73e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3790,9 +3790,8 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, if (se->on_rq) { /* commit outstanding execution time */ - if (curr) - update_curr(cfs_rq); - else + update_curr(cfs_rq); + if (!curr) __dequeue_entity(cfs_rq, se); update_load_sub(&cfs_rq->load, se->load.weight); } -- 2.39.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting 2024-03-04 3:00 ` [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting Tianchen Ding @ 2024-03-04 12:06 ` Abel Wu 2024-03-05 2:13 ` Tianchen Ding 0 siblings, 1 reply; 7+ messages in thread From: Abel Wu @ 2024-03-04 12:06 UTC (permalink / raw) To: Tianchen Ding, linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider On 3/4/24 11:00 AM, Tianchen Ding Wrote: > reweight_eevdf() needs the latest V to do accurate calculation for new > ve and vd. So update V unconditionally when se is runnable. As this should come along with commit eab03c23c2a1, I think it would be better add a Fixes tag? > > Suggested-by: Abel Wu <wuyun.abel@bytedance.com> > Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com> > --- > kernel/sched/fair.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 03be0d1330a6..5551ce2af73e 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -3790,9 +3790,8 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, > > if (se->on_rq) { > /* commit outstanding execution time */ > - if (curr) > - update_curr(cfs_rq); > - else > + update_curr(cfs_rq); > + if (!curr) > __dequeue_entity(cfs_rq, se); > update_load_sub(&cfs_rq->load, se->load.weight); > } ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting 2024-03-04 12:06 ` Abel Wu @ 2024-03-05 2:13 ` Tianchen Ding 2024-03-05 3:15 ` Abel Wu 0 siblings, 1 reply; 7+ messages in thread From: Tianchen Ding @ 2024-03-05 2:13 UTC (permalink / raw) To: Abel Wu, linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider On 2024/3/4 20:06, Abel Wu wrote: > On 3/4/24 11:00 AM, Tianchen Ding Wrote: >> reweight_eevdf() needs the latest V to do accurate calculation for new >> ve and vd. So update V unconditionally when se is runnable. > > As this should come along with commit eab03c23c2a1, I think it would > be better add a Fixes tag? > I'm not sure. In fact avg_vruntime_sub() in reweight_entity() was first introduced by af4cf40470c2, and at that time the algorithm about reweight was not completed... ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Re: [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting 2024-03-05 2:13 ` Tianchen Ding @ 2024-03-05 3:15 ` Abel Wu 0 siblings, 0 replies; 7+ messages in thread From: Abel Wu @ 2024-03-05 3:15 UTC (permalink / raw) To: Tianchen Ding, linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider On 3/5/24 10:13 AM, Tianchen Ding Wrote: > On 2024/3/4 20:06, Abel Wu wrote: >> On 3/4/24 11:00 AM, Tianchen Ding Wrote: >>> reweight_eevdf() needs the latest V to do accurate calculation for new >>> ve and vd. So update V unconditionally when se is runnable. >> >> As this should come along with commit eab03c23c2a1, I think it would >> be better add a Fixes tag? >> > > I'm not sure. In fact avg_vruntime_sub() in reweight_entity() was first introduced by af4cf40470c2, and at that time the algorithm about reweight was not completed... > It is because before commit eab03c23c2a1, reweight didn't rely on V. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr 2024-03-04 3:00 [PATCH 0/2] sched/eevdf: Minor fixes for reweight_entity() Tianchen Ding 2024-03-04 3:00 ` [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting Tianchen Ding @ 2024-03-04 3:00 ` Tianchen Ding 2024-03-04 12:06 ` Abel Wu 1 sibling, 1 reply; 7+ messages in thread From: Tianchen Ding @ 2024-03-04 3:00 UTC (permalink / raw) To: linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider, Abel Wu reweight_eevdf() only keeps V unchanged inside itself. When se != cfs_rq->curr, it would be dequeued from rb tree first. So that V is changed and the result is wrong. Pass the original V to reweight_eevdf() to fix this issue. Fixes: eab03c23c2a1 ("sched/eevdf: Fix vruntime adjustment on reweight") Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com> --- kernel/sched/fair.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5551ce2af73e..091a1a750638 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3676,11 +3676,10 @@ static inline void dequeue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { } #endif -static void reweight_eevdf(struct cfs_rq *cfs_rq, struct sched_entity *se, +static void reweight_eevdf(struct sched_entity *se, u64 avruntime, unsigned long weight) { unsigned long old_weight = se->load.weight; - u64 avruntime = avg_vruntime(cfs_rq); s64 vlag, vslice; /* @@ -3787,10 +3786,12 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, unsigned long weight) { bool curr = cfs_rq->curr == se; + u64 avruntime; if (se->on_rq) { /* commit outstanding execution time */ update_curr(cfs_rq); + avruntime = avg_vruntime(cfs_rq); if (!curr) __dequeue_entity(cfs_rq, se); update_load_sub(&cfs_rq->load, se->load.weight); @@ -3804,7 +3805,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, */ se->vlag = div_s64(se->vlag * se->load.weight, weight); } else { - reweight_eevdf(cfs_rq, se, weight); + reweight_eevdf(se, avruntime, weight); } update_load_set(&se->load, weight); -- 2.39.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr 2024-03-04 3:00 ` [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr Tianchen Ding @ 2024-03-04 12:06 ` Abel Wu 0 siblings, 0 replies; 7+ messages in thread From: Abel Wu @ 2024-03-04 12:06 UTC (permalink / raw) To: Tianchen Ding, linux-kernel Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman, Daniel Bristot de Oliveira, Valentin Schneider On 3/4/24 11:00 AM, Tianchen Ding Wrote: > reweight_eevdf() only keeps V unchanged inside itself. When se != > cfs_rq->curr, it would be dequeued from rb tree first. So that V is > changed and the result is wrong. Pass the original V to reweight_eevdf() > to fix this issue. > > Fixes: eab03c23c2a1 ("sched/eevdf: Fix vruntime adjustment on reweight") > Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com> > --- > kernel/sched/fair.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 5551ce2af73e..091a1a750638 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -3676,11 +3676,10 @@ static inline void > dequeue_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *se) { } > #endif > > -static void reweight_eevdf(struct cfs_rq *cfs_rq, struct sched_entity *se, > +static void reweight_eevdf(struct sched_entity *se, u64 avruntime, > unsigned long weight) > { > unsigned long old_weight = se->load.weight; > - u64 avruntime = avg_vruntime(cfs_rq); > s64 vlag, vslice; > > /* > @@ -3787,10 +3786,12 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, > unsigned long weight) > { > bool curr = cfs_rq->curr == se; > + u64 avruntime; > > if (se->on_rq) { > /* commit outstanding execution time */ > update_curr(cfs_rq); > + avruntime = avg_vruntime(cfs_rq); > if (!curr) > __dequeue_entity(cfs_rq, se); > update_load_sub(&cfs_rq->load, se->load.weight); > @@ -3804,7 +3805,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, > */ > se->vlag = div_s64(se->vlag * se->load.weight, weight); > } else { > - reweight_eevdf(cfs_rq, se, weight); > + reweight_eevdf(se, avruntime, weight); > } > > update_load_set(&se->load, weight); Reviewed-by: Abel Wu <wuyun.abel@bytedance.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-03-05 3:16 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-03-04 3:00 [PATCH 0/2] sched/eevdf: Minor fixes for reweight_entity() Tianchen Ding 2024-03-04 3:00 ` [PATCH 1/2] sched/eevdf: Always update V if se->on_rq when reweighting Tianchen Ding 2024-03-04 12:06 ` Abel Wu 2024-03-05 2:13 ` Tianchen Ding 2024-03-05 3:15 ` Abel Wu 2024-03-04 3:00 ` [PATCH 2/2] sched/eevdf: Fix miscalculation in reweight_entity() when se is not curr Tianchen Ding 2024-03-04 12:06 ` Abel Wu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox