Re: [PATCH V3 2/2] sched/fair: Fallback to sched-idle CPU if idle CPU isn't found

From: Peter Zijlstra
Date: Tue Jul 02 2019 - 04:35:45 EST


On Mon, Jul 01, 2019 at 03:08:41PM -0700, Subhra Mazumdar wrote:
> On 7/1/19 1:03 AM, Viresh Kumar wrote:
> > On 28-06-19, 18:16, Subhra Mazumdar wrote:
> > > On 6/25/19 10:06 PM, Viresh Kumar wrote:

> > > > @@ -5376,6 +5376,15 @@ static struct {
> > > > #endif /* CONFIG_NO_HZ_COMMON */
> > > > +/* CPU only has SCHED_IDLE tasks enqueued */
> > > > +static int sched_idle_cpu(int cpu)
> > > > +{
> > > > + struct rq *rq = cpu_rq(cpu);
> > > > +
> > > > + return unlikely(rq->nr_running == rq->cfs.idle_h_nr_running &&
> > > > + rq->nr_running);
> > > > +}
> > > > +
> > > Shouldn't this check if rq->curr is also sched idle?
> > Why wouldn't the current set of checks be enough to guarantee that ?
> I thought nr_running does not include the on-cpu thread.

It very much does.

> > > And why not drop the rq->nr_running non zero check?
> > Because CPU isn't sched-idle if nr_running and idle_h_nr_running are both 0,
> > i.e. it is an IDLE cpu in that case. And so I thought it is important to have
> > this check as well.
> >
> idle_cpu() not only checks nr_running is 0 but also rq->curr == rq->idle

idle_cpu() will try very hard to declare a CPU !idle. But I don't see
how that it relevant. sched_idle_cpu() will only return true if there
are only SCHED_IDLE tasks on the CPU. Viresh's test is simple and
straight forward.