From nobody Mon Dec 1 23:33:40 2025 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (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 0DFA5219A86 for ; Wed, 26 Nov 2025 06:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764137560; cv=none; b=FG4ILi+BJGOLXLAFKukCAFCU/NgvaedwwX3xo+sPY3Nq46IUjGZ00Ev7YDvyDbiYvl7VxswEsmaUqtQH999eE4eAQLBOGC5H3hDt7i7TGMACPYWXyUrAI3iYOAU0CZSoqc8Kr9ggAMW9tGL/FuJz9FnC6M/jLaxDdyirPjZONxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764137560; c=relaxed/simple; bh=FpX9XubduF51jUjVaCXnv8s7MJ/GnQvswPFp5AiwPMw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uijfmeyfzHGwgLUn5p49qlL4+gkx3N08UgPzvkngKF7fUbuxwRtM2j57nRiMiO50j3hCy8yB6v9GJ4TE6M9V/h2CTtR/5w0aX8nYMBEVLwS2h0FIy9vIN9O8KZagwyLUWdcnAUkcMZn/0DrFs6q6zf50uqWZEYRqpQHHLmiTJKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=F3vIP/fJ; arc=none smtp.client-ip=113.46.200.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="F3vIP/fJ" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=iAStQo5GDkIDwqNgKP7w+W57X8vQG3XPvdNynn9qKq4=; b=F3vIP/fJC5oN2S7F47Q/vbRwbQWHNTNoWe1nB3b+aXxlfdZF+aQQKKhPqoNTDdDsaE5/iw619 Bylw+eigZQOvcbqm1kKgthhOZW/v7rn+RS9evlCSmx1thGSnbGyL5KwZDWE2gB8ZT6PrXdIoqZb ExeDqD6uF5ncIHL4G0Ft/CU= Received: from mail.maildlp.com (unknown [172.19.162.254]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4dGTgl2zwszpSv4; Wed, 26 Nov 2025 14:10:27 +0800 (CST) Received: from kwepemg100008.china.huawei.com (unknown [7.202.181.26]) by mail.maildlp.com (Postfix) with ESMTPS id 68E7F180471; Wed, 26 Nov 2025 14:12:34 +0800 (CST) Received: from huawei.com (10.67.174.242) by kwepemg100008.china.huawei.com (7.202.181.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 26 Nov 2025 14:12:33 +0800 From: Chen Jinghuang To: CC: , , , , , , , , , Subject: [PATCH v3] sched/rt: Skip currently executing CPU in rto_next_cpu() Date: Wed, 26 Nov 2025 05:54:03 +0000 Message-ID: <20251126055403.2076735-1-chenjinghuang2@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251125112605.2c73227a@gandalf.local.home> References: <20251125112605.2c73227a@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemg100008.china.huawei.com (7.202.181.26) Content-Type: text/plain; charset="utf-8" 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, wasting CPU cycles on unnecessary interrupt handling. The triggering 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 !=3D 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(). Fixes: 4bdced5c9a292 ("sched/rt: Simplify the IPI based RT balancing logic") Suggested-by: Steven Rostedt (Google) Signed-off-by: Chen Jinghuang Reviewed-by: Steven Rostedt (Google) --- v1-->v2: - Replace the original "check NEED_RESCHED on target CPU" logic with "skip the currently executing CPU" - This modification eliminates self-IPIS v2-->v3: - Remove unneeded extra whitespace - Add Reviewed-by tag from Steven Rostedt --- --- kernel/sched/rt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 7936d4333731..f6af41e27508 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 =3D smp_processor_id(); int next; int cpu; =20 @@ -2118,10 +2119,12 @@ static int rto_next_cpu(struct root_domain *rd) */ for (;;) { =20 - /* When rto_cpu is -1 this acts like cpumask_first() */ - cpu =3D cpumask_next(rd->rto_cpu, rd->rto_mask); - - rd->rto_cpu =3D cpu; + do { + /* When rto_cpu is -1 this acts like cpumask_first() */ + cpu =3D cpumask_next(rd->rto_cpu, rd->rto_mask); + rd->rto_cpu =3D cpu; + /* Do not send IPI to self */ + } while (cpu =3D=3D this_cpu); =20 if (cpu < nr_cpu_ids) return cpu; --=20 2.34.1