lib/cpumask: reorganize cpumask_local_spread() logic
authorYury Norov <yury.norov@gmail.com>
Sat, 21 Jan 2023 04:24:32 +0000 (20:24 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 8 Feb 2023 02:20:00 +0000 (18:20 -0800)
Now after moving all NUMA logic into sched_numa_find_nth_cpu(),
else-branch of cpumask_local_spread() is just a function call, and
we can simplify logic by using ternary operator.

While here, replace BUG() with WARN_ON().

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Peter Lafreniere <peter@n8pjl.ca>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
lib/cpumask.c

index 255974cd6734f19677dd0d2f1f9be935ffb57b35..10aa15715c0d29731dc7acba367a34c084d815e8 100644 (file)
@@ -127,16 +127,12 @@ unsigned int cpumask_local_spread(unsigned int i, int node)
        /* Wrap: we always want a cpu. */
        i %= num_online_cpus();
 
-       if (node == NUMA_NO_NODE) {
-               cpu = cpumask_nth(i, cpu_online_mask);
-               if (cpu < nr_cpu_ids)
-                       return cpu;
-       } else {
-               cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node);
-               if (cpu < nr_cpu_ids)
-                       return cpu;
-       }
-       BUG();
+       cpu = (node == NUMA_NO_NODE) ?
+               cpumask_nth(i, cpu_online_mask) :
+               sched_numa_find_nth_cpu(cpu_online_mask, i, node);
+
+       WARN_ON(cpu >= nr_cpu_ids);
+       return cpu;
 }
 EXPORT_SYMBOL(cpumask_local_spread);