Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched/nohz: Remove unnecessarily complex error handling pattern from find_new_ilb()

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

+2 -3
+2 -3
kernel/sched/fair.c
··· 11528 11528 return ilb_cpu; 11529 11529 } 11530 11530 11531 - return nr_cpu_ids; 11531 + return -1; 11532 11532 } 11533 11533 11534 11534 /* ··· 11549 11549 nohz.next_balance = jiffies+1; 11550 11550 11551 11551 ilb_cpu = find_new_ilb(); 11552 - 11553 - if (ilb_cpu >= nr_cpu_ids) 11552 + if (ilb_cpu < 0) 11554 11553 return; 11555 11554 11556 11555 /*