]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpumask: introduce cpumask_random()
authorYury Norov [NVIDIA] <yury.norov@gmail.com>
Thu, 19 Jun 2025 18:26:24 +0000 (14:26 -0400)
committerYury Norov <yury.norov@gmail.com>
Tue, 8 Jul 2025 23:11:57 +0000 (19:11 -0400)
Propagate find_random_bit() to cpumask API.

CC: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
include/linux/cpumask.h

index 7ae80a7ca81efd7a3d8ca1674e5d519548b5e030..39b71b662da384fd043c0d3b201f8e80cfd6151e 100644 (file)
@@ -354,6 +354,18 @@ unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
        return find_next_bit_wrap(cpumask_bits(src), small_cpumask_bits, n + 1);
 }
 
+/**
+ * cpumask_random - get random cpu in *src.
+ * @src: cpumask pointer
+ *
+ * Return: random set bit, or >= nr_cpu_ids if @src is empty.
+ */
+static __always_inline
+unsigned int cpumask_random(const struct cpumask *src)
+{
+       return find_random_bit(cpumask_bits(src), nr_cpu_ids);
+}
+
 /**
  * for_each_cpu - iterate over every cpu in a mask
  * @cpu: the (optionally unsigned) integer iterator