aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2025-01-28 11:46:35 -0500
committerYury Norov <yury.norov@gmail.com>2025-02-24 16:37:22 -0500
commit3268cb2e49cc2a2d142f210efdc82602639d2047 (patch)
treef1c005fca4ca683ac451b38e1d860fd7cc05ef1b
parentcpumask: deprecate cpumask_next_wrap() (diff)
downloadwireguard-linux-3268cb2e49cc2a2d142f210efdc82602639d2047.tar.xz
wireguard-linux-3268cb2e49cc2a2d142f210efdc82602639d2047.zip
cpumask: re-introduce cpumask_next{,_and}_wrap()
cpumask_next_wrap_old() has two additional parameters, comparing to its generic counterpart find_next_bit_wrap(). The reason for that is historical. Before 4fe49b3b97c262 ("lib/bitmap: introduce for_each_set_bit_wrap() macro"), cpumask_next_wrap() was used to implement for_each_cpu_wrap() iterator. Now that the iterator is an alias to generic for_each_set_bit_wrap(), the additional parameters aren't used and may confuse readers. All existing users call cpumask_next_wrap() in a way that makes it possible to turn it to straight and simple alias to find_next_bit_wrap(). In a couple of places kernel users opencode missing cpumask_next_and_wrap(). Add it as well. CC: Alexander Gordeev <agordeev@linux.ibm.com> CC: Bjorn Helgaas <helgaas@kernel.org> Signed-off-by: Yury Norov <yury.norov@gmail.com>
Diffstat (limited to '')
-rw-r--r--include/linux/cpumask.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 7f7f17cfd21d..87d9784e009d 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -285,6 +285,44 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
}
/**
+ * cpumask_next_and_wrap - get the next cpu in *src1p & *src2p, starting from
+ * @n+1. If nothing found, wrap around and start from
+ * the beginning
+ * @n: the cpu prior to the place to search (i.e. search starts from @n+1)
+ * @src1p: the first cpumask pointer
+ * @src2p: the second cpumask pointer
+ *
+ * Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src1p & @src2p is empty.
+ */
+static __always_inline
+unsigned int cpumask_next_and_wrap(int n, const struct cpumask *src1p,
+ const struct cpumask *src2p)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_next_and_bit_wrap(cpumask_bits(src1p), cpumask_bits(src2p),
+ small_cpumask_bits, n + 1);
+}
+
+/**
+ * cpumask_next_wrap - get the next cpu in *src, starting from @n+1. If nothing
+ * found, wrap around and start from the beginning
+ * @n: the cpu prior to the place to search (i.e. search starts from @n+1)
+ * @src: cpumask pointer
+ *
+ * Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src is empty.
+ */
+static __always_inline
+unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_next_bit_wrap(cpumask_bits(src), small_cpumask_bits, n + 1);
+}
+
+/**
* for_each_cpu - iterate over every cpu in a mask
* @cpu: the (optionally unsigned) integer iterator
* @mask: the cpumask pointer