diff mbox

[RFC,v2,11/25] x86: NUMA: Move common code from srat.c

Message ID 1490716413-19796-12-git-send-email-vijay.kilari@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vijay Kilari March 28, 2017, 3:53 p.m. UTC
From: Vijaya Kumar K <Vijaya.Kumar@cavium.com>

Move code from xen/arch/x86/srat.c to xen/common/numa.c
so that it can be used by other archs.
Few generic static functions in x86/srat.c are made
non-static common/numa.c

Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
---
 xen/arch/x86/srat.c        | 152 ++-------------------------------------------
 xen/common/numa.c          | 146 +++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/acpi.h |   3 -
 xen/include/asm-x86/numa.h |   2 -
 xen/include/xen/numa.h     |  14 +++++
 5 files changed, 164 insertions(+), 153 deletions(-)

Comments

Julien Grall May 8, 2017, 5:06 p.m. UTC | #1
Hi Vijay,

On 28/03/17 16:53, vijay.kilari@gmail.com wrote:
> From: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
>
> Move code from xen/arch/x86/srat.c to xen/common/numa.c
> so that it can be used by other archs.
> Few generic static functions in x86/srat.c are made
> non-static common/numa.c
>
> Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
> ---
>  xen/arch/x86/srat.c        | 152 ++-------------------------------------------
>  xen/common/numa.c          | 146 +++++++++++++++++++++++++++++++++++++++++++
>  xen/include/asm-x86/acpi.h |   3 -
>  xen/include/asm-x86/numa.h |   2 -
>  xen/include/xen/numa.h     |  14 +++++
>  5 files changed, 164 insertions(+), 153 deletions(-)
>
> diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
> index 2cc87a3..55947bb 100644
> --- a/xen/arch/x86/srat.c
> +++ b/xen/arch/x86/srat.c
> @@ -23,9 +23,8 @@
>
>  static struct acpi_table_slit *__read_mostly acpi_slit;
>
> -static nodemask_t __initdata memory_nodes_parsed;
> -static nodemask_t __initdata processor_nodes_parsed;
> -static struct node __initdata nodes[MAX_NUMNODES];
> +extern nodemask_t processor_nodes_parsed;
> +extern nodemask_t memory_nodes_parsed;

On v1, Jan clearly NAK to changes like this. Declarations belong in 
header files. It is a different variable compare to v1, but I would have 
expected you to apply what he said everywhere...

[...]

> diff --git a/xen/common/numa.c b/xen/common/numa.c
> index 207ebd8..1789bba 100644
> --- a/xen/common/numa.c
> +++ b/xen/common/numa.c
> @@ -32,6 +32,8 @@
>  static int numa_setup(char *s);
>  custom_param("numa", numa_setup);
>
> +nodemask_t __initdata memory_nodes_parsed;
> +nodemask_t __initdata processor_nodes_parsed;
>  struct node_data node_data[MAX_NUMNODES];
>
>  /* Mapping from pdx to node id */
> @@ -47,6 +49,10 @@ cpumask_t __read_mostly node_to_cpumask[MAX_NUMNODES];
>
>  static bool numa_off = 0;
>  static bool acpi_numa = 1;
> +static int num_node_memblks;
> +static struct node node_memblk_range[NR_NODE_MEMBLKS];
> +static nodeid_t memblk_nodeid[NR_NODE_MEMBLKS];
> +static struct node __initdata nodes[MAX_NUMNODES];

It would make sense to keep those variables together with 
{memory,processor}_nodes_parsed.

[...]

> +int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
> +{
> +    int i;
> +
> +    for (i = 0; i < get_num_node_memblks(); i++) {

common/numa.c is using Xen coding style whilst arch/x86/srat.c is using 
Linux coding style.

You decided to validly switch to soft tab, making quite difficult to 
check if this patch is only code movement. But you did not go far enough 
and fix the coding style of the code moved.

Please do it properly and not half of it. For simplicity I would be OK 
that it is done in this patch. But this needs to be clearly written in 
the commit message.

> +        struct node *nd = get_node_memblk_range(i);
> +
> +        if (nd->start <= start && nd->end > end &&
> +            get_memblk_nodeid(i) == node)
> +            return 1;
> +    }
> +
> +    return 0;
> +}

