[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221021121927.2893692-3-vschneid@redhat.com>
Date: Fri, 21 Oct 2022 13:19:26 +0100
From: Valentin Schneider <vschneid@...hat.com>
To: netdev@...r.kernel.org, linux-rdma@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: Saeed Mahameed <saeedm@...dia.com>,
Leon Romanovsky <leon@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Yury Norov <yury.norov@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Ingo Molnar <mingo@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Vincent Guittot <vincent.guittot@...aro.org>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Steven Rostedt <rostedt@...dmis.org>,
Mel Gorman <mgorman@...e.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heiko Carstens <hca@...ux.ibm.com>,
Tony Luck <tony.luck@...el.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Gal Pressman <gal@...dia.com>,
Tariq Toukan <tariqt@...dia.com>,
Jesse Brandeburg <jesse.brandeburg@...el.com>
Subject: [PATCH v5 2/3] sched/topology: Introduce for_each_numa_hop_mask()
The recently introduced sched_numa_hop_mask() exposes cpumasks of CPUs
reachable within a given distance budget, wrap the logic for iterating over
all (distance, mask) values inside an iterator macro.
Signed-off-by: Valentin Schneider <vschneid@...hat.com>
---
include/linux/topology.h | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 3e91ae6d0ad58..8185e12ec1ccc 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -246,16 +246,36 @@ static inline const struct cpumask *cpu_cpu_mask(int cpu)
}
#ifdef CONFIG_NUMA
-extern const struct cpumask *sched_numa_hop_mask(int node, int hops);
+extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int hops);
#else
-static inline const struct cpumask *sched_numa_hop_mask(int node, int hops)
+static inline const struct cpumask *
+sched_numa_hop_mask(unsigned int node, unsigned int hops)
{
- if (node == NUMA_NO_NODE && !hops)
- return cpu_online_mask;
-
return ERR_PTR(-EOPNOTSUPP);
}
#endif /* CONFIG_NUMA */
+/**
+ * for_each_numa_hop_mask - iterate over cpumasks of increasing NUMA distance
+ * from a given node.
+ * @mask: the iteration variable.
+ * @node: the NUMA node to start the search from.
+ *
+ * Requires rcu_lock to be held.
+ *
+ * Yields cpu_online_mask for @node == NUMA_NO_NODE.
+ */
+#define for_each_numa_hop_mask(mask, node) \
+ for (unsigned int __hops = 0; \
+ /* \
+ * Unsightly trickery required as we can't both initialize \
+ * @mask and declare __hops in for()'s first clause \
+ */ \
+ mask = __hops > 0 ? mask : \
+ node == NUMA_NO_NODE ? \
+ cpu_online_mask : sched_numa_hop_mask(node, 0), \
+ !IS_ERR_OR_NULL(mask); \
+ __hops++, \
+ mask = sched_numa_hop_mask(node, __hops))
#endif /* _LINUX_TOPOLOGY_H */
--
2.31.1
Powered by blists - more mailing lists