diff mbox series

[RFC,bitmap-for-next,1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro

Message ID 20221006122112.663119-2-vschneid@redhat.com (mailing list archive)
State New, archived
Headers show
Series lib/cpumask, blk_mq: Fix blk_mq_hctx_next_cpu() vs cpumask_check() | expand

Commit Message

Valentin Schneider Oct. 6, 2022, 12:21 p.m. UTC
In preparation of introducing cpumask_next_and_wrap(), gather the
would-be-boiler-plate logic into a macro, as was done in

e79864f3164c ("lib/find_bit: optimize find_next_bit() functions")

Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
 lib/cpumask.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/lib/cpumask.c b/lib/cpumask.c
index c7c392514fd3..6e576485c84f 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -7,8 +7,27 @@ 
 #include <linux/memblock.h>
 #include <linux/numa.h>
 
+#define CPUMASK_NEXT_WRAP(FETCH_NEXT, n, start, wrap)			\
+({									\
+	unsigned int next;						\
+									\
+again:									\
+	next = (FETCH_NEXT);						\
+									\
+	if (wrap && n < start && next >= start) {			\
+		next = nr_cpumask_bits;					\
+	} else if (next >= nr_cpumask_bits) {				\
+		wrap = true;						\
+		n = -1;							\
+		goto again;						\
+	}								\
+									\
+	next;								\
+})
+
 /**
- * cpumask_next_wrap - helper to implement for_each_cpu_wrap
+ * cpumask_next_wrap - Get the next CPU in a mask, starting from a given
+ *                     position and wrapping around to visit all CPUs.
  * @n: the cpu prior to the place to search
  * @mask: the cpumask pointer
  * @start: the start point of the iteration
@@ -21,21 +40,7 @@ 
  */
 unsigned int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
 {
-	unsigned int next;
-
-again:
-	next = cpumask_next(n, mask);
-
-	if (wrap && n < start && next >= start) {
-		return nr_cpumask_bits;
-
-	} else if (next >= nr_cpumask_bits) {
-		wrap = true;
-		n = -1;
-		goto again;
-	}
-
-	return next;
+	return CPUMASK_NEXT_WRAP(cpumask_next(n, mask), n, start, wrap);
 }
 EXPORT_SYMBOL(cpumask_next_wrap);