* [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
@ 2026-01-05 3:40 Chen Jinghuang
2026-01-05 21:25 ` Steven Rostedt
2026-01-06 8:41 ` K Prateek Nayak
0 siblings, 2 replies; 8+ messages in thread
From: Chen Jinghuang @ 2026-01-05 3:40 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
linux-kernel
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) <rostedt@goodmis.org>
Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
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;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
2026-01-05 3:40 Chen Jinghuang
@ 2026-01-05 21:25 ` Steven Rostedt
2026-01-06 8:41 ` K Prateek Nayak
1 sibling, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2026-01-05 21:25 UTC (permalink / raw)
To: Chen Jinghuang
Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
bsegall, mgorman, vschneid, linux-kernel
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 <chenjinghuang2@huawei.com> 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) <rostedt@goodmis.org>
> Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> ---
> 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;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
2026-01-05 3:40 Chen Jinghuang
2026-01-05 21:25 ` Steven Rostedt
@ 2026-01-06 8:41 ` K Prateek Nayak
2026-01-06 15:49 ` Steven Rostedt
1 sibling, 1 reply; 8+ messages in thread
From: K Prateek Nayak @ 2026-01-06 8:41 UTC (permalink / raw)
To: Chen Jinghuang, mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
linux-kernel
Hello Chen, Steve,
On 1/5/2026 9:10 AM, Chen Jinghuang wrote:
> @@ -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);
nit.
Since we are already within an infinite for-loop, can't we simply do:
/* Do not send IPI to self */
if (cpu == this_cpu)
continue;
here and go evaluate cpumask_next() again instead of adding another
do-while? Was the nested loop intentional to highlight these bits
explicitly?
>
> if (cpu < nr_cpu_ids)
> return cpu;
--
Thanks and Regards,
Prateek
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
2026-01-06 8:41 ` K Prateek Nayak
@ 2026-01-06 15:49 ` Steven Rostedt
0 siblings, 0 replies; 8+ messages in thread
From: Steven Rostedt @ 2026-01-06 15:49 UTC (permalink / raw)
To: K Prateek Nayak
Cc: Chen Jinghuang, mingo, peterz, juri.lelli, vincent.guittot,
dietmar.eggemann, bsegall, mgorman, vschneid, linux-kernel
On Tue, 6 Jan 2026 14:11:57 +0530
K Prateek Nayak <kprateek.nayak@amd.com> wrote:
> Hello Chen, Steve,
>
> On 1/5/2026 9:10 AM, Chen Jinghuang wrote:
> > @@ -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);
>
> nit.
>
> Since we are already within an infinite for-loop, can't we simply do:
>
> /* Do not send IPI to self */
> if (cpu == this_cpu)
> continue;
>
> here and go evaluate cpumask_next() again instead of adding another
> do-while? Was the nested loop intentional to highlight these bits
> explicitly?
Hmm, yeah, I think I added the loop to express this issue. But I think your
suggestion could work too. I originally had something like that, but for
some reason I thought it added an extra branch (over the added do { } while).
>
> >
> > if (cpu < nr_cpu_ids)
> > return cpu;
>
for (;;) {
/* When rto_cpu is -1 this acts like cpumask_first() */
cpu = cpumask_next(rd->rto_cpu, rd->rto_mask);
rd->rto_cpu = cpu;
+ /* Do not send IPI to self */
+ if (cpu == this_cpu)
+ continue;
+
if (cpu < nr_cpu_ids)
return cpu;
rd->rto_cpu = -1;
/*
* ACQUIRE ensures we see the @rto_mask changes
* made prior to the @next value observed.
*
* Matches WMB in rt_set_overload().
*/
next = atomic_read_acquire(&rd->rto_loop_next);
if (rd->rto_loop == next)
break;
rd->rto_loop = next;
}
Looks to be equivalent.
Chen, care to send a new version?
-- Steve
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
@ 2026-01-15 6:13 Chen Jinghuang
0 siblings, 0 replies; 8+ messages in thread
From: Chen Jinghuang @ 2026-01-15 6:13 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
linux-kernel
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) <rostedt@goodmis.org>
Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
---
Changes since v4: https://lore.kernel.org/all/20260108070355.259530-1-chenjinghuang2@huawei.com/
- Add Reviewed-by tag from Valentin Schneider
Changes since v3: https://lore.kernel.org/all/20260105034012.3196947-1-chenjinghuang2@huawei.com/
- Replace the do-while loop with a continue statement to simplify the loop logic
- Add Suggested-by tag from K Prateek Nayak
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 | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f1867fe8e5c5..e0ff90905019 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;
@@ -2123,6 +2124,10 @@ static int rto_next_cpu(struct root_domain *rd)
rd->rto_cpu = cpu;
+ /* Do not send IPI to self */
+ if (cpu == this_cpu)
+ continue;
+
if (cpu < nr_cpu_ids)
return cpu;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
@ 2026-01-22 1:25 Chen Jinghuang
2026-01-23 10:06 ` Peter Zijlstra
2026-02-03 11:18 ` [tip: sched/core] " tip-bot2 for Chen Jinghuang
0 siblings, 2 replies; 8+ messages in thread
From: Chen Jinghuang @ 2026-01-22 1:25 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot
Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
linux-kernel
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) <rostedt@goodmis.org>
Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
---
Changes since v4: https://lore.kernel.org/all/20260108070355.259530-1-chenjinghuang2@huawei.com/
- Add Reviewed-by tag from Valentin Schneider
Changes since v3: https://lore.kernel.org/all/20260105034012.3196947-1-chenjinghuang2@huawei.com/
- Replace the do-while loop with a continue statement to simplify the loop logic
- Add Suggested-by tag from K Prateek Nayak
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 | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f1867fe8e5c5..e0ff90905019 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;
@@ -2123,6 +2124,10 @@ static int rto_next_cpu(struct root_domain *rd)
rd->rto_cpu = cpu;
+ /* Do not send IPI to self */
+ if (cpu == this_cpu)
+ continue;
+
if (cpu < nr_cpu_ids)
return cpu;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()
2026-01-22 1:25 [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu() Chen Jinghuang
@ 2026-01-23 10:06 ` Peter Zijlstra
2026-02-03 11:18 ` [tip: sched/core] " tip-bot2 for Chen Jinghuang
1 sibling, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2026-01-23 10:06 UTC (permalink / raw)
To: Chen Jinghuang
Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
bsegall, mgorman, vschneid, linux-kernel
On Thu, Jan 22, 2026 at 01:25:33AM +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) <rostedt@goodmis.org>
> Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
> Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
> ---
Thanks!
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip: sched/core] sched/rt: Skip currently executing CPU in rto_next_cpu()
2026-01-22 1:25 [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu() Chen Jinghuang
2026-01-23 10:06 ` Peter Zijlstra
@ 2026-02-03 11:18 ` tip-bot2 for Chen Jinghuang
1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for Chen Jinghuang @ 2026-02-03 11:18 UTC (permalink / raw)
To: linux-tip-commits
Cc: Steven Rostedt (Google), K Prateek Nayak, Chen Jinghuang,
Peter Zijlstra (Intel), Valentin Schneider, x86, linux-kernel
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 94894c9c477e53bcea052e075c53f89df3d2a33e
Gitweb: https://git.kernel.org/tip/94894c9c477e53bcea052e075c53f89df3d2a33e
Author: Chen Jinghuang <chenjinghuang2@huawei.com>
AuthorDate: Thu, 22 Jan 2026 01:25:33
Committer: Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 03 Feb 2026 12:04:19 +01:00
sched/rt: Skip currently executing CPU in rto_next_cpu()
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) <rostedt@goodmis.org>
Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Chen Jinghuang <chenjinghuang2@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Link: https://patch.msgid.link/20260122012533.673768-1-chenjinghuang2@huawei.com
---
kernel/sched/rt.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 0a9b2cd..a768047 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2106,6 +2106,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;
@@ -2129,6 +2130,10 @@ static int rto_next_cpu(struct root_domain *rd)
rd->rto_cpu = cpu;
+ /* Do not send IPI to self */
+ if (cpu == this_cpu)
+ continue;
+
if (cpu < nr_cpu_ids)
return cpu;
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-02-03 11:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22 1:25 [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu() Chen Jinghuang
2026-01-23 10:06 ` Peter Zijlstra
2026-02-03 11:18 ` [tip: sched/core] " tip-bot2 for Chen Jinghuang
-- strict thread matches above, loose matches on Subject: below --
2026-01-15 6:13 [RESEND] " Chen Jinghuang
2026-01-05 3:40 Chen Jinghuang
2026-01-05 21:25 ` Steven Rostedt
2026-01-06 8:41 ` K Prateek Nayak
2026-01-06 15:49 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox