sched/nohz: Remove unnecessarily complex error handling pattern from find_new_ilb()
authorIngo Molnar <mingo@kernel.org>
Fri, 6 Oct 2023 10:25:18 +0000 (12:25 +0200)
committerIngo Molnar <mingo@kernel.org>
Mon, 9 Oct 2023 10:21:23 +0000 (12:21 +0200)
find_new_ilb() returns nr_cpu_ids on failure - which is the usual
cpumask bitops return pattern, but is weird & unnecessary in this
context: not only is it a global variable, it it is a +1 out of
bounds CPU index and also has different signedness ...

Its only user, kick_ilb(), then checks the return against nr_cpu_ids
to decide to return. There's no other use.

So instead of this, use a standard -1 return on failure to find an
idle CPU, as the argument is signed already.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Link: https://lore.kernel.org/r/20231006102518.2452758-4-mingo@kernel.org
kernel/sched/fair.c

index f82b301740ece85744a9a91eb0b1b23bd16e8598..19bb4ac94146571a9d53ef71fe099261bfc64d90 100644 (file)
@@ -11528,7 +11528,7 @@ static inline int find_new_ilb(void)
                        return ilb_cpu;
        }
 
-       return nr_cpu_ids;
+       return -1;
 }
 
 /*
@@ -11549,8 +11549,7 @@ static void kick_ilb(unsigned int flags)
                nohz.next_balance = jiffies+1;
 
        ilb_cpu = find_new_ilb();
-
-       if (ilb_cpu >= nr_cpu_ids)
+       if (ilb_cpu < 0)
                return;
 
        /*