From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82D4A301704 for ; Mon, 5 Jan 2026 21:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767648288; cv=none; b=up+PKSwh1I+wXQa4MYYb2EEhWOs0RkWj98x2OZICGQYx8cumnzOW5lJRo/zpp6RwXyWWJWMKHxzSB2TqY7wUTIU0CiwqKX7Oq/uPBn9CpmWmWCFOaueeQtbFS9mQHc5zqnTdV7wpqTx/mqY3in1VVEh109RPq+Lvjs1MRv96ynQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767648288; c=relaxed/simple; bh=JubYRhN+YOag8XOMJs46diuEopUA2V6hwmirEoN373c=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OscGP/kUC0Hn18XoEYVX7c0T89ywW9If2gEM0FfRpFdhGOLObWFzPLJwlpLq6AfLglemwlkt+Eqg1wPNoHA6bjeHH9pNIsSGtKMqc1k7bwLX76pSGMKL35uZCWktPvtWjWpC4/Hv+zJmBPd7duGZ3DmsaVjlWQ9MJkvnGZHIhsY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; arc=none smtp.client-ip=216.40.44.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Received: from omf07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E78DB1602A6; Mon, 5 Jan 2026 21:24:42 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf07.hostedemail.com (Postfix) with ESMTPA id A862D20032; Mon, 5 Jan 2026 21:24:40 +0000 (UTC) Date: Mon, 5 Jan 2026 16:25:03 -0500 From: Steven Rostedt To: Chen Jinghuang Cc: , , , , , , , , Subject: Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu() Message-ID: <20260105162503.36377c7e@gandalf.local.home> In-Reply-To: <20260105034012.3196947-1-chenjinghuang2@huawei.com> References: <20260105034012.3196947-1-chenjinghuang2@huawei.com> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: 3xxnyb77dxt6efr68etptwqxj5yf1epb X-Rspamd-Server: rspamout02 X-Rspamd-Queue-Id: A862D20032 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX19Pm75zikGNf+RR30VId11ISgSfE/1UA7Y= X-HE-Tag: 1767648280-598046 X-HE-Meta: U2FsdGVkX1/Gp3OKpKfZfXnbUCTChqkPUtqIgWD8A3KnaWR2W+3RZKP+gn/862VFVnZ9whVFnP7eLSA1u42M9KxouGwCR3t2rwdNHJYhhYSENI7xsYWOwCqkR7OyXoCe400qZv97vTC7cPALsiFzaBLktBpVvsf2XWp4qA1KKXHA7ImWzg4TcLSM1UahNGq9lck6lL0fUtTlP8X798N6vh4Y8Md6Eb4xJRC7GqixXWVkajnfVlbexUgp58GqU7aKpZ50VW051SEaPB+UABI2TuqRhKWvzFW839mgH5bIe5LuhaI5U2hUigy7yVbObdzZF0UOBbPqZjY3EEykbq4VesR6dU1kCOZHSa4iijYvKrJOlx5wNnFnoWXNixPqkBiZccH7kujsJD4iJP7myOTF/EIKydXkanZfB8Ce2FUGgT8= Peter, Are you OK with this change? If so, care to take it? -- Steve On Mon, 5 Jan 2026 03:40:12 +0000 Chen Jinghuang wrote: > CPU0 becomes overloaded when hosting a CPU-bound RT task, a non-CPU-bound > RT task, and a CFS task stuck in kernel space. When other CPUs switch from > RT to non-RT tasks, RT load balancing (LB) is triggered; with > HAVE_RT_PUSH_IPI enabled, they send IPIs to CPU0 to drive the execution > of rto_push_irq_work_func. During push_rt_task on CPU0, > if next_task->prio < rq->donor->prio, resched_curr() sets NEED_RESCHED > and after the push operation completes, CPU0 calls rto_next_cpu(). > Since only CPU0 is overloaded in this scenario, rto_next_cpu() should > ideally return -1 (no further IPI needed). > > However, multiple CPUs invoking tell_cpu_to_push() during LB increments > rd->rto_loop_next. Even when rd->rto_cpu is set to -1, the mismatch between > rd->rto_loop and rd->rto_loop_next forces rto_next_cpu() to restart its > search from -1. With CPU0 remaining overloaded (satisfying rt_nr_migratory > && rt_nr_total > 1), it gets reselected, causing CPU0 to queue irq_work to > itself and send self-IPIs repeatedly. As long as CPU0 stays overloaded and > other CPUs run pull_rt_tasks(), it falls into an infinite self-IPI loop, > which triggers a CPU hardlockup due to continuous self-interrupts. > > The trigging scenario is as follows: > > cpu0 cpu1 cpu2 > pull_rt_task > tell_cpu_to_push > <------------irq_work_queue_on > rto_push_irq_work_func > push_rt_task > resched_curr(rq) pull_rt_task > rto_next_cpu tell_cpu_to_push > <-------------------------- atomic_inc(rto_loop_next) > rd->rto_loop != next > rto_next_cpu > irq_work_queue_on > rto_push_irq_work_func > > Fix redundant self-IPI by filtering the initiating CPU in rto_next_cpu(). > This solution has been verified to effectively eliminate spurious self-IPIs > and prevent CPU hardlockup scenarios. > > Fixes: 4bdced5c9a29 ("sched/rt: Simplify the IPI based RT balancing logic") > Suggested-by: Steven Rostedt (Google) > Signed-off-by: Chen Jinghuang > Reviewed-by: Steven Rostedt (Google) > > --- > Changes since v2: https://lore.kernel.org/all/20251125083649.1814558-1-chenjinghuang2@huawei.com/ > - Replace the original "check NEED_RESCHED on target CPU" > logic with "skip the currently executing CPU" > - This modification eliminates self-IPIS > > Changes since v1: https://lore.kernel.org/all/20251121014004.564508-1-chenjinghuang2@huawei.com/ > - Remove unneeded extra whitespace > - Add Reviewed-by tag from Steven Rostedt > --- > kernel/sched/rt.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index f1867fe8e5c5..ec10ed7bb75d 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -2100,6 +2100,7 @@ static void push_rt_tasks(struct rq *rq) > */ > static int rto_next_cpu(struct root_domain *rd) > { > + int this_cpu = smp_processor_id(); > int next; > int cpu; > > @@ -2118,10 +2119,13 @@ static int rto_next_cpu(struct root_domain *rd) > */ > for (;;) { > > - /* When rto_cpu is -1 this acts like cpumask_first() */ > - cpu = cpumask_next(rd->rto_cpu, rd->rto_mask); > + do { > + /* When rto_cpu is -1 this acts like cpumask_first() */ > + cpu = cpumask_next(rd->rto_cpu, rd->rto_mask); > > - rd->rto_cpu = cpu; > + rd->rto_cpu = cpu; > + /* Do not send IPI to self */ > + } while (cpu == this_cpu); > > if (cpu < nr_cpu_ids) > return cpu;