From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Xin Zhao <jackzxcui1989@163.com>, <mingo@redhat.com>,
<peterz@infradead.org>, <juri.lelli@redhat.com>,
<vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>,
<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
<vschneid@redhat.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH RESEND 03/10] sched/fair: Clear active_balance at the end of active_load_balance_cpu_stop()
Date: Thu, 10 Sep 2026 13:39:10 +0530 [thread overview]
Message-ID: <f771bdd6-3e4b-47db-bfa9-b04bd58b9a06@amd.com> (raw)
In-Reply-To: <20260910042950.1619727-4-jackzxcui1989@163.com>
Hello Xin,
On 9/10/2026 9:59 AM, Xin Zhao wrote:
> 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.
Aren't we moving tasks *out* of the busiest CPU where the stopper is
scheduled?
As soon as we do detach_one_task() within the rq_lock, the load is
reflected correctly. There is no need to wait until we attach task to
a remote target_rq. TASK_ON_RQ_MIGRATING will immediately detach its
PELT signal from busiest.
That last statement seems to be inaccurate.
>
> 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 <jackzxcui1989@163.com>
> ---
> 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();
As soon as we enable IRQs, a timer for a remote tick may go off which
may want to push the task from this CPU again but it sees
->active_balance still set.
At the very least, I think this should be done before IRQs are enabled
but I'm not convinced by the justification for this in the commit
message.
> + busiest_rq->active_balance = 0;
>
> return 0;
> }
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-09-10 8:09 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 4:29 [RFC PATCH RESEND 00/10] sched/fair: A series of load balance patches to improve real-time performance of CFS tasks Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 01/10] sched/fair: Do not set_rd_overloaded() if rd->online != env->cpus Xin Zhao
2026-09-10 8:30 ` K Prateek Nayak
2026-09-10 13:45 ` Vincent Guittot
2026-09-11 1:06 ` Xin Zhao
2026-09-11 6:21 ` K Prateek Nayak
2026-09-12 1:46 ` Xin Zhao
2026-09-12 1:53 ` Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 02/10] scbed/fair: Remove duplicate check for busiest_cpu in active_load_balance_cpu_stop() Xin Zhao
2026-09-10 11:41 ` Kayra Cizmeci
2026-09-11 0:22 ` Xin Zhao
2026-09-11 9:20 ` Kayra Cizmeci
2026-09-10 4:29 ` [RFC PATCH RESEND 03/10] sched/fair: Clear active_balance at the end of active_load_balance_cpu_stop() Xin Zhao
2026-09-10 8:09 ` K Prateek Nayak [this message]
2026-09-10 14:15 ` Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 04/10] sched/fair: Add LB_PROMOTE feature to enhance real-time performance of fair tasks Xin Zhao
2026-09-11 12:32 ` Vincent Guittot
2026-09-12 4:28 ` Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 05/10] sched/fair: Introduce select_task_rq_fair_thin() to select rq when LB_PROMOTE Xin Zhao
2026-09-10 8:19 ` Vincent Guittot
2026-09-10 14:39 ` Xin Zhao
2026-09-10 15:31 ` Vincent Guittot
2026-09-10 15:56 ` Xin Zhao
2026-09-11 12:27 ` Vincent Guittot
2026-09-12 4:08 ` Xin Zhao
2026-09-10 12:00 ` Kayra Cizmeci
2026-09-10 14:56 ` Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 06/10] sched/fair: Modify active_load_balance_cpu_stop() to accommodate more scenarios Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 07/10] sched/fair: Trigger active balance if a CFS task is preempted when LB_PROMOTE Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 08/10] sched/fair: Do not check avg_idle to prematurely exit newly idle " Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 09/10] sched/fair: Not goto more_balance if newly idle and has pending task when LBF_NEED_BREAK Xin Zhao
2026-09-10 4:29 ` [RFC PATCH RESEND 10/10] sched/fair: Strive to find a task to migrate if newly idle when LB_PROMOTE Xin Zhao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f771bdd6-3e4b-47db-bfa9-b04bd58b9a06@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jackzxcui1989@163.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®