[...]

> diff --git a/xen/include/asm-x86/numa.h b/xen/include/asm-x86/numa.h
> index 421e8b7..7cff220 100644
> --- a/xen/include/asm-x86/numa.h
> +++ b/xen/include/asm-x86/numa.h
> @@ -47,8 +47,6 @@ static inline __attribute__((pure)) nodeid_t phys_to_nid(paddr_t addr)
>  #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
>                                   NODE_DATA(nid)->node_spanned_pages)
>
> -extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
> -
>  void srat_parse_regions(uint64_t addr);
>  extern uint8_t __node_distance(nodeid_t a, nodeid_t b);
>  unsigned int arch_get_dma_bitsize(void);
> diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
> index eed40af..ee53526 100644
> --- a/xen/include/xen/numa.h
> +++ b/xen/include/xen/numa.h
> @@ -13,6 +13,7 @@
>  #define NUMA_NO_DISTANCE 0xFF
>
>  #define MAX_NUMNODES    (1 << NODES_SHIFT)
> +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)
>
>  struct node {
>      paddr_t start;
> @@ -28,6 +29,19 @@ extern nodeid_t acpi_setup_node(unsigned int pxm);
>  extern void srat_detect_node(int cpu);
>  extern void setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_t end);
>  extern void init_cpu_to_node(void);
> +extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
> +extern int conflicting_memblks(paddr_t start, paddr_t end);
> +extern void cutoff_node(int i, paddr_t start, paddr_t end);
> +extern struct node *get_numa_node(int id);
> +extern nodeid_t get_memblk_nodeid(int memblk);
> +extern nodeid_t *get_memblk_nodeid_map(void);
> +extern struct node *get_node_memblk_range(int memblk);
> +extern struct node *get_memblk(int memblk);
> +extern int numa_add_memblk(nodeid_t nodeid, paddr_t start, uint64_t size);
> +extern int get_num_node_memblks(void);
> +extern int arch_sanitize_nodes_memory(void);
> +extern void numa_failed(void);
> +extern int numa_scan_nodes(uint64_t start, uint64_t end);

See my comment on the previous patch.

>
>  #define vcpu_to_node(v) (cpu_to_node((v)->processor))
>
>

Cheers,
Vijay Kilari May 10, 2017, 9 a.m. UTC | #2
and

On Mon, May 8, 2017 at 10:36 PM, Julien Grall <julien.grall@arm.com> wrote:
> Hi Vijay,
>
>
> On 28/03/17 16:53, vijay.kilari@gmail.com wrote:
>>
>> From: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
>>
>> Move code from xen/arch/x86/srat.c to xen/common/numa.c
>> so that it can be used by other archs.
>> Few generic static functions in x86/srat.c are made
>> non-static common/numa.c
>>
>> Signed-off-by: Vijaya Kumar K <Vijaya.Kumar@cavium.com>
>> ---
>>  xen/arch/x86/srat.c        | 152
>> ++-------------------------------------------
>>  xen/common/numa.c          | 146
>> +++++++++++++++++++++++++++++++++++++++++++
>>  xen/include/asm-x86/acpi.h |   3 -
>>  xen/include/asm-x86/numa.h |   2 -
>>  xen/include/xen/numa.h     |  14 +++++
>>  5 files changed, 164 insertions(+), 153 deletions(-)
>>
>> diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
>> index 2cc87a3..55947bb 100644
>> --- a/xen/arch/x86/srat.c
>> +++ b/xen/arch/x86/srat.c
>> @@ -23,9 +23,8 @@
>>
>>  static struct acpi_table_slit *__read_mostly acpi_slit;
>>
>> -static nodemask_t __initdata memory_nodes_parsed;
>> -static nodemask_t __initdata processor_nodes_parsed;
>> -static struct node __initdata nodes[MAX_NUMNODES];
>> +extern nodemask_t processor_nodes_parsed;
>> +extern nodemask_t memory_nodes_parsed;
>
>
> On v1, Jan clearly NAK to changes like this. Declarations belong in header
> files. It is a different variable compare to v1, but I would have expected
> you to apply what he said everywhere...

