Skip to content

Commit

Permalink
sched/fair: Fix unthrottle_cfs_rq() for leaf_cfs_rq list
Browse files Browse the repository at this point in the history
OpenAnolis BugTracker: 0000301

commit 39f23ce upstream

Although not exactly identical, unthrottle_cfs_rq() and enqueue_task_fair()
are quite close and follow the same sequence for enqueuing an entity in the
cfs hierarchy. Modify unthrottle_cfs_rq() to use the same pattern as
enqueue_task_fair(). This fixes a problem already faced with the latter and
add an optimization in the last for_each_sched_entity loop.

Fixes: fe61468 (sched/fair: Fix enqueue_task_fair warning)
Reported-by Tao Zhou <zohooouoto@zoho.com.cn>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Phil Auld <pauld@redhat.com>
Reviewed-by: Ben Segall <bsegall@google.com>
Link: https://lkml.kernel.org/r/20200513135528.4742-1-vincent.guittot@linaro.org
Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Acked-by: Michael Wang <yun.wang@linux.alibaba.com>
  • Loading branch information
vingu-linaro authored and Cruz Zhao committed Sep 28, 2021
1 parent 1302fe3 commit 2df6821
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions kernel/sched/fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -6024,11 +6024,9 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
{
bool immune = true;
struct task_group *tg = cfs_rq->tg;
struct cfs_rq *bottom_cfs_rq = cfs_rq;
struct rq *rq = rq_of(cfs_rq);
struct cfs_bandwidth *cfs_b = tg_cfs_bandwidth(tg);
struct sched_entity *se;
int enqueue = 1;
long task_delta, ei_delta;

se = tg->se[cpu_of(rq)];
Expand All @@ -6052,24 +6050,42 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
task_delta = cfs_rq->h_nr_running;
for_each_sched_entity(se) {
if (se->on_rq)
enqueue = 0;
break;

cfs_rq = cfs_rq_of(se);
if (enqueue) {
if (se->my_q != bottom_cfs_rq)
cgroup_idle_end(se);
enqueue_entity(cfs_rq, se, ENQUEUE_WAKEUP);
}
enqueue_entity(cfs_rq, se, ENQUEUE_WAKEUP);

cfs_rq->h_nr_running += task_delta;
update_nr_expel_immune(cfs_rq, se, &immune, ei_delta);

/* end evaluation on encountering a throttled cfs_rq */
if (cfs_rq_throttled(cfs_rq))
break;
goto unthrottle_throttle;
}

if (!se)
add_nr_running(rq, task_delta);
for_each_sched_entity(se) {
cfs_rq = cfs_rq_of(se);

update_load_avg(cfs_rq, se, UPDATE_TG);

cfs_rq->h_nr_running += task_delta;

/* end evaluation on encountering a throttled cfs_rq */
if (cfs_rq_throttled(cfs_rq))
goto unthrottle_throttle;

/*
* One parent has been throttled and cfs_rq removed from the
* list. Add it back to not break the leaf list.
*/
if (throttled_hierarchy(cfs_rq))
list_add_leaf_cfs_rq(cfs_rq);
}

/* At this point se is NULL and we are at root level*/
add_nr_running(rq, task_delta);

unthrottle_throttle:
/*
* The cfs_rq_throttled() breaks in the above iteration can result in
* incomplete leaf list maintenance, resulting in triggering the
Expand All @@ -6078,7 +6094,8 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
for_each_sched_entity(se) {
cfs_rq = cfs_rq_of(se);

list_add_leaf_cfs_rq(cfs_rq);
if (list_add_leaf_cfs_rq(cfs_rq))
break;
}

assert_list_leaf_cfs_rq(rq);
Expand Down

0 comments on commit 2df6821

Please sign in to comment.