Skip to content

Commit 3268cb2

Browse files
committed
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 <[email protected]> CC: Bjorn Helgaas <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent dc5bb9b commit 3268cb2

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

include/linux/cpumask.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,44 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
284284
small_cpumask_bits, n + 1);
285285
}
286286

287+
/**
288+
* cpumask_next_and_wrap - get the next cpu in *src1p & *src2p, starting from
289+
* @n+1. If nothing found, wrap around and start from
290+
* the beginning
291+
* @n: the cpu prior to the place to search (i.e. search starts from @n+1)
292+
* @src1p: the first cpumask pointer
293+
* @src2p: the second cpumask pointer
294+
*
295+
* Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src1p & @src2p is empty.
296+
*/
297+
static __always_inline
298+
unsigned int cpumask_next_and_wrap(int n, const struct cpumask *src1p,
299+
const struct cpumask *src2p)
300+
{
301+
/* -1 is a legal arg here. */
302+
if (n != -1)
303+
cpumask_check(n);
304+
return find_next_and_bit_wrap(cpumask_bits(src1p), cpumask_bits(src2p),
305+
small_cpumask_bits, n + 1);
306+
}
307+
308+
/**
309+
* cpumask_next_wrap - get the next cpu in *src, starting from @n+1. If nothing
310+
* found, wrap around and start from the beginning
311+
* @n: the cpu prior to the place to search (i.e. search starts from @n+1)
312+
* @src: cpumask pointer
313+
*
314+
* Return: next set bit, wrapped if needed, or >= nr_cpu_ids if @src is empty.
315+
*/
316+
static __always_inline
317+
unsigned int cpumask_next_wrap(int n, const struct cpumask *src)
318+
{
319+
/* -1 is a legal arg here. */
320+
if (n != -1)
321+
cpumask_check(n);
322+
return find_next_bit_wrap(cpumask_bits(src), small_cpumask_bits, n + 1);
323+
}
324+
287325
/**
288326
* for_each_cpu - iterate over every cpu in a mask
289327
* @cpu: the (optionally unsigned) integer iterator

0 commit comments

Comments
 (0)