Re: [EXTERNAL] Re: [PATCH V2 net-next] net: mana: Assigning IRQ affinity on HT cores

From: Souradeep Chakrabarti
Date: Wed Nov 29 2023 - 17:17:45 EST


On Mon, Nov 27, 2023 at 10:06:39AM -0800, Jakub Kicinski wrote:
> On Mon, 27 Nov 2023 09:36:38 +0000 Souradeep Chakrabarti wrote:
> > easier to keep things inside the mana driver code here
>
> Easier for who? Upstream we care about consistency and maintainability
> across all drivers.
I am refactoring the code and putting some of the changes in topology.h
and in nodemask.h. I am sharing the proposed change here for those two
files. Please let me know if they are acceptable.

Added a new helper to iterate on numa nodes with cpu and start from a
particular node, instead of first node. This helps when we want to
iterate from the local numa node.

diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 8d07116caaf1..6e4528376164 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -392,6 +392,15 @@ 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_next_mask(node_start, node_next, mask) \
+ for ((node_next) = (node_start); \
+ (node_next) < MAX_NUMNODES; \
+ (node_next) = next_node((node_next), (mask)))
+#else
+#define for_each_node_next_mask(node_start, node_next, mask) \
+ for_each_node_mask(node_next, mask)
+#endif
/*
* Bitmasks that are kept for all the nodes.
*/
@@ -440,6 +449,8 @@ 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_next_state(__node_start, __node_next, __state) \
+ for_each_node_next_mask((__node_start), (__node_next), node_states[__state])

#define first_online_node first_node(node_states[N_ONLINE])
#define first_memory_node first_node(node_states[N_MEMORY])
@@ -489,7 +500,8 @@ static inline int num_node_state(enum node_states state)

#define for_each_node_state(node, __state) \
for ( (node) = 0; (node) == 0; (node) = 1)
-
+#define for_each_node_next_state(node, next_node, _state) \
+ for_each_node_state(node, __state)
#define first_online_node 0
#define first_memory_node 0
#define next_online_node(nid) (MAX_NUMNODES)
@@ -535,6 +547,8 @@ static inline int node_random(const nodemask_t *maskp)

#define for_each_node(node) for_each_node_state(node, N_POSSIBLE)
#define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
+#define for_each_online_node_next(node, next_node) \
+ for_each_node_next_state(node, next_node, N_ONLINE)

/*
* For nodemask scratch area.
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 52f5850730b3..a06b16e5a955 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -43,6 +43,9 @@
for_each_online_node(node) \
if (nr_cpus_node(node))

+#define for_each_next_node_with_cpus(node, next_node) \
+ for_each_online_node_next(node, next_node) \
+ if (nr_cpus_node(next_node))
int arch_update_cpu_topology(void);

/* Conform to ACPI 2.0 SLIT distance definitions */