diff mbox series

[RFC,1/3] x86/numa: Introduce numa_find_node(start, end)

Message ID 6bf1866161446f03105ec50c3a09de194d830bc3.1683742429.git.alison.schofield@intel.com
State New, archived
Headers show
Series Apply SRAT defined PXM to entire CFMWS | expand

Commit Message

Alison Schofield May 10, 2023, 6:44 p.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

phys_to_target_node(phys_addr_t start) returns a NUMA node id for
a single physical address. In order to discover if there is a NUMA
node assigned to any, in a range of addressses, there is no solution.

Repeatedly calling phys_to_target_node() from start/end is too
expensive to consider. Examining the numa memblks is nicer.

Introduce numa_find_node(start, end) to return the first NUMA node
found anywhere in the start/end HPA range.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 arch/x86/include/asm/numa.h |  1 +
 arch/x86/mm/numa.c          | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

Comments

Dan Williams May 11, 2023, 10:46 p.m. UTC | #1
alison.schofield@ wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> phys_to_target_node(phys_addr_t start) returns a NUMA node id for
> a single physical address. In order to discover if there is a NUMA
> node assigned to any, in a range of addressses, there is no solution.
> 
> Repeatedly calling phys_to_target_node() from start/end is too
> expensive to consider. Examining the numa memblks is nicer.
> 
> Introduce numa_find_node(start, end) to return the first NUMA node
> found anywhere in the start/end HPA range.

I don't think this patch stands on its own, it assumes that something
*wants* to scan for nodes by a range. Maybe it becomes clearer in a
follow-on patch, but this feels like it wants squashing.
diff mbox series

Patch

diff --git a/arch/x86/include/asm/numa.h b/arch/x86/include/asm/numa.h
index e3bae2b60a0d..5f2b811f1a5f 100644
--- a/arch/x86/include/asm/numa.h
+++ b/arch/x86/include/asm/numa.h
@@ -34,6 +34,7 @@  extern nodemask_t numa_nodes_parsed __initdata;
 
 extern int __init numa_add_memblk(int nodeid, u64 start, u64 end);
 extern void __init numa_set_distance(int from, int to, int distance);
+extern int __init numa_find_node(u64 start, u64 end);
 
 static inline void set_apicid_to_node(int apicid, s16 node)
 {
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 2aadb2019b4f..62990977f720 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -225,6 +225,20 @@  static void __init alloc_node_data(int nid)
 	node_set_online(nid);
 }
 
+/* find node with any memblk start/end */
+int __init numa_find_node(u64 start, u64 end)
+{
+	struct numa_meminfo *mi = &numa_meminfo;
+
+	for (int i = 0; i < mi->nr_blks; i++) {
+		struct numa_memblk *bi = &mi->blk[i];
+
+		if (start <= bi->start && end >= bi->end)
+			return bi->nid;
+	}
+	return NUMA_NO_NODE;
+}
+
 /**
  * numa_cleanup_meminfo - Cleanup a numa_meminfo
  * @mi: numa_meminfo to clean up