Skip to content

Commit d5bb20c

Browse files
vingu-linarogregkh
authored andcommitted
sched/fair: Fix enqueue_task_fair warning
commit fe61468 upstream. When a cfs rq is throttled, the latter and its child are removed from the leaf list but their nr_running is not changed which includes staying higher than 1. When a task is enqueued in this throttled branch, the cfs rqs must be added back in order to ensure correct ordering in the list but this can only happens if nr_running == 1. When cfs bandwidth is used, we call unconditionnaly list_add_leaf_cfs_rq() when enqueuing an entity to make sure that the complete branch will be added. Similarly unthrottle_cfs_rq() can stop adding cfs in the list when a parent is throttled. Iterate the remaining entity to ensure that the complete branch will be added in the list. Reported-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Tested-by: Christian Borntraeger <borntraeger@de.ibm.com> Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Cc: stable@vger.kernel.org Cc: stable@vger.kernel.org #v5.1+ Link: https://lkml.kernel.org/r/20200306135257.25044-1-vincent.guittot@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e9f3847 commit d5bb20c

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

‎kernel/sched/fair.c‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,7 @@ static inline void check_schedstat_required(void)
39433943
#endif
39443944
}
39453945

3946+
static inline bool cfs_bandwidth_used(void);
39463947

39473948
/*
39483949
* MIGRATION
@@ -4021,10 +4022,16 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
40214022
__enqueue_entity(cfs_rq, se);
40224023
se->on_rq = 1;
40234024

4024-
if (cfs_rq->nr_running == 1) {
4025+
/*
4026+
* When bandwidth control is enabled, cfs might have been removed
4027+
* because of a parent been throttled but cfs->nr_running > 1. Try to
4028+
* add it unconditionnally.
4029+
*/
4030+
if (cfs_rq->nr_running == 1 || cfs_bandwidth_used())
40254031
list_add_leaf_cfs_rq(cfs_rq);
4032+
4033+
if (cfs_rq->nr_running == 1)
40264034
check_enqueue_throttle(cfs_rq);
4027-
}
40284035
}
40294036

40304037
static void __clear_buddies_last(struct sched_entity *se)
@@ -4605,11 +4612,22 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
46054612
break;
46064613
}
46074614

4608-
assert_list_leaf_cfs_rq(rq);
4609-
46104615
if (!se)
46114616
add_nr_running(rq, task_delta);
46124617

4618+
/*
4619+
* The cfs_rq_throttled() breaks in the above iteration can result in
4620+
* incomplete leaf list maintenance, resulting in triggering the
4621+
* assertion below.
4622+
*/
4623+
for_each_sched_entity(se) {
4624+
cfs_rq = cfs_rq_of(se);
4625+
4626+
list_add_leaf_cfs_rq(cfs_rq);
4627+
}
4628+
4629+
assert_list_leaf_cfs_rq(rq);
4630+
46134631
/* Determine whether we need to wake up potentially idle CPU: */
46144632
if (rq->curr == rq->idle && rq->cfs.nr_running)
46154633
resched_curr(rq);

0 commit comments

Comments
 (0)