Re: [RESEND] sched/rt: Skip currently executing CPU in rto_next_cpu()

From: Steven Rostedt

Date: Tue Jan 06 2026 - 10:48:56 EST


On Tue, 6 Jan 2026 14:11:57 +0530
K Prateek Nayak <kprateek.nayak@xxxxxxx> 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