cpumask: introduce cpumask_random()

Propagate find_random_bit() to cpumask API.

CC: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
This commit is contained in:
Yury Norov [NVIDIA]
2025-06-19 14:26:24 -04:00
committed by Yury Norov
parent c56f97c5c7
commit 012b104342

View 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