diff options
author | Yury Norov <yury.norov@gmail.com> | 2022-09-18 05:07:16 +0200 |
---|---|---|
committer | Yury Norov <yury.norov@gmail.com> | 2022-09-26 21:19:12 +0200 |
commit | 944c417daeb63fa345fe0f754c57a5a23ca6d701 (patch) | |
tree | 25646edde93de485e2a0b6ce0e849a0080c05ebf /lib/cpumask.c | |
parent | lib/bitmap: remove bitmap_ord_to_pos (diff) | |
download | linux-944c417daeb63fa345fe0f754c57a5a23ca6d701.tar.xz linux-944c417daeb63fa345fe0f754c57a5a23ca6d701.zip |
cpumask: add cpumask_nth_{,and,andnot}
Add cpumask_nth_{,and,andnot} as wrappers around corresponding
find functions, and use it in cpumask_local_spread().
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Diffstat (limited to 'lib/cpumask.c')
-rw-r--r-- | lib/cpumask.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/cpumask.c b/lib/cpumask.c index f0ae119be8c4..2c4a63b6f03f 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -128,23 +128,21 @@ unsigned int cpumask_local_spread(unsigned int i, int node) i %= num_online_cpus(); if (node == NUMA_NO_NODE) { - for_each_cpu(cpu, cpu_online_mask) - if (i-- == 0) - return cpu; + cpu = cpumask_nth(i, cpu_online_mask); + if (cpu < nr_cpu_ids) + return cpu; } else { /* NUMA first. */ - for_each_cpu_and(cpu, cpumask_of_node(node), cpu_online_mask) - if (i-- == 0) - return cpu; - - for_each_cpu(cpu, cpu_online_mask) { - /* Skip NUMA nodes, done above. */ - if (cpumask_test_cpu(cpu, cpumask_of_node(node))) - continue; - - if (i-- == 0) - return cpu; - } + cpu = cpumask_nth_and(i, cpu_online_mask, cpumask_of_node(node)); + if (cpu < nr_cpu_ids) + return cpu; + + i -= cpumask_weight_and(cpu_online_mask, cpumask_of_node(node)); + + /* Skip NUMA nodes, done above. */ + cpu = cpumask_nth_andnot(i, cpu_online_mask, cpumask_of_node(node)); + if (cpu < nr_cpu_ids) + return cpu; } BUG(); } |