Skip to content

Commit 72bffbf

Browse files
daweilicsIngo Molnar
authored andcommitted
sched/fair: Fix initial util_avg calculation
Change se->load.weight to se_weight(se) in the calculation for the initial util_avg to avoid unnecessarily inflating the util_avg by 1024 times. The reason is that se->load.weight has the unit/scale as the scaled-up load, while cfs_rg->avg.load_avg has the unit/scale as the true task weight (as mapped directly from the task's nice/priority value). With CONFIG_32BIT, the scaled-up load is equal to the true task weight. With CONFIG_64BIT, the scaled-up load is 1024 times the true task weight. Thus, the current code may inflate the util_avg by 1024 times. The follow-up capping will not allow the util_avg value to go wild. But the calculation should have the correct logic. Signed-off-by: Dawei Li <daweilics@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Reviewed-by: Vishal Chourasia <vishalc@linux.ibm.com> Link: https://lore.kernel.org/r/20240315015916.21545-1-daweilics@gmail.com
1 parent 0f1c74b commit 72bffbf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/sched/fair.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ void init_entity_runnable_average(struct sched_entity *se)
10311031
* With new tasks being created, their initial util_avgs are extrapolated
10321032
* based on the cfs_rq's current util_avg:
10331033
*
1034-
* util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight
1034+
* util_avg = cfs_rq->avg.util_avg / (cfs_rq->avg.load_avg + 1)
1035+
* * se_weight(se)
10351036
*
10361037
* However, in many cases, the above util_avg does not give a desired
10371038
* value. Moreover, the sum of the util_avgs may be divergent, such
@@ -1078,7 +1079,7 @@ void post_init_entity_util_avg(struct task_struct *p)
10781079

10791080
if (cap > 0) {
10801081
if (cfs_rq->avg.util_avg != 0) {
1081-
sa->util_avg = cfs_rq->avg.util_avg * se->load.weight;
1082+
sa->util_avg = cfs_rq->avg.util_avg * se_weight(se);
10821083
sa->util_avg /= (cfs_rq->avg.load_avg + 1);
10831084

10841085
if (sa->util_avg > cap)

0 commit comments

Comments
 (0)