From nobody Tue Dec 2 01:50:43 2025 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (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 37BDF2110E for ; Fri, 21 Nov 2025 01:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763690323; cv=none; b=g15nYRJmSwZb8PjUhDpvX945uE21yiZ2OOuW1xNKX+0DM0CiR7BMucgkZHT3aRP8Qjuh8q93NJFSsNsQ/iZa9oBcLKziX2vI45BoHA+Z5yTVfBMk50b7yl9490gDL9Xi0VRFE/ix3Pc6OWEQKJJUeGw8yYciTBKXWI1e4wQyGPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763690323; c=relaxed/simple; bh=bqAG1yB7+xJT0+02Q39IW7zYquAUpAj6E9Qv0Y1O6eA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZarDQlkBzXIYrtU6VG4ChpM2X18XjVL9TW9xEMcSfUFKi77zylCTA9JIx2u7s+pJFrlaXYfdDFlIakaS5yuBAcp9hj/gbPfj40zfpsQo43lbMoAFUeQPJFngPzvMhDqxpCnMz597bKJcJD6M6THAehgYlaV27HWSYEwkpgwOcVI= 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=hrOYdL6k; arc=none smtp.client-ip=113.46.200.227 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="hrOYdL6k" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=EwOwEcQIhh7SAc0JnvpXQvmg43j2GCJUk/CUYG8jN4A=; b=hrOYdL6kwjICD2ae7jzBlik+Z5sUBgtPi2qedq4ynHZvMlevVqvJNcv3Ml7yXyeJlpAd/yYnY 7uzX3f1ve7/IB/glZB6PUSAGnIkwS8QmwGggD08epOiqZqRkBfqfQWVIJpw/UrMWhE8STuVXn62 PNSiZQkk0YI8Z7L5HBbPwFs= Received: from mail.maildlp.com (unknown [172.19.162.112]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4dCJHj09QSznTV9; Fri, 21 Nov 2025 09:57:05 +0800 (CST) Received: from kwepemg100008.china.huawei.com (unknown [7.202.181.26]) by mail.maildlp.com (Postfix) with ESMTPS id 9206C140279; Fri, 21 Nov 2025 09:58:31 +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; Fri, 21 Nov 2025 09:58:30 +0800 From: Chen Jinghuang To: CC: , , , , , , , , Subject: [PATCH] sched/rt: rto_next_cpu: Skip CPUs with NEED_RESCHED Date: Fri, 21 Nov 2025 01:40:04 +0000 Message-ID: <20251121014004.564508-1-chenjinghuang2@huawei.com> X-Mailer: git-send-email 2.34.1 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: kwepems500001.china.huawei.com (7.221.188.70) 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/cross-CPU IPI when target CPU already has a pending reschedule, making the IPI unnecessary. Signed-off-by: Chen Jinghuang --- kernel/sched/rt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 7936d4333731..29ce1af9f121 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2123,8 +2123,20 @@ static int rto_next_cpu(struct root_domain *rd) =20 rd->rto_cpu =3D cpu; =20 - if (cpu < nr_cpu_ids) + if (cpu < nr_cpu_ids) { + struct task_struct *t; + struct rq *rq =3D cpu_rq(cpu); + + rcu_read_lock(); + t =3D rcu_dereference(rq->curr); + if (test_tsk_need_resched(t)) { + rcu_read_unlock(); + continue; + } + rcu_read_unlock(); + return cpu; + } =20 rd->rto_cpu =3D -1; =20 --=20 2.34.1