[RFC PATCH bitmap-for-next 1/4] lib/cpumask: Generate cpumask_next_wrap() body with a macro
From: Valentin Schneider
Date: Thu Oct 06 2022 - 08:22:20 EST
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@xxxxxxxxxx>
---
lib/cpumask.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
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);
--
2.31.1