sched/balancing: Change 'enum cpu_idle_type' to have more natural definitions
authorIngo Molnar <mingo@kernel.org>
Fri, 8 Mar 2024 10:58:54 +0000 (11:58 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 12 Mar 2024 10:03:40 +0000 (11:03 +0100)
commit38d707c54df4ca58cd9ceae2ddcbd6f606b99e9f
treeb2e6f4d23dd5c8acd31a65801dd80699e74a2d09
parent02a61f325a8e62a7c76479c5f2f7ddcba16877e8
sched/balancing: Change 'enum cpu_idle_type' to have more natural definitions

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@kernel.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Cc: "Gautham R. Shenoy" <gautham.shenoy@amd.com>
Link: https://lore.kernel.org/r/20240308105901.1096078-4-mingo@kernel.org
include/linux/sched/idle.h
kernel/sched/fair.c