[PATCH 1/2] nodemask: Introduce for_each_node_mask_wrap/for_each_node_state_wrap()

From: Andrea Righi
Date: Fri Nov 29 2024 - 13:13:51 EST


Introduce NUMA node iterators to support circular iteration, starting
from a specified node.

Cc: Yury Norov <yury.norov@xxxxxxxxx>
Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
---
include/linux/nodemask.h | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index b61438313a73..c99cea40dfac 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -392,6 +392,16 @@ static inline void __nodes_fold(nodemask_t *dstp, const nodemask_t *origp,
for ((node) = 0; (node) < 1 && !nodes_empty(mask); (node)++)
#endif /* MAX_NUMNODES */

+#if MAX_NUMNODES > 1
+#define for_each_node_mask_wrap(node, nodemask, start) \
+ for_each_set_bit_wrap((node), (nodemask)->bits, MAX_NUMNODES, (start))
+#else /* MAX_NUMNODES == 1 */
+#define for_each_node_mask_wrap(node, mask, start) \
+ for ((node) = 0; \
+ (node) < 1 && !nodes_empty(mask); \
+ (node)++, (void)(start), (void)(cnt))
+#endif /* MAX_NUMNODES */
+
/*
* Bitmasks that are kept for all the nodes.
*/
@@ -441,6 +451,9 @@ static inline int num_node_state(enum node_states state)
#define for_each_node_state(__node, __state) \
for_each_node_mask((__node), node_states[__state])

+#define for_each_node_state_wrap(__node, __state, __start) \
+ for_each_node_mask_wrap((__node), &node_states[__state], __start)
+
#define first_online_node first_node(node_states[N_ONLINE])
#define first_memory_node first_node(node_states[N_MEMORY])
static inline unsigned int next_online_node(int nid)
--
2.47.1