[PATCH] sched/fair: updates weight of cfs_rq before update_cfs_group() in enqueue_entity()

From: pugaowei
Date: Thu May 30 2024 - 23:08:57 EST


we should update the weight of cfs_rq before update_cfs_group().
Ensure that we can get accurate shares of the cfs_rq when its
weights changes. we can find this work was done correctly in
dequeue_entity(). so fix it.

Signed-off-by: pugaowei <pugaowei@xxxxxxxx>
---
kernel/sched/fair.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8a5b1ae0aa55..395840f3fa1d 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5304,6 +5304,12 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
*/
update_load_avg(cfs_rq, se, UPDATE_TG | DO_ATTACH);
se_update_runnable(se);
+
+ /*
+ * we should update the weight of cfs_rq before update_cfs_group.
+ * Ensure we can get accurate shares of the cfs_rq when its weights changes.
+ */
+ account_entity_enqueue(cfs_rq, se);
/*
* XXX update_load_avg() above will have attached us to the pelt sum;
* but update_cfs_group() here will re-adjust the weight and have to
@@ -5318,8 +5324,6 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
if (!curr)
place_entity(cfs_rq, se, flags);

- account_entity_enqueue(cfs_rq, se);
-
/* Entity has migrated, no longer consider this task hot */
if (flags & ENQUEUE_MIGRATED)
se->exec_start = 0;
--
2.17.1