sched/fair: Fix the util_avg_cap formula in a comment
PATCH 1/1 sched/fair: Fix the util_avg_cap formula in a comment
The comment documents the initial util_avg cap for a new task as:
util_avg_cap = (cpu_scale - cfs_rq->avg.util_avg) / 2^n
but the code caps it at half of the remaining budget:
cap = (long)(cpu_scale - cfs_rq->avg.util_avg) / 2;
The "/ 2^n" form matches neither the code nor the comment's own worked
example: for the 2nd task with a cfs_rq util_avg of 512 on a 1024-capacity CPU it would give (1024 - 512) / 2^2 = 128, whereas both the code and the tabulated example give (1024 - 512) / 2 = 256.
The cpu_scale / 2^n progression shown in the example instead emerges from applying the per-task "/ 2" cap repeatedly, since cfs_rq->avg.util_avg accumulates the previously created tasks. Correct the formula to match the code and note where the 2^n series comes from.
Fixes 2b8c41daba32 ("sched/fair: Fix initial util_avg calculation")
Signed-off-by Zhan Xusheng <[email protected]>
--- kernel/sched/fair.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/fair.c +4 -2
@@ -1299,9 +1299,11 @@ void init_entity_runnable_average(struct sched_entity *se)* To solve this problem, we also cap the util_avg of successive tasks to * only 1/2 of the left utilization budget: * -* util_avg_cap = (cpu_scale - cfs_rq->avg.util_avg) / 2^n +* util_avg_cap = (cpu_scale - cfs_rq->avg.util_avg) / 2 * -* where n denotes the nth task and cpu_scale the CPU capacity. +* where cpu_scale is the CPU capacity. Since cfs_rq->avg.util_avg +* accumulates the previously created tasks, applying this cap to each new +* task gives the nth task a util_avg_cap of cpu_scale / 2^n. * * For example, for a CPU with 1024 of capacity, a simplest series from * the beginning would be like:
Signature · 1 line
2.43.0