Re: [PATCH 3/9] sched/balancing: Change 'enum cpu_idle_type' to have more natural definitions

From: Ingo Molnar
Date: Fri Mar 08 2024 - 05:00:11 EST



* Vincent Guittot <vincent.guittot@xxxxxxxxxx> wrote:

> On Mon, 4 Mar 2024 at 10:48, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
> >
> > The cpu_idle_type enum has the confusingly inverted property
> > that 'not idle' is 1, and 'idle' is '0'.
> >
> > This resulted in a number of unnecessary complications in the code.
> >
> > Reverse the order, remove the CPU_NOT_IDLE type, and convert
> > all code to a natural boolean form.
> >
> > It's much more readable:
> >
> > - enum cpu_idle_type idle = this_rq->idle_balance ?
> > - CPU_IDLE : CPU_NOT_IDLE;
> > -
> > + enum cpu_idle_type idle = this_rq->idle_balance;
> >
> > --------------------------------
> >
> > - if (env->idle == CPU_NOT_IDLE || !busiest->sum_nr_running)
> > + if (!env->idle || !busiest->sum_nr_running)
> >
> > --------------------------------
> >
> > And gets rid of the double negation in these usages:
> >
> > - if (env->idle != CPU_NOT_IDLE && env->src_rq->nr_running <= 1)
> > + if (env->idle && env->src_rq->nr_running <= 1)
> >
> > Furthermore, this makes code much more obvious where there's
> > differentiation between CPU_IDLE and CPU_NEWLY_IDLE.
> >
> > Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
> > Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> > Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
> > Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
> > Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> > Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
> > ---
> > include/linux/sched/idle.h | 3 +--
> > kernel/sched/fair.c | 27 ++++++++++++---------------
> > 2 files changed, 13 insertions(+), 17 deletions(-)
> >
> > diff --git a/include/linux/sched/idle.h b/include/linux/sched/idle.h
> > index 478084f9105e..4a6423700ffc 100644
> > --- a/include/linux/sched/idle.h
> > +++ b/include/linux/sched/idle.h
> > @@ -5,8 +5,7 @@
> > #include <linux/sched.h>
> >
> > enum cpu_idle_type {
> > - CPU_IDLE,
> > - CPU_NOT_IDLE,
>
> Could be set CPU_NOT_IDLE = 0 to help keeping in mind that 0 means
> cpu is not idle even if we don't use it ?

Yeah, makes sense. I've added back __CPU_NOT_IDLE = 0 (with the underscore
to make sure some pending patch isn't accidentally relying on something it
shouldn't), and added your Reviewed-by.

Thanks,

Ingo