Ok I will move these to header files.

One more change that I made is moved from static to global.
because creating accessor functions around these nodesmask_t is tricky because
the macros (defined in nodemask.h) does not take pointer parameters.

I will add comment.

>
> [...]
>
>> diff --git a/xen/common/numa.c b/xen/common/numa.c
>> index 207ebd8..1789bba 100644
>> --- a/xen/common/numa.c
>> +++ b/xen/common/numa.c
>> @@ -32,6 +32,8 @@
>>  static int numa_setup(char *s);
>>  custom_param("numa", numa_setup);
>>
>> +nodemask_t __initdata memory_nodes_parsed;
>> +nodemask_t __initdata processor_nodes_parsed;
>>  struct node_data node_data[MAX_NUMNODES];
>>
>>  /* Mapping from pdx to node id */
>> @@ -47,6 +49,10 @@ cpumask_t __read_mostly node_to_cpumask[MAX_NUMNODES];
>>
>>  static bool numa_off = 0;
>>  static bool acpi_numa = 1;
>> +static int num_node_memblks;
>> +static struct node node_memblk_range[NR_NODE_MEMBLKS];
>> +static nodeid_t memblk_nodeid[NR_NODE_MEMBLKS];
>> +static struct node __initdata nodes[MAX_NUMNODES];
>
>
> It would make sense to keep those variables together with
> {memory,processor}_nodes_parsed.

ok
>
> [...]
>
>> +int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
>> +{
>> +    int i;
>> +
>> +    for (i = 0; i < get_num_node_memblks(); i++) {
>
>
> common/numa.c is using Xen coding style whilst arch/x86/srat.c is using
> Linux coding style.
>
> You decided to validly switch to soft tab, making quite difficult to check
> if this patch is only code movement. But you did not go far enough and fix
> the coding style of the code moved.
>
> Please do it properly and not half of it. For simplicity I would be OK that
> it is done in this patch. But this needs to be clearly written in the commit
> message.

I will add in commit message about coding style changes to destination file
compared to source file.

>
>> +        struct node *nd = get_node_memblk_range(i);
>> +
>> +        if (nd->start <= start && nd->end > end &&
>> +            get_memblk_nodeid(i) == node)
>> +            return 1;
>> +    }
>> +
>> +    return 0;
>> +}
>
>
> [...]
>
>
>> diff --git a/xen/include/asm-x86/numa.h b/xen/include/asm-x86/numa.h
>> index 421e8b7..7cff220 100644
>> --- a/xen/include/asm-x86/numa.h
>> +++ b/xen/include/asm-x86/numa.h
>> @@ -47,8 +47,6 @@ static inline __attribute__((pure)) nodeid_t
>> phys_to_nid(paddr_t addr)
>>  #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
>>                                   NODE_DATA(nid)->node_spanned_pages)
>>
>> -extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
>> -
>>  void srat_parse_regions(uint64_t addr);
>>  extern uint8_t __node_distance(nodeid_t a, nodeid_t b);
>>  unsigned int arch_get_dma_bitsize(void);
>> diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
>> index eed40af..ee53526 100644
>> --- a/xen/include/xen/numa.h
>> +++ b/xen/include/xen/numa.h
>> @@ -13,6 +13,7 @@
>>  #define NUMA_NO_DISTANCE 0xFF
>>
>>  #define MAX_NUMNODES    (1 << NODES_SHIFT)
>> +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)
>>
>>  struct node {
>>      paddr_t start;
>> @@ -28,6 +29,19 @@ extern nodeid_t acpi_setup_node(unsigned int pxm);
>>  extern void srat_detect_node(int cpu);
>>  extern void setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_t
>> end);
>>  extern void init_cpu_to_node(void);
>> +extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
>> +extern int conflicting_memblks(paddr_t start, paddr_t end);
>> +extern void cutoff_node(int i, paddr_t start, paddr_t end);
>> +extern struct node *get_numa_node(int id);
>> +extern nodeid_t get_memblk_nodeid(int memblk);
>> +extern nodeid_t *get_memblk_nodeid_map(void);
>> +extern struct node *get_node_memblk_range(int memblk);
>> +extern struct node *get_memblk(int memblk);
>> +extern int numa_add_memblk(nodeid_t nodeid, paddr_t start, uint64_t
>> size);
>> +extern int get_num_node_memblks(void);
>> +extern int arch_sanitize_nodes_memory(void);
>> +extern void numa_failed(void);
>> +extern int numa_scan_nodes(uint64_t start, uint64_t end);
>
>
> See my comment on the previous patch.

