Skip to content

Commit 5f75ff2

Browse files
valschneiderYuryNorov
authored andcommitted
cpumask: Introduce for_each_cpu_andnot()
for_each_cpu_and() is very convenient as it saves having to allocate a temporary cpumask to store the result of cpumask_and(). The same issue applies to cpumask_andnot() which doesn't actually need temporary storage for iteration purposes. Following what has been done for for_each_cpu_and(), introduce for_each_cpu_andnot(). Signed-off-by: Valentin Schneider <vschneid@redhat.com>
1 parent 90d4829 commit 5f75ff2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/linux/cpumask.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,24 @@ unsigned int __pure cpumask_next_wrap(int n, const struct cpumask *mask, int sta
306306
#define for_each_cpu_and(cpu, mask1, mask2) \
307307
for_each_and_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits)
308308

309+
/**
310+
* for_each_cpu_andnot - iterate over every cpu present in one mask, excluding
311+
* those present in another.
312+
* @cpu: the (optionally unsigned) integer iterator
313+
* @mask1: the first cpumask pointer
314+
* @mask2: the second cpumask pointer
315+
*
316+
* This saves a temporary CPU mask in many places. It is equivalent to:
317+
* struct cpumask tmp;
318+
* cpumask_andnot(&tmp, &mask1, &mask2);
319+
* for_each_cpu(cpu, &tmp)
320+
* ...
321+
*
322+
* After the loop, cpu is >= nr_cpu_ids.
323+
*/
324+
#define for_each_cpu_andnot(cpu, mask1, mask2) \
325+
for_each_andnot_bit(cpu, cpumask_bits(mask1), cpumask_bits(mask2), nr_cpumask_bits)
326+
309327
/**
310328
* cpumask_any_but - return a "random" in a cpumask, but not this one.
311329
* @mask: the cpumask to search

include/linux/find.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ unsigned long find_next_bit_le(const void *addr, unsigned
498498
(bit) = find_next_and_bit((addr1), (addr2), (size), (bit)), (bit) < (size);\
499499
(bit)++)
500500

501+
#define for_each_andnot_bit(bit, addr1, addr2, size) \
502+
for ((bit) = 0; \
503+
(bit) = find_next_andnot_bit((addr1), (addr2), (size), (bit)), (bit) < (size);\
504+
(bit)++)
505+
501506
/* same as for_each_set_bit() but use bit as value to start with */
502507
#define for_each_set_bit_from(bit, addr, size) \
503508
for (; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++)

0 commit comments

Comments
 (0)