[PATCH 03/10] sched/fair: Clear active_balance at the end of active_load_balance_cpu_stop()
Xin Zhao <[email protected]>
| Newsgroups | org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
The rq->active_balance flag is used to prevent multiple CPUs from simultaneously dispatching active balance stop tasks. Since there can only ever be one consumer of the stop task, it is not strictly necessary to protect the setting of rq->active_balance to 0 with the rq lock in active_load_balance_cpu_stop(). Therefore, we can move the action of clearing rq->active_balance to the end of active_load_balance_cpu_stop(). The benefit of this approach is that the task load of dst_rq will change due to the execution of attach_one_task(), which helps avoid prematurely clearing rq->active_balance before attach_one_task(), thus preventing unnecessary dispatch of duplicate active balance stop tasks. Active balance stop task is triggered only when rq->active_balance flag changes from 0 to 1, and there can be at most one consumer of active balance stop task at any given time. Therefore, we should never see zero rq->active_balance in active_load_balance_cpu_stop(), use WARN_ON_ONCE instead. Signed-off-by: Xin Zhao <[email protected]> --- kernel/sched/fair.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 11c104010b2e..20d03ceed9d7 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13769,8 +13769,7 @@ static int active_load_balance_cpu_stop(void *data) if (!cpu_active(busiest_cpu) || !cpu_active(target_cpu)) goto out_unlock; - if (unlikely(!busiest_rq->active_balance)) - goto out_unlock; + WARN_ON_ONCE(!busiest_rq->active_balance); /* Is there any task to move? */ if (busiest_rq->nr_running <= 1) @@ -13815,13 +13814,13 @@ static int active_load_balance_cpu_stop(void *data) } rcu_read_unlock(); out_unlock: - busiest_rq->active_balance = 0; rq_unlock(busiest_rq, &rf); if (p) attach_one_task(target_rq, p); local_irq_enable(); + busiest_rq->active_balance = 0; return 0; } -- 2.34.1