I understand that we can drop this extern
>
>>
>>  #define vcpu_to_node(v) (cpu_to_node((v)->processor))
>>
>>
>
> Cheers,
>
> --
> Julien Grall
diff mbox

Patch

diff --git a/xen/arch/x86/srat.c b/xen/arch/x86/srat.c
index 2cc87a3..55947bb 100644
--- a/xen/arch/x86/srat.c
+++ b/xen/arch/x86/srat.c
@@ -23,9 +23,8 @@ 
 
 static struct acpi_table_slit *__read_mostly acpi_slit;
 
-static nodemask_t __initdata memory_nodes_parsed;
-static nodemask_t __initdata processor_nodes_parsed;
-static struct node __initdata nodes[MAX_NUMNODES];
+extern nodemask_t processor_nodes_parsed;
+extern nodemask_t memory_nodes_parsed;
 
 /*
  * Keep BIOS's CPU2node information, should not be used for memory allocaion
@@ -43,49 +42,8 @@  static struct pxm2node __read_mostly pxm2node[MAX_NUMNODES] =
 
 static unsigned node_to_pxm(nodeid_t n);
 
-static int num_node_memblks;
-static struct node node_memblk_range[NR_NODE_MEMBLKS];
-static nodeid_t memblk_nodeid[NR_NODE_MEMBLKS];
 static __initdata DECLARE_BITMAP(memblk_hotplug, NR_NODE_MEMBLKS);
 
-static struct node *get_numa_node(int id)
-{
-	return &nodes[id];
-}
-
-static nodeid_t get_memblk_nodeid(int id)
-{
-	return memblk_nodeid[id];
-}
-
-static nodeid_t *get_memblk_nodeid_map(void)
-{
-	return &memblk_nodeid[0];
-}
-
-static struct node *get_node_memblk_range(int memblk)
-{
-	return &node_memblk_range[memblk];
-}
-
-static int get_num_node_memblks(void)
-{
-	return num_node_memblks;
-}
-
-static int __init numa_add_memblk(nodeid_t nodeid, paddr_t start, uint64_t size)
-{
-	if (nodeid >= NR_NODE_MEMBLKS)
-		return -EINVAL;
-
-	node_memblk_range[num_node_memblks].start = start;
-	node_memblk_range[num_node_memblks].end = start + size;
-	memblk_nodeid[num_node_memblks] = nodeid;
-	num_node_memblks++;
-
-	return 0;
-}
-
 static inline bool node_found(unsigned int idx, unsigned int pxm)
 {
 	return ((pxm2node[idx].pxm == pxm) &&
@@ -156,54 +114,7 @@  nodeid_t acpi_setup_node(unsigned int pxm)
 	return node;
 }
 
-int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
-{
-	int i;
-
-	for (i = 0; i < get_num_node_memblks(); i++) {
-		struct node *nd = get_node_memblk_range(i);
-
-		if (nd->start <= start && nd->end > end &&
-		    get_memblk_nodeid(i) == node)
-			return 1;
-	}
-
-	return 0;
-}
-
-static int __init conflicting_memblks(paddr_t start, paddr_t end)
-{
-	int i;
-
-	for (i = 0; i < get_num_node_memblks(); i++) {
-		struct node *nd = get_node_memblk_range(i);
-		if (nd->start == nd->end)
-			continue;
-		if (nd->end > start && nd->start < end)
-			return i;
-		if (nd->end == end && nd->start == start)
-			return i;
-	}
-	return -1;
-}
-
-static void __init cutoff_node(int i, paddr_t start, paddr_t end)
-{
-	struct node *nd = get_numa_node(i);
-
-	if (nd->start < start) {
-		nd->start = start;
-		if (nd->end < nd->start)
-			nd->start = nd->end;
-	}
-	if (nd->end > end) {
-		nd->end = end;
-		if (nd->start > nd->end)
-			nd->start = nd->end;
-	}
-}
-
-static void __init numa_failed(void)
+void __init numa_failed(void)
 {
 	int i;
 	printk(KERN_ERR "SRAT: SRAT not used.\n");
@@ -419,7 +330,7 @@  acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma)
 
 /* Sanity check to catch more bad SRATs (they are amazingly common).
    Make sure the PXMs cover all memory. */
