Skip to content

Commit 7ceb771

Browse files
vingu-linaroPeter Zijlstra
authored andcommitted
sched/pelt: Continue to relax the sync of util_sum with util_avg
Rick reported performance regressions in bugzilla because of cpu frequency being lower than before: https://bugzilla.kernel.org/show_bug.cgi?id=215045 He bisected the problem to: commit 1c35b07 ("sched/fair: Ensure _sum and _avg values stay consistent") This commit forces util_sum to be synced with the new util_avg after removing the contribution of a task and before the next periodic sync. By doing so util_sum is rounded to its lower bound and might lost up to LOAD_AVG_MAX-1 of accumulated contribution which has not yet been reflected in util_avg. update_tg_cfs_util() is not the only place where we round util_sum and lost some accumulated contributions that are not already reflected in util_avg. Modify update_tg_cfs_util() and detach_entity_load_avg() to not sync util_sum with the new util_avg. Instead of always setting util_sum to the low bound of util_avg, which can significantly lower the utilization, we propagate the difference. In addition, we also check that cfs's util_sum always stays above the lower bound for a given util_avg as it has been observed that sched_entity's util_sum is sometimes above cfs one. Signed-off-by: Vincent Guittot <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Dietmar Eggemann <[email protected]> Tested-by: Sachin Sant <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 98b0d89 commit 7ceb771

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

kernel/sched/fair.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,11 +3451,11 @@ void set_task_rq_fair(struct sched_entity *se,
34513451
static inline void
34523452
update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq *gcfs_rq)
34533453
{
3454-
long delta = gcfs_rq->avg.util_avg - se->avg.util_avg;
3455-
u32 divider;
3454+
long delta_sum, delta_avg = gcfs_rq->avg.util_avg - se->avg.util_avg;
3455+
u32 new_sum, divider;
34563456

34573457
/* Nothing to update */
3458-
if (!delta)
3458+
if (!delta_avg)
34593459
return;
34603460

34613461
/*
@@ -3464,13 +3464,20 @@ update_tg_cfs_util(struct cfs_rq *cfs_rq, struct sched_entity *se, struct cfs_rq
34643464
*/
34653465
divider = get_pelt_divider(&cfs_rq->avg);
34663466

3467+
34673468
/* Set new sched_entity's utilization */
34683469
se->avg.util_avg = gcfs_rq->avg.util_avg;
3469-
se->avg.util_sum = se->avg.util_avg * divider;
3470+
new_sum = se->avg.util_avg * divider;
3471+
delta_sum = (long)new_sum - (long)se->avg.util_sum;
3472+
se->avg.util_sum = new_sum;
34703473

34713474
/* Update parent cfs_rq utilization */
3472-
add_positive(&cfs_rq->avg.util_avg, delta);
3473-
cfs_rq->avg.util_sum = cfs_rq->avg.util_avg * divider;
3475+
add_positive(&cfs_rq->avg.util_avg, delta_avg);
3476+
add_positive(&cfs_rq->avg.util_sum, delta_sum);
3477+
3478+
/* See update_cfs_rq_load_avg() */
3479+
cfs_rq->avg.util_sum = max_t(u32, cfs_rq->avg.util_sum,
3480+
cfs_rq->avg.util_avg * PELT_MIN_DIVIDER);
34743481
}
34753482

34763483
static inline void
@@ -3790,7 +3797,11 @@ static void detach_entity_load_avg(struct cfs_rq *cfs_rq, struct sched_entity *s
37903797

37913798
dequeue_load_avg(cfs_rq, se);
37923799
sub_positive(&cfs_rq->avg.util_avg, se->avg.util_avg);
3793-
cfs_rq->avg.util_sum = cfs_rq->avg.util_avg * divider;
3800+
sub_positive(&cfs_rq->avg.util_sum, se->avg.util_sum);
3801+
/* See update_cfs_rq_load_avg() */
3802+
cfs_rq->avg.util_sum = max_t(u32, cfs_rq->avg.util_sum,
3803+
cfs_rq->avg.util_avg * PELT_MIN_DIVIDER);
3804+
37943805
sub_positive(&cfs_rq->avg.runnable_avg, se->avg.runnable_avg);
37953806
cfs_rq->avg.runnable_sum = cfs_rq->avg.runnable_avg * divider;
37963807

0 commit comments

Comments
 (0)