-static int __init arch_sanitize_nodes_memory(void)
+int __init arch_sanitize_nodes_memory(void)
 {
 	int i;
 
@@ -516,61 +427,6 @@  void __init srat_parse_regions(uint64_t addr)
 	pfn_pdx_hole_setup(mask >> PAGE_SHIFT);
 }
 
-/* Use the information discovered above to actually set up the nodes. */
-int __init numa_scan_nodes(uint64_t start, uint64_t end)
-{
-	int i;
-	nodemask_t all_nodes_parsed;
-	struct node *memblks;
-	nodeid_t *nodeids;
-
-	/* First clean up the node list */
-	for (i = 0; i < MAX_NUMNODES; i++)
-		cutoff_node(i, start, end);
-
-	if (get_acpi_numa() == 0)
-		return -1;
-
-	if (!arch_sanitize_nodes_memory()) {
-		numa_failed();
-		return -1;
-	}
-
-	memblks = get_node_memblk_range(0);
-	nodeids = get_memblk_nodeid_map();
-	if (compute_memnode_shift(node_memblk_range, num_node_memblks,
-				  memblk_nodeid, &memnode_shift)) {
-		memnode_shift = 0;
-		printk(KERN_ERR
-		     "SRAT: No NUMA node hash function found. Contact maintainer\n");
-		numa_failed();
-		return -1;
-	}
-
-	nodes_or(all_nodes_parsed, memory_nodes_parsed, processor_nodes_parsed);
-
-	/* Finally register nodes */
-	for_each_node_mask(i, all_nodes_parsed)
-	{
-		struct node *nd = get_numa_node(i);
-		uint64_t size = nd->end - nd->start;
-
-		if ( size == 0 )
-			printk(KERN_WARNING "SRAT: Node %u has no memory. "
-			       "BIOS Bug or mis-configured hardware?\n", i);
-
-		setup_node_bootmem(i, nd->start, nd->end);
-	}
-	for (i = 0; i < nr_cpu_ids; i++) {
-		if (cpu_to_node[i] == NUMA_NO_NODE)
-			continue;
-		if (!node_isset(cpu_to_node[i], processor_nodes_parsed))
-			numa_set_node(i, NUMA_NO_NODE);
-	}
-	numa_init_array();
-	return 0;
-}
-
 static unsigned node_to_pxm(nodeid_t n)
 {
 	unsigned i;
diff --git a/xen/common/numa.c b/xen/common/numa.c
index 207ebd8..1789bba 100644
--- a/xen/common/numa.c
+++ b/xen/common/numa.c
@@ -32,6 +32,8 @@ 
 static int numa_setup(char *s);
 custom_param("numa", numa_setup);
 
+nodemask_t __initdata memory_nodes_parsed;
+nodemask_t __initdata processor_nodes_parsed;
 struct node_data node_data[MAX_NUMNODES];
 
 /* Mapping from pdx to node id */
@@ -47,6 +49,10 @@  cpumask_t __read_mostly node_to_cpumask[MAX_NUMNODES];
 
 static bool numa_off = 0;
 static bool acpi_numa = 1;
+static int num_node_memblks;
+static struct node node_memblk_range[NR_NODE_MEMBLKS];
+static nodeid_t memblk_nodeid[NR_NODE_MEMBLKS];
+static struct node __initdata nodes[MAX_NUMNODES];
 
 bool is_numa_off(void)
 {
@@ -68,6 +74,91 @@  bool srat_disabled(void)
     return numa_off || acpi_numa == 0;
 }
 
+struct node *get_numa_node(int id)
+{
+    return &nodes[id];
+}
+
+nodeid_t get_memblk_nodeid(int id)
+{
+    return memblk_nodeid[id];
+}
+
+nodeid_t *get_memblk_nodeid_map(void)
+{
+    return &memblk_nodeid[0];
+}
+
+struct node *get_node_memblk_range(int memblk)
+{
+    return &node_memblk_range[memblk];
+}
+
+int get_num_node_memblks(void)
+{
+    return num_node_memblks;
+}
+
+int __init numa_add_memblk(nodeid_t nodeid, paddr_t start, uint64_t size)
+{
+    if (nodeid >= NR_NODE_MEMBLKS)
+        return -EINVAL;
+
+    node_memblk_range[num_node_memblks].start = start;
+    node_memblk_range[num_node_memblks].end = start + size;
+    memblk_nodeid[num_node_memblks] = nodeid;
+    num_node_memblks++;
+
+    return 0;
+}
+
+int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
+{
+    int i;
+
+    for (i = 0; i < get_num_node_memblks(); i++) {
+        struct node *nd = get_node_memblk_range(i);
+
+        if (nd->start <= start && nd->end > end &&
+            get_memblk_nodeid(i) == node)
+            return 1;
+    }
+
+    return 0;
+}
+
+int __init conflicting_memblks(paddr_t start, paddr_t end)
+{
+    int i;
+
+    for (i = 0; i < get_num_node_memblks(); i++) {
+        struct node *nd = get_node_memblk_range(i);
+        if (nd->start == nd->end)
+            continue;
+        if (nd->end > start && nd->start < end)
+            return i;
+        if (nd->end == end && nd->start == start)
+            return i;
+    }
+    return -1;
+}
+
+void __init cutoff_node(int i, paddr_t start, paddr_t end)
+{
+    struct node *nd = get_numa_node(i);
+
+    if (nd->start < start) {
+        nd->start = start;
+        if (nd->end < nd->start)
+            nd->start = nd->end;
+    }
+    if (nd->end > end) {
+        nd->end = end;
+        if (nd->start > nd->end)
+            nd->start = nd->end;
+    }
+}
+
 /*
  * Given a shift value, try to populate memnodemap[]
  * Returns :
@@ -306,6 +397,61 @@  void numa_set_node(int cpu, nodeid_t node)
     cpu_to_node[cpu] = node;
 }
 
+/* Use the information discovered above to actually set up the nodes. */
+int __init numa_scan_nodes(uint64_t start, uint64_t end)
+{
+    int i;
+    nodemask_t all_nodes_parsed;
+    struct node *memblks;
+    nodeid_t *nodeids;
+
+    /* First clean up the node list */
+    for (i = 0; i < MAX_NUMNODES; i++)
+        cutoff_node(i, start, end);
+
+    if (get_acpi_numa() == 0)
+        return -1;
+
+    if (!arch_sanitize_nodes_memory()) {
+        numa_failed();
+        return -1;
+    }
+
+    memblks = get_node_memblk_range(0);
+    nodeids = get_memblk_nodeid_map();
+    if (compute_memnode_shift(node_memblk_range, num_node_memblks,
+                  memblk_nodeid, &memnode_shift)) {
+        memnode_shift = 0;
+        printk(KERN_ERR
+             "SRAT: No NUMA node hash function found. Contact maintainer\n");
+        numa_failed();
+        return -1;
+    }
+
+    nodes_or(all_nodes_parsed, memory_nodes_parsed, processor_nodes_parsed);
+
+    /* Finally register nodes */
+    for_each_node_mask(i, all_nodes_parsed)
+    {
+        struct node *nd = get_numa_node(i);
+        uint64_t size = nd->end - nd->start;
+
+        if ( size == 0 )
+            printk(KERN_WARNING "SRAT: Node %u has no memory. "
+                   "BIOS Bug or mis-configured hardware?\n", i);
+
+        setup_node_bootmem(i, nd->start, nd->end);
+    }
+    for (i = 0; i < nr_cpu_ids; i++) {
+        if (cpu_to_node[i] == NUMA_NO_NODE)
+            continue;
+        if (!node_isset(cpu_to_node[i], processor_nodes_parsed))
+            numa_set_node(i, NUMA_NO_NODE);
+    }
+    numa_init_array();
+    return 0;
+}
+
 /* [numa=off] */
 static int __init numa_setup(char *opt)
 {
diff --git a/xen/include/asm-x86/acpi.h b/xen/include/asm-x86/acpi.h
index 445b8e5..e4f3f9a 100644
--- a/xen/include/asm-x86/acpi.h
+++ b/xen/include/asm-x86/acpi.h
@@ -103,9 +103,6 @@  extern void acpi_reserve_bootmem(void);
 
 #define ARCH_HAS_POWER_INIT	1
 
-extern int numa_scan_nodes(u64 start, u64 end);
-#define NR_NODE_MEMBLKS (MAX_NUMNODES*2)
-
 #ifdef CONFIG_ACPI_SLEEP
 
 extern struct acpi_sleep_info acpi_sinfo;
diff --git a/xen/include/asm-x86/numa.h b/xen/include/asm-x86/numa.h
index 421e8b7..7cff220 100644
--- a/xen/include/asm-x86/numa.h
+++ b/xen/include/asm-x86/numa.h
@@ -47,8 +47,6 @@  static inline __attribute__((pure)) nodeid_t phys_to_nid(paddr_t addr)
 #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
                                  NODE_DATA(nid)->node_spanned_pages)
 
-extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
-
 void srat_parse_regions(uint64_t addr);
 extern uint8_t __node_distance(nodeid_t a, nodeid_t b);
 unsigned int arch_get_dma_bitsize(void);
diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
index eed40af..ee53526 100644
--- a/xen/include/xen/numa.h
+++ b/xen/include/xen/numa.h
@@ -13,6 +13,7 @@ 
 #define NUMA_NO_DISTANCE 0xFF
 
 #define MAX_NUMNODES    (1 << NODES_SHIFT)
+#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)
 
 struct node {
     paddr_t start;
@@ -28,6 +29,19 @@  extern nodeid_t acpi_setup_node(unsigned int pxm);
 extern void srat_detect_node(int cpu);
 extern void setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_t end);
 extern void init_cpu_to_node(void);
+extern int valid_numa_range(paddr_t start, paddr_t end, nodeid_t node);
+extern int conflicting_memblks(paddr_t start, paddr_t end);
+extern void cutoff_node(int i, paddr_t start, paddr_t end);
+extern struct node *get_numa_node(int id);
+extern nodeid_t get_memblk_nodeid(int memblk);
+extern nodeid_t *get_memblk_nodeid_map(void);
+extern struct node *get_node_memblk_range(int memblk);
+extern struct node *get_memblk(int memblk);
+extern int numa_add_memblk(nodeid_t nodeid, paddr_t start, uint64_t size);
+extern int get_num_node_memblks(void);
+extern int arch_sanitize_nodes_memory(void);
+extern void numa_failed(void);
+extern int numa_scan_nodes(uint64_t start, uint64_t end);
 
 #define vcpu_to_node(v) (cpu_to_node((v)->processor))