Device tree based NUMA support for Arm - Part#2
v3 cover Device tree based NUMA support for Arm - Part#2
(The Arm device tree based NUMA support patch set contains 35 patches. In order to make stuff easier for reviewers, I split them into 3 parts:
1. Preparation. I have re-sorted the patch series. And moved independent patches to the head of the series - merged in [1]
2. Move generically usable code from x86 to common - this series.
3. Add new code to support Arm.
This series only contains the second part patches. As the whole NUMA series has been reviewed for 1 round in [2], so this series would be v3)
Xen memory allocation and scheduler modules are NUMA aware. But actually, on x86 has implemented the architecture APIs to support NUMA. Arm was providing a set of fake architecture APIs to make it compatible with NUMA awared memory allocation and scheduler.
Arm system was working well as a single node NUMA system with these fake APIs, because we didn't have multiple nodes NUMA system on Arm. But in recent years, more and more Arm devices support multiple nodes NUMA system.
So now we have a new problem. When Xen is running on these Arm devices, Xen still treat them as single node SMP systems. The NUMA affinity capability of Xen memory allocation and scheduler becomes meaningless. Because they rely on input data that does not reflect real NUMA layout.
Xen still think the access time for all of the memory is the same for all CPUs. However, Xen may allocate memory to a VM from different NUMA nodes with different access speeds. This difference can be amplified in workloads inside VM, causing performance instability and timeouts.
So in this patch series, we implement a set of NUMA API to use device tree to describe the NUMA layout. We reuse most of the code of x86 NUMA to create and maintain the mapping between memory and CPU, create the matrix between any two NUMA nodes. Except ACPI and some x86 specified code, we have moved other code to common. In next stage, when we implement ACPI based NUMA for Arm64, we may move the ACPI NUMA code to common too, but in current stage, we keep it as x86 only.
This patch serires has been tested and booted well on one Arm64 NUMA machine and one HPE x86 NUMA machine.
[1] https://lists.xenproject.org/archives/html/xen-devel/2022-06/msg00499.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2021-09/msg01903.html
---
v2 -> v3:
1. Drop enumeration of numa status.
2. Use helpers to get/update acpi_numa.
3. Insert spaces among parameters of strncmp in numa_setup.
4. Drop helpers to access mem_hotplug. Export mem_hotplug for all arch.
5. Remove acpi.h from common/numa.c.
6. Rename acpi_scan_nodes to numa_scan_nodes.
7. Replace u8 by uint8_t for memnodemap.
8. Use unsigned int for memnode_shift and adjust related functions (compute_hash_shift, populate_memnodemap) to use correct types for return values or parameters.
9. Use nodeid_t for nodeid and node numbers.
10. Use __read_mostly and __ro_after_init for appropriate variables.
11. Adjust the __read_mostly and __initdata location for some variables.
12. Convert from plain int to unsigned for cpuid and other proper
13. Remove unnecessary change items in history.
14. Rename arch_get_memory_map to arch_get_ram_range.
15. Use -ENOENT instead of -ENODEV to indicate end of memory map.
16. Add description to code comment that arch_get_ram_range returns RAM range in [start, end) format.
17. Rename bad_srat to numa_fw_bad.
18. Rename node_to_pxm to numa_node_to_arch_nid.
19. Merge patch#7 and #8 into patch#6.
20. Move NR_NODE_MEMBLKS from x86/acpi.h to common/numa.h
22. Use 2-64 for node range.
v1 -> v2:
1. Refine the commit messages of several patches.
2. Merge v1 patch#9,10 into one patch. Introduce the new functions in the same patch that this patch will be used first time.
3. Fold if ( end > mem_hotplug ) to mem_hotplug_update_boundary, in this case, we can drop mem_hotplug_boundary.
4. Remove fw_numa, use enumeration to replace numa_off and acpi_numa.
5. Correct return value of srat_disabled.
6. Introduce numa_enabled_with_firmware.
7. Refine the justification of using !node_data[nid].node_spanned_pages.
8. Use ASSERT to replace VIRTUAL_BUG_ON in phys_to_nid.
9. Adjust the conditional express for ASSERT.
10. Move MAX_NUMNODES from xen/numa.h to asm/numa.h for x86.
11. Use conditional macro to gate MAX_NUMNODES for other architectures.
12. Use arch_get_memory_map to replace arch_get_memory_bank_range and arch_get_memory_bank_number.
13. Remove the !start || !end check, because caller guarantee these two pointers will not be NULL.
14. Add code comment for numa_update_node_memblks to explain:
Assumes all memory regions belonging to a single node
are in one chunk. Holes between them will be included
in the node.
15. Merge this single patch instead of serval patches to move x86 SRAT code to common.
16. Export node_to_pxm to keep pxm information in NUMA scan nodes error messages.
17. Change the code style to target file's Xen code-style.
18. Adjust some __init and __initdata for some functions and variables.
19. Replace CONFIG_ACPI_NUMA by CONFIG_NUMA. Replace "SRAT" texts.
20. Turn numa_scan_nodes to static.
21. Change NR_NUMA_NODES upper bound from 4095 to 255.
Wei Chen (6):
xen/x86: Provide helpers for common code to access acpi_numa xen/x86: move generically usable NUMA code from x86 to common xen/x86: Use ASSERT instead of VIRTUAL_BUG_ON for phys_to_nid xen/x86: use arch_get_ram_range to get information from E820 map xen/x86: move NUMA scan nodes codes from x86 to common
xen: introduce a Kconfig option to configure NUMA nodes number
xen/arch/Kconfig | 11 + xen/arch/x86/include/asm/acpi.h | 2 - xen/arch/x86/include/asm/mm.h | 2 - xen/arch/x86/include/asm/numa.h | 61 +-- xen/arch/x86/include/asm/setup.h | 1 - xen/arch/x86/mm.c | 2 - xen/arch/x86/numa.c | 448 ++---------------- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/srat.c | 313 ++----------- xen/common/Makefile | 1 + xen/common/numa.c | 757 +++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 2 + xen/include/xen/mm.h | 2 + xen/include/xen/numa.h | 87 +++- 14 files changed, 916 insertions(+), 775 deletions(-) create mode 100644 xen/common/numa.c
Signature · 1 line
2.25.1
PATCH v3 1/6 xen/x86: Provide helpers for common code to access acpi_numa
acpi_numa is a specific NUMA switch for ACPI NUMA implementation. Other NUMA implementation may not need this switch. But this switch is not only used by ACPI code, it is also used directly in some general NUMA logic code. So far this hasn't caused any problem because Xen only has x86 implementing ACPI NUMA, but now Arm is implementing device tree based NUMA. Accesssing acpi_numa directly in some functions will be a block of reusing NUMA common code. It is also difficult for us to replace it with a new generic switch, because it is hard to prove that the new switch states can guarantee the original code will work correctly.
So in this patch, we provide two helpers for common code to update and get states of acpi_numa. And other new NUMA implementations just need to provide the same helpers for common code. In this case, the generic NUMA logic code can be reused by all NUMA implementations.
---
v2 -> v3:
1. Drop enumeration of numa status.
2. Use helpers to get/update acpi_numa.
3. Insert spaces among parameters of strncmp in numa_setup. v1 -> v2:
1. Remove fw_numa.
2. Use enumeration to replace numa_off and acpi_numa.
3. Correct return value of srat_disabled.
4. Introduce numa_enabled_with_firmware.
--- xen/arch/x86/include/asm/numa.h | 5 ++-- xen/arch/x86/numa.c | 41 ++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 15 deletions(-)
xen/arch/x86/include/asm/numa.h +3 -2
@@ -32,8 +32,9 @@ extern void numa_add_cpu(int cpu);extern void numa_init_array (void );extern bool numa_off; - -extern int srat_disabled (void ); +extern int arch_numa_setup (const char *opt); +extern bool arch_numa_disabled (bool init_as_disable); +extern bool srat_disabled (void );extern void numa_set_node (int cpu,nodeid_t node);extern nodeid_t setup_node (unsigned int pxm);extern void srat_detect_node (int cpu);
xen/arch/x86/numa.c +28 -13
65 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 1/6] xen/x86: Provide helpers for common code to access acpi_numa
xen/arch/x86/include/asm/numa.h extern void numa_add_cpu(int cpu); · line 36
Quoted 10 lines · Wei Chen
xen/arch/x86/include/asm/numa.h +2
-2@@ -32,8 +32,9 @@ extern void numa_add_cpu(int cpu);extern void numa_init_array (void );extern bool numa_off; - -extern int srat_disabled (void ); +extern int arch_numa_setup (const char *opt); +extern bool arch_numa_disabled (bool init_as_disable);
What is the parameter name intended to mean? Since the only caller passes "false", this also isn't really possible to guess from the use(s) in this patch. In any event perhaps best for the parameter to be introduced only once it's actually needed.
Quoted 6 lines
xen/arch/x86/numa.c +0
-0@@ -50,9 +50,31 @@ nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };bool numa_off;s8 acpi_numa =0 ;
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 60
Quoted 10 lines
xen/arch/x86/numa.c +7
-2-int srat_disabled (void ) +int __init arch_numa_setup (const char *opt) { -return numa_off || acpi_numa <0 ; +#ifdef CONFIG_ACPI_NUMA +if ( !strncmp (opt,"noacpi" ,6 ) ) + { + numa_off = false; + acpi_numa =-1 ; +return 0 ;
With this "return" ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 62
Quoted 2 lines
xen/arch/x86/numa.c +2
-0+ } +else
... this "else" is unnecessary and hence would better be dropped, not the least to ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 64
Quoted 2 lines
xen/arch/x86/numa.c +2
-0+#endif +return -EINVAL ;
... avoid the otherwise ambiguous indentation of this line.
Jan
RE: [PATCH v3 1/6] xen/x86: Provide helpers for common code to access acpi_numa
Hi Jan,
Quoted 17 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 18:18
To: Wei Chen <[email protected]>
Cc: nd <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v3 1/6] xen/x86: Provide helpers for common code to accessacpi_numaQuoted 6 lines · Wei Chen
xen/arch/x86/include/asm/numa.h +0
-0@@ -32,8 +32,9 @@ extern void numa_add_cpu(int cpu);extern void numa_init_array (void );extern bool numa_off;
Quoted 10 lines
xen/arch/x86/include/asm/numa.h extern void numa_add_cpu(int cpu); · line 36
Quoted 4 lines
xen/arch/x86/include/asm/numa.h +2
-2- -extern int srat_disabled (void ); +extern int arch_numa_setup (const char *opt); +extern bool arch_numa_disabled (bool init_as_disable);What is the parameter name intended to mean? Since the only caller passes "false", this also isn't really possible to guess from the use(s) in this patch. In any event perhaps best for the parameter to be introduced only once it's actually needed.
This parameter will be used in patch#5 and set to true, I will introduce this parameter in that patch.
Quoted 23 lines
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] =
Quoted 3 lines
xen/arch/x86/numa.c +0
-0@@ -50,9 +50,31 @@ nodemask_t __read_mostly node_online_map = { { [0] =1UL } };
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 60
Quoted 13 lines
xen/arch/x86/numa.c +7
-2bool numa_off;s8 acpi_numa =0 ; -int srat_disabled (void ) +int __init arch_numa_setup (const char *opt) { -return numa_off || acpi_numa <0 ; +#ifdef CONFIG_ACPI_NUMA +if ( !strncmp (opt,"noacpi" ,6 ) ) + { + numa_off = false; + acpi_numa =-1 ; +return 0 ;With this "return" ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 62
Quoted 2 lines
xen/arch/x86/numa.c +2
-0+ } +else
Quoted 8 lines
... this "else" is unnecessary and hence would better be dropped, not the least to ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 64
Quoted 2 lines
xen/arch/x86/numa.c +2
-0+#endif +return -EINVAL ;... avoid the otherwise ambiguous indentation of this line.
This is a good suggestion, current indentation looks weird, I will fix above 3 in next version.
Thanks,
Wei Che
Quoted 1 line
Jan
PATCH v3 2/6 xen/x86: move generically usable NUMA code from x86 to common
In reply to Wei ChenThere are some codes in x86/numa.c can be shared by common architectures to implememnt NUMA support. Just like some variables and functions to check and store NUMA memory map. And some variables and functions to do NUMA initialization.
In this patch, we move them to common/numa.c and xen/numa.h and use the CONFIG_NUMA to gate them for non-NUMA supported architectures. As the target header file is Xen-style, so we trim some spaces and replace tabs for the codes that has been moved to xen/numa.h at the same time.
As acpi_scan_nodes has been used in a common function, it doesn't make sense to use acpi_xxx in common code, so we rename it to numa_scan_nodes in this patch too. After that if we still use CONFIG_ACPI_NUMA in to gate numa_scan_nodes in numa_initmem_init, that doesn't make sense. As CONFIG_NUMA will be selected by CONFIG_ACPI_NUMA for x86. So, we replace CONFIG_ACPI_NUMA by CONFIG_NUMA to gate numa_scan_nodes.
As arch_numa_disabled has been implememnted for ACPI NUMA, we can rename srat_disabled to numa_disabled and move it to common code as well.
---
v2 -> v3:
1. Remove acpi.h from common/numa.c.
2. Rename acpi_scan_nodes to numa_scan_nodes.
3. Replace u8 by uint8_t for memnodemap.
4. Use unsigned int for memnode_shift and adjust related functions (compute_hash_shift, populate_memnodemap) to use correct types for return values or parameters.
5. Use nodeid_t for nodeid and node numbers.
6. Use __read_mostly and __ro_after_init for appropriate variables.
7. Adjust the __read_mostly and __initdata location for some variables.
8. convert from plain int to unsigned for cpuid and other proper variables.
9. Use __attribute_pure__ instead of __attribute__((pure)).
10. Replace CONFIG_ACPI_NUMA by CONFIG_NUMA in numa_initmem_init.
11. Add const for some functions' parameters.
12. Move srat_disabled to common code with new name numa_disabled.
13. Fix some spaces code-style for numa_emulation.
14. Change from int to unsigned int for numa_fake.
v1 -> v2:
1. New patch in v2.
--- xen/arch/x86/include/asm/acpi.h | 1 - xen/arch/x86/include/asm/numa.h | 57 +--- xen/arch/x86/include/asm/setup.h | 1 - xen/arch/x86/numa.c | 430 +----------------------------- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/srat.c | 8 +- xen/common/Makefile | 1 + xen/common/numa.c | 440 +++++++++++++++++++++++++++++++ xen/include/xen/numa.h | 66 +++++ 9 files changed, 514 insertions(+), 492 deletions(-) create mode 100644 xen/common/numa.c
xen/arch/x86/include/asm/acpi.h +0 -1
@@ -102,7 +102,6 @@ extern unsigned long acpi_wakeup_address;#define ARCH_HAS_POWER_INIT 1extern s8 acpi_numa; -extern int acpi_scan_nodes (u64 start,u64 end);#define NR_NODE_MEMBLKS (MAX_NUMNODES*2)extern struct acpi_sleep_info acpi_sinfo;
xen/arch/x86/include/asm/numa.h +1 -56
73 lines not on this page · raw message
xen/arch/x86/include/asm/setup.h +0 -1
@@ -20,7 +20,6 @@ void early_time_init(void);void set_nr_cpu_ids (unsigned int max_cpus); -void numa_initmem_init (unsigned long start_pfn,unsigned long end_pfn);void arch_init_memory (void );void subarch_init_memory (void );
xen/arch/x86/numa.c +1 -429
462 lines not on this page · raw message
xen/arch/x86/smpboot.c +1 -1
@@ -1350,7 +1350,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm) x86_acpiid_to_apicid[acpi_id] = apic_id; -if ( !srat_disabled () ) +if ( !numa_disabled () ) {nodeid_t node =setup_node (pxm);
xen/arch/x86/srat.c +4 -4
@@ -238,7 +238,7 @@ acpi_numa_x2apic_affinity_init(const struct acpi_srat_x2apic_cpu_affinity *pa)unsigned pxm;nodeid_t node; -if (srat_disabled ()) +if (numa_disabled ())return ;if (pa->header.length <sizeof (struct acpi_srat_x2apic_cpu_affinity )) {bad_srat ();
@@ -274,7 +274,7 @@ acpi_numa_processor_affinity_init(const struct acpi_srat_cpu_affinity *pa)unsigned pxm;nodeid_t node; -if (srat_disabled ()) +if (numa_disabled ())return ;if (pa->header.length !=sizeof (struct acpi_srat_cpu_affinity )) {bad_srat ();
@@ -313,7 +313,7 @@ acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma)nodeid_t node;unsigned int i; -if (srat_disabled ()) +if (numa_disabled ())return ;if (ma->header.length !=sizeof (struct acpi_srat_mem_affinity )) {bad_srat ();
@@ -520,7 +520,7 @@ void __init srat_parse_regions(paddr_t addr) }/* Use the information discovered above to actually set up the nodes. */ -int __init acpi_scan_nodes (paddr_t start,paddr_t end) +int __init numa_scan_nodes (paddr_t start,paddr_t end) {int i;nodemask_t all_nodes_parsed;
xen/common/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_MEM_ACCESS) += mem_access.o obj-y += memory.o obj-y += multicall.o obj-y += notifier.o +obj-$(CONFIG_NUMA) += numa.o obj-y += page_alloc.o obj-$(CONFIG_HAS_PDX) += pdx.o obj-$(CONFIG_PERF_COUNTERS) += perfc.o
xen/common/numa.c new file +440 -0
440 lines not on this page · raw message
xen/include/xen/numa.h +66 -0
70 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 2/6] xen/x86: move generically usable NUMA code from x86 to common
Quoted 17 lines · Wei Chen
xen/common/numa.c new file +14
-0@@ -0,0 +1,440 @@ +/* +* Generic VM initialization for NUMA setups. +* Copyright 2002,2003 Andi Kleen, SuSE Labs. +* Adapted for Xen: Ryan Harper <[email protected]> +*/ + +#include <xen/init.h> +#include <xen/keyhandler.h> +#include <xen/mm.h> +#include <xen/nodemask.h> +#include <xen/numa.h> +#include <xen/param.h> +#include <xen/sched.h> +#include <xen/softirq.h>
xen/common/numa.c line 24
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +struct node_data __ro_after_init node_data[MAX_NUMNODES ]; + +/* Mapping from pdx to node id */ +unsigned int __ro_after_init memnode_shift; +unsigned long __ro_after_init memnodemapsize; +uint8_t *__ro_after_init memnodemap; +static uint8_t __ro_after_init _memnodemap[64 ]; + +nodeid_t __ro_after_init cpu_to_node[NR_CPUS ] = {
I don't think this can be __ro_after_init, or you'll break CPU hotplug.
xen/common/numa.c line 28
Quoted 4 lines
xen/common/numa.c new file +4
-0+ [0 ... NR_CPUS-1] = NUMA_NO_NODE +}; + +cpumask_t __ro_after_init node_to_cpumask[MAX_NUMNODES ];
Same here.
xen/common/numa.c line 32
Quoted 3 lines
xen/common/numa.c new file +3
-0+nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; + +bool __read_mostly numa_off;
This, otoh, can be, or have I missed a place where it's written by a non-__init function?
Quoted 4 lines
xen/common/numa.c new file +4
-0+bool numa_disabled (void ) +{ +return numa_off ||arch_numa_disabled (false); +}
xen/common/numa.c line 47
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +/* +* Given a shift value, try to populate memnodemap[] +* Returns : +* 1 if OK +* 0 if memnodmap[] too small (of shift too small) +* -1 if node overlap or lost ram (shift too big) +*/ +static int __init populate_memnodemap(const struct node *nodes, + nodeid_t numnodes, unsigned int shift,
I don't think you can use nodeid_t for a variable holding a node count. Think of what would happen if there were 256 nodes, the IDs of which all fit in nodeid_t. (Same again further down.)
xen/common/numa.c line 51
Quoted 4 lines
xen/common/numa.c new file +4
-0+ nodeid_t *nodeids) +{ +unsigned long spdx, epdx; +nodeid_t i;
This is likely inefficient for a loop counter variable. Note how you use "unsigned int" in e.g. extract_lsb_from_nodes().
xen/common/numa.c line 135
Quoted 10 lines
xen/common/numa.c new file +10
-0+unsigned int __init compute_hash_shift (const struct node *nodes, +nodeid_t numnodes,nodeid_t *nodeids) +{ +unsigned int shift; + + shift =extract_lsb_from_nodes (nodes, numnodes); +if ( memnodemapsize <=ARRAY_SIZE (_memnodemap) ) + memnodemap = _memnodemap; +else if (allocate_cachealigned_memnodemap () ) +return -1 ;
With this the function can't very well have "unsigned int" return type.
xen/common/numa.c line 163
Quoted 3 lines
xen/common/numa.c new file +3
-0+void __init numa_init_array (void ) +{ +int rr, i;
"unsigned int" for i and perhaps nodeid_t for rr?
xen/common/numa.c line 196
Quoted 11 lines
xen/common/numa.c new file +11
-0+static int __init numa_emulation (unsigned long start_pfn, +unsigned long end_pfn) +{ +unsigned int i; +struct node nodes[MAX_NUMNODES ]; +uint64_t sz =pfn_to_paddr (end_pfn - start_pfn) / numa_fake; + +/* Kludge needed for the hash function */ +if (hweight64 (sz) >1 ) + { +u64 x =1 ;
uint64_t and a blank line between declaration(s) and statement(s) please.
Quoted 11 lines
xen/common/numa.c new file +11
-0+while ( (x <<1 ) < sz ) + x <<=1 ; +if ( x < sz /2 ) +printk (KERN_ERR "Numa emulation unbalanced. Complain to maintainer\n" ); + sz = x; + } + +memset (&nodes,0 ,sizeof (nodes)); +for ( i =0 ; i < numa_fake; i++ ) + { + nodes[i].start =pfn_to_paddr (start_pfn) + i * sz;
xen/common/numa.c line 217
Quoted 10 lines
xen/common/numa.c new file +10
-0+if ( i == numa_fake -1 ) + sz =pfn_to_paddr (end_pfn) - nodes[i].start; + nodes[i].end = nodes[i].start + sz; +printk (KERN_INFO "Faking node %u at %" PRIx64"-%" PRIx64" (%" PRIu64"MB)\n" , + i, nodes[i].start, nodes[i].end, + (nodes[i].end - nodes[i].start) >>20 ); +node_set_online (i); + } + memnode_shift =compute_hash_shift (nodes, numa_fake,NULL ); +if ( memnode_shift <0 )
Does the compiler not warn here, comparing an unsigned value for being negative?
Quoted 6 lines
xen/include/xen/numa.h +0
-0@@ -18,4 +18,70 @@ (((d)->vcpu !=NULL && (d)->vcpu[0 ] !=NULL ) \ ?vcpu_to_node ((d)->vcpu[0 ]) :NUMA_NO_NODE )
xen/include/xen/numa.h line 30
Quoted 10 lines
xen/include/xen/numa.h +10
-0+/* The following content can be used when NUMA feature is enabled */ +#ifdef CONFIG_NUMA + +extern nodeid_t cpu_to_node[NR_CPUS ]; +extern cpumask_t node_to_cpumask[]; + +#define cpu_to_node (cpu) (cpu_to_node[cpu]) +#define parent_node (node) (node) +#define node_to_first_cpu (node) (__ffs(node_to_cpumask[node])) +#define node_to_cpumask (node) (node_to_cpumask[node])
Please could you take the opportunity and drop unnecessary parentheses from here? Afaict only parent_node() need them to be kept.
xen/include/xen/numa.h line 42
Quoted 11 lines
xen/include/xen/numa.h +11
-0+struct node { +paddr_t start, end; +}; + +extern unsigned int compute_hash_shift (const struct node *nodes, +nodeid_t numnodes,nodeid_t *nodeids); + +#define VIRTUAL_BUG_ON (x) + +extern bool numa_off; +extern void numa_add_cpu (unsigned int cpu);
Please can you have variable and function declarations visually separated, by adding a blank line between them?
Quoted 17 lines
xen/include/xen/numa.h +17
-0+extern void numa_init_array (void ); +extern void numa_set_node (unsigned int cpu,nodeid_t node); +extern void numa_initmem_init (unsigned long start_pfn,unsigned long end_pfn); +extern int numa_scan_nodes (paddr_t start,paddr_t end); + +extern int arch_numa_setup (const char *opt); +extern bool arch_numa_disabled (bool init_as_disable); +extern void setup_node_bootmem (nodeid_t nodeid,paddr_t start,paddr_t end); + +static inline void clear_node_cpumask (unsigned int cpu) +{ +cpumask_clear_cpu (cpu, &node_to_cpumask[cpu_to_node (cpu)]); +} + +/* Simple perfect hash to map pdx to node numbers */ +extern unsigned int memnode_shift; +extern unsigned long memnodemapsize;
xen/include/xen/numa.h line 69
Quoted 10 lines
xen/include/xen/numa.h +10
-0+extern uint8_t *memnodemap; + +struct node_data { +unsigned long node_start_pfn; +unsigned long node_spanned_pages; +}; + +extern struct node_data node_data[]; + +static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t addr)
Nit: The conventional place for attributes is between return type and function (or object) name.
xen/include/xen/numa.h line 78
Quoted 9 lines
xen/include/xen/numa.h +9
-0+{ +nodeid_t nid; +VIRTUAL_BUG_ON ((paddr_to_pdx (addr) >> memnode_shift) >= memnodemapsize); + nid = memnodemap[paddr_to_pdx (addr) >> memnode_shift]; +VIRTUAL_BUG_ON (nid >=MAX_NUMNODES || !node_data[nid]); +return nid; +} + +#define NODE_DATA (nid) (&(node_data[nid]))
Again please take the opportunity and drop the unnecessary inner parentheses.
xen/include/xen/numa.h line 83
Quoted 4 lines
xen/include/xen/numa.h +4
-0+#define node_start_pfn (nid) (NODE_DATA(nid)->node_start_pfn) +#define node_spanned_pages (nid) (NODE_DATA(nid)->node_spanned_pages) +#define node_end_pfn (nid) (NODE_DATA(nid)->node_start_pfn + \ + NODE_DATA(nid)->node_spanned_pages)
Pleae correct indentation here - it was correct originally (except for the fact that it was using hard tabs).
Jan
RE: [PATCH v3 2/6] xen/x86: move generically usable NUMA code from x86 to common
Hi Jan,
Quoted 34 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 18:58
To: Wei Chen <[email protected]>
Cc: nd <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v3 2/6] xen/x86: move generically usable NUMA code from x86 to commonQuoted 22 lines · Wei Chen
xen/common/numa.c new file +19
-0@@ -0,0 +1,440 @@ +/* +* Generic VM initialization for NUMA setups. +* Copyright 2002,2003 Andi Kleen, SuSE Labs. +* Adapted for Xen: Ryan Harper <[email protected]> +*/ + +#include <xen/init.h> +#include <xen/keyhandler.h> +#include <xen/mm.h> +#include <xen/nodemask.h> +#include <xen/numa.h> +#include <xen/param.h> +#include <xen/sched.h> +#include <xen/softirq.h> + +struct node_data __ro_after_init node_data[MAX_NUMNODES ]; + +/* Mapping from pdx to node id */ +unsigned int __ro_after_init memnode_shift;
Quoted 9 lines
xen/common/numa.c line 24
Quoted 5 lines
xen/common/numa.c new file +5
-0+unsigned long __ro_after_init memnodemapsize; +uint8_t *__ro_after_init memnodemap; +static uint8_t __ro_after_init _memnodemap[64 ]; + +nodeid_t __ro_after_init cpu_to_node[NR_CPUS ] = {I don't think this can be
__ro_after_init, or you'll break CPU hotplug.
Yes, this will cause problem in cpu_add. I will __read_mostly for it in next version.
Quoted 7 lines
xen/common/numa.c line 28
Quoted 4 lines
xen/common/numa.c new file +4
-0+ [0 ... NR_CPUS-1] = NUMA_NO_NODE +}; + +cpumask_t __ro_after_init node_to_cpumask[MAX_NUMNODES ];Same here.
Ok.
Quoted 7 lines
xen/common/numa.c line 32
Quoted 3 lines
xen/common/numa.c new file +3
-0+nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; + +bool __read_mostly numa_off;This, otoh, can be, or have I missed a place where it's written by a non-__init function?
I think yes, it will be used in numa_disabled and numa_disabled will be called in cpu_add.
Quoted 16 lines
Quoted 4 lines
xen/common/numa.c new file +4
-0+bool numa_disabled (void ) +{ +return numa_off ||arch_numa_disabled (false); +}xen/common/numa.c
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +/* +* Given a shift value, try to populate memnodemap[] +* Returns : +* 1 if OK +* 0 if memnodmap[] too small (of shift too small) +* -1 if node overlap or lost ram (shift too big) +*/ +static int __init populate_memnodemap (const struct node *nodes, + nodeid_t numnodes, unsigned intshift,
Quoted 4 lines
I don't think you can use
nodeid_tfor a variable holding a node count. Think of what would happen if there were 256 nodes, the IDs of which all fit innodeid_t. (Same again further down.)
If we use u8 as nodeid_t, why there will be 256 nodes to here? And the MAX_NUMNODES has been limited to 64 (using NODES_SHIFT or CONFIG_NR_NUMA_NODES). If we allow 256 nodes, we have to update MAX_NUMNODES and nodeid_t first I think?
Quoted 8 lines
xen/common/numa.c line 51
Quoted 4 lines
xen/common/numa.c new file +4
-0+ nodeid_t *nodeids) +{ +unsigned long spdx, epdx; +nodeid_t i;This is likely inefficient for a loop counter variable. Note how you use "unsigned int" in e.g.
extract_lsb_from_nodes().
Did you mean u8 for "i" will cause something like unalignment, and will cause loop inefficient. If yes, I will use unsigned int for "i" in next version.
Quoted 14 lines
xen/common/numa.c line 51
Quoted 2 lines
xen/common/numa.c new file +2
-0+unsigned int __init compute_hash_shift (const struct node *nodes, + nodeid_t numnodes, nodeid_t*nodeids)
xen/common/numa.c line 135
Quoted 8 lines
xen/common/numa.c new file +8
-0+{ +unsigned int shift; + + shift =extract_lsb_from_nodes (nodes, numnodes); +if ( memnodemapsize <=ARRAY_SIZE (_memnodemap) ) + memnodemap = _memnodemap; +else if (allocate_cachealigned_memnodemap () ) +return -1 ;With this the function can't very well have "unsigned int" return type.
Oh, yes, I had only thought a negative shift will be strange and hadn't noticed this return value. I will restore the return value.
Quoted 6 lines
xen/common/numa.c line 163
Quoted 3 lines
xen/common/numa.c new file +3
-0+void __init numa_init_array (void ) +{ +int rr, i;"unsigned int" for i and perhaps
nodeid_tfor rr?
Yes, I will do it.
Quoted 6 lines
Quoted 6 lines
xen/common/numa.c new file +6
-0+static int __init numa_emulation (unsigned long start_pfn, +unsigned long end_pfn) +{ +unsigned int i; +struct node nodes[MAX_NUMNODES ]; +uint64_t sz =pfn_to_paddr (end_pfn - start_pfn) / numa_fake;
Quoted 9 lines
xen/common/numa.c line 196
Quoted 5 lines
xen/common/numa.c new file +5
-0+ +/* Kludge needed for the hash function */ +if (hweight64 (sz) >1 ) + { +u64 x =1 ;
uint64_tand a blank line between declaration(s) and statement(s) please.
OK.
Quoted 24 lines
xen/common/numa.c
Quoted 4 lines
xen/common/numa.c new file +4
-0+while ( (x <<1 ) < sz ) + x <<=1 ; +if ( x < sz /2 ) + printk(KERN_ERR "Numa emulation unbalanced. Complain tomaintainer\n");
xen/common/numa.c
Quoted 11 lines
xen/common/numa.c new file +11
-0+ sz = x; + } + +memset (&nodes,0 ,sizeof (nodes)); + for ( i = 0; i < numa_fake; i++ ) + { + nodes[i].start = pfn_to_paddr(start_pfn) + i * sz; + if ( i == numa_fake - 1 ) + sz = pfn_to_paddr(end_pfn) - nodes[i].start; + nodes[i].end = nodes[i].start + sz; + printk(KERN_INFO "Faking node %u at %"PRIx64"-%"PRIx64"(%"PRIu64"MB)\n",
xen/common/numa.c line 217
Quoted 6 lines
xen/common/numa.c new file +6
-0+ i, nodes[i].start, nodes[i].end, + (nodes[i].end - nodes[i].start) >> 20); +node_set_online (i); + } + memnode_shift =compute_hash_shift (nodes, numa_fake,NULL ); +if ( memnode_shift <0 )
Quoted 2 lines
Does the compiler not warn here, comparing an unsigned value for being negative?
It's strange, I haven't seen warnings for this kind of comparison.
Quoted 7 lines
Quoted 7 lines
xen/include/xen/numa.h +0
-0@@ -18,4 +18,70 @@ (((d)->vcpu !=NULL && (d)->vcpu[0 ] !=NULL ) \ ?vcpu_to_node ((d)->vcpu[0 ]) :NUMA_NO_NODE )
Quoted 14 lines
xen/include/xen/numa.h line 30
Quoted 10 lines
xen/include/xen/numa.h +10
-0+/* The following content can be used when NUMA feature is enabled */ +#ifdef CONFIG_NUMA + +extern nodeid_t cpu_to_node[NR_CPUS ]; +extern cpumask_t node_to_cpumask[]; + +#define cpu_to_node (cpu) (cpu_to_node[cpu]) +#define parent_node (node) (node) +#define node_to_first_cpu (node) (__ffs(node_to_cpumask[node])) +#define node_to_cpumask (node) (node_to_cpumask[node])Please could you take the opportunity and drop unnecessary parentheses from here? Afaict only
parent_node()need them to be kept.
OK.
Quoted 7 lines
xen/include/xen/numa.h
Quoted 6 lines
xen/include/xen/numa.h +6
-0+struct node { +paddr_t start, end; +}; + +extern unsigned int compute_hash_shift (const struct node *nodes, + nodeid_t numnodes, nodeid_t*nodeids);
Quoted 9 lines
xen/include/xen/numa.h line 42
Quoted 5 lines
xen/include/xen/numa.h +5
-0+ +#define VIRTUAL_BUG_ON (x) + +extern bool numa_off; +extern void numa_add_cpu (unsigned int cpu);Please can you have variable and function declarations visually separated, by adding a blank line between them?
Sure. I will do it.
Quoted 24 lines
xen/include/xen/numa.h
Quoted 3 lines
xen/include/xen/numa.h +3
-0+extern void numa_init_array (void ); +extern void numa_set_node (unsigned int cpu,nodeid_t node); +extern void numa_initmem_init(unsigned long start_pfn, unsigned long
end_pfn);xen/include/xen/numa.h
Quoted 5 lines
xen/include/xen/numa.h +5
-0+extern int numa_scan_nodes (paddr_t start,paddr_t end); + +extern int arch_numa_setup (const char *opt); +extern bool arch_numa_disabled (bool init_as_disable); +extern void setup_node_bootmem(nodeid_t nodeid, paddr_t start, paddr_tend);
Quoted 14 lines
xen/include/xen/numa.h +14
-0+ +static inline void clear_node_cpumask (unsigned int cpu) +{ +cpumask_clear_cpu (cpu, &node_to_cpumask[cpu_to_node (cpu)]); +} + +/* Simple perfect hash to map pdx to node numbers */ +extern unsigned int memnode_shift; +extern unsigned long memnodemapsize; +extern uint8_t *memnodemap; + +struct node_data { +unsigned long node_start_pfn; +unsigned long node_spanned_pages;
Quoted 9 lines
xen/include/xen/numa.h line 69
Quoted 5 lines
xen/include/xen/numa.h +5
-0+}; + +extern struct node_data node_data[]; + +static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t addr)Nit: The conventional place for attributes is between return type and function (or object) name.
Ok.
Quoted 4 lines
xen/include/xen/numa.h
Quoted 3 lines
xen/include/xen/numa.h +3
-0+{ +nodeid_t nid; + VIRTUAL_BUG_ON((paddr_to_pdx(addr) >> memnode_shift) >=memnodemapsize);
Quoted 10 lines
xen/include/xen/numa.h line 78
Quoted 6 lines
xen/include/xen/numa.h +6
-0+ nid = memnodemap[paddr_to_pdx (addr) >> memnode_shift]; +VIRTUAL_BUG_ON (nid >=MAX_NUMNODES || !node_data[nid]); +return nid; +} + +#define NODE_DATA (nid) (&(node_data[nid]))Again please take the opportunity and drop the unnecessary inner parentheses.
Ok.
Quoted 8 lines
xen/include/xen/numa.h line 83
Quoted 4 lines
xen/include/xen/numa.h +4
-0+#define node_start_pfn (nid) (NODE_DATA(nid)->node_start_pfn) +#define node_spanned_pages (nid) (NODE_DATA(nid)->node_spanned_pages) +#define node_end_pfn (nid) (NODE_DATA(nid)->node_start_pfn + \ + NODE_DATA(nid)->node_spanned_pages)Pleae correct indentation here - it was correct originally (except for the fact that it was using hard tabs).
Ok.
Cheers,
Wei Chen
Quoted 1 line
Jan
Re: [PATCH v3 2/6] xen/x86: move generically usable NUMA code from x86 to common
Quoted 13 lines · Wei Chen
Quoted 4 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 18:58Quoted 8 lines
xen/common/numa.c line 32
Quoted 3 lines · Wei Chen
xen/common/numa.c new file +3
-0+nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; + +bool __read_mostly numa_off;This, otoh, can be, or have I missed a place where it's written by a non-__init function?
Quoted 2 lines
I think yes, it will be used in
numa_disabledandnuma_disabledwill be called incpu_add.
In the original code I cannot spot such a path - can you please point out how exactly you see numa_disabled() reachable from cpu_add()? I'm clearly overlooking something ...
Quoted 21 lines
Quoted 16 lines
Quoted 4 lines
xen/common/numa.c new file +4
-0+bool numa_disabled (void ) +{ +return numa_off ||arch_numa_disabled (false); +}xen/common/numa.c
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +/* +* Given a shift value, try to populate memnodemap[] +* Returns : +* 1 if OK +* 0 if memnodmap[] too small (of shift too small) +* -1 if node overlap or lost ram (shift too big) +*/ +static int __init populate_memnodemap (const struct node *nodes, + nodeid_t numnodes, unsigned intshift,
Quoted 4 lines
I don't think you can use
nodeid_tfor a variable holding a node count. Think of what would happen if there were 256 nodes, the IDs of which all fit innodeid_t. (Same again further down.)
Quoted 4 lines
If we use u8 as
nodeid_t, why there will be 256 nodes to here? And theMAX_NUMNODEShas been limited to 64 (usingNODES_SHIFTorCONFIG_NR_NUMA_NODES). If we allow 256 nodes, we have to updateMAX_NUMNODESandnodeid_tfirst I think?
Well, when writing the reply I did forget about MAX_NUMNODES, so yes, with that the value can't be larger than 255. Nevertheless I don't think a count-of-nodes value should be expressed with nodeid_t. It should be simply "unsigned int".
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/common/numa.c new file +4
-0+ nodeid_t *nodeids) +{ +unsigned long spdx, epdx; +nodeid_t i;
Quoted 7 lines
Quoted 3 lines
This is likely inefficient for a loop counter variable. Note how you use "unsigned int" in e.g.
extract_lsb_from_nodes().Did you mean u8 for "i" will cause something like unalignment, and will cause loop inefficient. If yes, I will use unsigned int for "i" in next version.
There's no issue with mis-alignment afaics, but there still is the inefficiency issue requiring the loop variable to be zero-extended before being usable as an array. Both x86-64 and aarch64 have the zero-extension as a side effect when moving 32-bit quantities (from memory or between registers), and arm wouldn't require any zero- extension at all then.
Jan
PATCH v3 3/6 xen/x86: Use ASSERT instead of VIRTUAL_BUG_ON for phys_to_nid
In reply to Wei ChenVIRTUAL_BUG_ON is an empty macro used in phys_to_nid. This results in two lines of error-checking code in phys_to_nid that is not actually working and causing two compilation errors:
1. error: "MAX_NUMNODES" undeclared (first use in this function). This is because in the common header file, "MAX_NUMNODES" is defined after the common header file includes the ARCH header file, where phys_to_nid has attempted to use "MAX_NUMNODES". This error was resolved after we moved the phys_to_nid from x86 ARCH header file to common header file.
2. error: wrong type argument to unary exclamation mark. This is because, the error-checking code contains !node_data[nid]. But node_data is a data structure variable, it's not a pointer.
So, in this patch, we use ASSERT instead of VIRTUAL_BUG_ON to enable the two lines of error-checking code. And fix the left compilation errors by replacing !node_data[nid] to !node_data[nid].node_spanned_pages. Although NUMA allows one node can only have CPUs but without any memory. And node with 0 bytes of memory might have an entry in memnodemap[] theoretically. But that doesn't mean phys_to_nid can find any valid address from a node with 0 bytes memory.
---
v2 -> v3:
1. Remove unnecessary change items in history.
2. Add Acked-by.
v1 -> v2:
1. Use ASSERT to replace VIRTUAL_BUG_ON in phys_to_nid.
2. Adjust the conditional express for ASSERT.
3. Refine the justification of using !node_data[nid].node_spanned_pages.
--- xen/include/xen/numa.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
xen/include/xen/numa.h +2 -4
@@ -36,8 +36,6 @@ struct node {extern unsigned int compute_hash_shift (const struct node *nodes,nodeid_t numnodes,nodeid_t *nodeids); -#define VIRTUAL_BUG_ON (x) -extern bool numa_off;extern void numa_add_cpu (unsigned int cpu);extern void numa_init_array (void );
@@ -69,9 +67,9 @@ extern struct node_data node_data[]; static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t addr) {nodeid_t nid; -VIRTUAL_BUG_ON ((paddr_to_pdx (addr) >> memnode_shift) >= memnodemapsize); +ASSERT ((paddr_to_pdx (addr) >> memnode_shift) < memnodemapsize); nid = memnodemap[paddr_to_pdx (addr) >> memnode_shift]; -VIRTUAL_BUG_ON (nid >=MAX_NUMNODES || !node_data[nid]); +ASSERT (nid <MAX_NUMNODES && node_data[nid].node_spanned_pages);return nid; }
Signature · 1 line
2.25.1
PATCH v3 4/6 xen/x86: use arch_get_ram_range to get information from E820 map
In reply to Wei ChenThe sanity check of nodes_cover_memory is also a requirement of other architectures that support NUMA. But now, the code of nodes_cover_memory is tied to the x86 E820. In this case, we introduce arch_get_ram_range to decouple architecture specific memory map from this function. This means, other architectures like Arm can also use it to check its node and memory coverage from bootmem info.
Depends arch_get_ram_range, we make nodes_cover_memory become architecture independent. We also use neutral words to replace SRAT and E820 in the print message of this function. This will to make the massage seems more common.
As arch_get_ram_range use unsigned int for index, we also adjust the index in nodes_cover_memory from int to unsigned int.
---
v2 -> v3:
1. Rename arch_get_memory_map to arch_get_ram_range.
2. Use -ENOENT instead of -ENODEV to indicate end of memory map.
3. Add description to code comment that arch_get_ram_range returns RAM range in [start, end) format.
v1 -> v2:
1. Use arch_get_memory_map to replace arch_get_memory_bank_range and arch_get_memory_bank_number.
2. Remove the !start || !end check, because caller guarantee these two pointers will not be NULL.
--- xen/arch/x86/numa.c | 25 +++++++++++++++++++++++++ xen/arch/x86/srat.c | 18 +++++++++++------- xen/include/xen/numa.h | 3 +++ 3 files changed, 39 insertions(+), 7 deletions(-)
xen/arch/x86/numa.c +25 -0
@@ -9,6 +9,7 @@#include <xen/nodemask.h> #include <xen/numa.h> #include <asm/acpi.h> +#include <asm/e820.h> #ifndef Dprintk #define Dprintk(x...)
@@ -96,3 +97,27 @@ unsigned int __init arch_get_dma_bitsize(void)flsl (node_start_pfn (node) +node_spanned_pages (node) /4 -1 ) + PAGE_SHIFT, 32); } + +/* +* This function provides the ability for caller to get one RAM entry +* from architectural memory map by index. +* +* This function will return zero if it can return a proper RAM entry. +* otherwise it will return -ENOENT for out of scope index, or return +* -EINVAL for non-RAM type memory entry. +* +* Note: the range is exclusive at the end, e.g. [start, end). +*/ +int __init arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end) +{ +if ( idx >= e820.nr_map ) +return -ENOENT ; + +if ( e820.map[idx].type !=E820_RAM ) +return -EINVAL ; + + *start = e820.map[idx].addr; + *end = *start + e820.map[idx].size; + +return 0 ; +}
xen/arch/x86/srat.c +11 -7
@@ -428,18 +428,22 @@ acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma)Make sure the PXMs cover all memory. */ static int __init nodes_cover_memory (void ) { -int i; +unsigned int i; -for (i =0 ; i < e820.nr_map; i++) { +for (i =0 ; ; i++) {int j, found;paddr_t start, end; -if (e820.map[i].type !=E820_RAM ) { +/* Try to loop memory map from index 0 to end to get RAM ranges. */ + found =arch_get_ram_range (i, &start, &end); + +/* Index relate entry is not RAM, skip it. */ +if (found == -EINVAL )continue ; - } - start = e820.map[i].addr; - end = e820.map[i].addr + e820.map[i].size; +/* Reach the end of arch's memory map */ +if (found == -ENOENT ) +break ; do { found = 0;
@@ -458,7 +462,7 @@ static int __init nodes_cover_memory(void) }while (found && start < end);if (start < end) { -printk (KERN_ERR "SRAT: No PXM for e820 range: " +printk (KERN_ERR "NUMA: No NODE for RAM range: " "[%" PRIpaddr", %" PRIpaddr"]\n" , start, end -1 );return 0 ; }
xen/include/xen/numa.h +3 -0
@@ -80,6 +80,9 @@ 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 arch_get_ram_range (unsigned int idx, +paddr_t *start,paddr_t *end); +#endif #endif /* _XEN_NUMA_H */
Signature · 1 line
2.25.1
Re: [PATCH v3 4/6] xen/x86: use arch_get_ram_range to get information from E820 map
Quoted 6 lines · Wei Chen
xen/arch/x86/numa.c +2
-0@@ -96,3 +97,27 @@ unsigned int __init arch_get_dma_bitsize(void)flsl (node_start_pfn (node) +node_spanned_pages (node) /4 -1 ) + PAGE_SHIFT, 32); } + +/*
xen/arch/x86/numa.c unsigned int __init arch_get_dma_bitsize(void) · line 111
Quoted 10 lines
xen/arch/x86/numa.c +10
-0+* This function provides the ability for caller to get one RAM entry +* from architectural memory map by index. +* +* This function will return zero if it can return a proper RAM entry. +* otherwise it will return -ENOENT for out of scope index, or return +* -EINVAL for non-RAM type memory entry. +* +* Note: the range is exclusive at the end, e.g. [start, end). +*/ +int __init arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end)
Since the comment is intended to apply to all architectures providing, I think it should go with the declaration (once) rather than the definition (at least one instance per arch).
xen/arch/x86/numa.c unsigned int __init arch_get_dma_bitsize(void) · line 117
Quoted 6 lines
xen/arch/x86/numa.c +6
-0+{ +if ( idx >= e820.nr_map ) +return -ENOENT ; + +if ( e820.map[idx].type !=E820_RAM ) +return -EINVAL ;
EINVAL is so heavily (over)loaded that I'm inclined to ask to use e.g. -ENODATA here.
Quoted 18 lines
xen/arch/x86/srat.c +5
-3@@ -428,18 +428,22 @@ acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma)Make sure the PXMs cover all memory. */ static int __init nodes_cover_memory (void ) { -int i; +unsigned int i; -for (i =0 ; i < e820.nr_map; i++) { +for (i =0 ; ; i++) {int j, found;paddr_t start, end; -if (e820.map[i].type !=E820_RAM ) { +/* Try to loop memory map from index 0 to end to get RAM ranges. */ + found =arch_get_ram_range (i, &start, &end); +
xen/arch/x86/srat.c acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma) · line 446
Quoted 10 lines
xen/arch/x86/srat.c +5
-3+/* Index relate entry is not RAM, skip it. */ +if (found == -EINVAL )continue ; - } - start = e820.map[i].addr; - end = e820.map[i].addr + e820.map[i].size; +/* Reach the end of arch's memory map */ +if (found == -ENOENT ) +break ;
What if an arch returns a 3rd error indicator? The way you've written it code below would assume success and use uninitialized data. I'd like to suggest to only special-case -ENOENT and treat all other errors the same. But of course the variable (re)used doesn't really fit that:
/* Reach the end of arch's memory map */ if (found == -ENOENT) break; /* Index relate entry is not RAM, skip it. */ if (found) continue;
because here really you mean "not found". Since in fact "found" would want to be of "bool" type in the function, and "j" would want to be "unsigned int" just like "i" is, I recommend introducing a new local variable, e.g. "err".
Jan
Quoted 2 lines
xen/arch/x86/srat.c +0
-0do { found = 0;
RE: [PATCH v3 4/6] xen/x86: use arch_get_ram_range to get information from E820 map
Hi Jan,
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 20:14
To: Wei Chen <[email protected]>
Cc: nd <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v3 4/6] xen/x86: usearch_get_ram_rangeto get information from E820 mapReview unsigned int __init arch_get_dma_bitsize(void) · line 97
Quoted 2 lines · Wei Chen
(quoted diff) +0
-0@@ -96,3 +97,27 @@ unsigned int __init arch_get_dma_bitsize(void) flsl(node_start_pfn(node) + node_spanned_pages(node) /4 - 1)
Quoted 4 lines
xen/arch/x86/numa.c +2
-0+ PAGE_SHIFT, 32); } + +/* xen/arch/x86/numa.c unsigned int __init arch_get_dma_bitsize(void)
Quoted 10 lines
xen/arch/x86/numa.c +10
-0+* This function provides the ability for caller to get one RAM entry +* from architectural memory map by index. +* +* This function will return zero if it can return a proper RAM entry. +* otherwise it will return -ENOENT for out of scope index, or return +* -EINVAL for non-RAM type memory entry. +* +* Note: the range is exclusive at the end, e.g. [start, end). +*/ +int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t*end)
Quoted 4 lines
Since the comment is intended to apply to all architectures providing, I think it should go with the declaration (once) rather than the definition (at least one instance per arch).
Ok, I will move the comment to header file.
Quoted 10 lines
xen/arch/x86/numa.c unsigned int __init arch_get_dma_bitsize(void) · line 117
Quoted 6 lines
xen/arch/x86/numa.c +6
-0+{ +if ( idx >= e820.nr_map ) +return -ENOENT ; + +if ( e820.map[idx].type !=E820_RAM ) +return -EINVAL ;EINVAL is so heavily (over)loaded that I'm inclined to ask to use e.g.
-ENODATAhere.
Ok.
Quoted 25 lines
xen/arch/x86/srat.c acpi_numa_memory_affinity_init(const struct
Quoted 3 lines
xen/arch/x86/srat.c +0
-0@@ -428,18 +428,22 @@ acpi_numa_memory_affinity_init(const struct
acpi_srat_mem_affinity*ma)xen/arch/x86/srat.c acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma)
Quoted 13 lines
xen/arch/x86/srat.c +3
-3Make sure the PXMs cover all memory. */ static int __init nodes_cover_memory (void ) { -int i; +unsigned int i; -for (i =0 ; i < e820.nr_map; i++) { +for (i =0 ; ; i++) {int j, found;paddr_t start, end; -if (e820.map[i].type !=E820_RAM ) { +/* Try to loop memory map from index 0 to end to get RAM ranges. */
Quoted 7 lines
xen/arch/x86/srat.c +4
-1+ found =arch_get_ram_range (i, &start, &end); + +/* Index relate entry is not RAM, skip it. */ +if (found == -EINVAL )continue ; - }
Quoted 9 lines
xen/arch/x86/srat.c acpi_numa_memory_affinity_init(const struct acpi_srat_mem_affinity *ma) · line 446
Quoted 5 lines
xen/arch/x86/srat.c +3
-2- start = e820.map[i].addr; - end = e820.map[i].addr + e820.map[i].size; +/* Reach the end of arch's memory map */ +if (found == -ENOENT ) +break ;What if an arch returns a 3rd error indicator? The way you've written it code below would assume success and use uninitialized data. I'd like to suggest to only special-case
-ENOENTand treat all other
Yes, I hadn't taken the 3rd error case into account. I will follow your Comment in next version.
Quoted 11 lines
errors the same. But of course the variable (re)used doesn't really fit that:
/* Reach the end of arch's memory map */ if (found == -ENOENT) break; /* Index relate entry is not RAM, skip it. */ if (found) continue;
Quoted 5 lines
because here really you mean "not found". Since in fact "found" would want to be of "bool" type in the function, and "j" would want to be "unsigned int" just like "i" is, I recommend introducing a new local variable, e.g. "err".
Ok.
Cheers,
Wei Chen
Quoted 4 lines
Jan
Quoted 2 lines
xen/arch/x86/srat.c +0
-0do { found = 0;
PATCH v3 5/6 xen/x86: move NUMA scan nodes codes from x86 to common
In reply to Wei Chenx86 has implemented a set of codes to scan NUMA nodes. These codes will parse NUMA memory and processor information from ACPI SRAT table. But except some ACPI specific codes, most of the scan codes like memory blocks validation, node memory range updates and some sanity check can be reused by other NUMA implementation.
So in this patch, we move some variables and related functions for NUMA memory and processor to common as library. At the same time, numa_set_processor_nodes_parsed has been introduced for ACPI specific code to update processor parsing results. With this helper, we can reuse most of NUMA memory affinity init code from ACPI. As bad_srat and node_to_pxm functions have been used in common code to do architectural fallback and node to architectural node info translation. But it doesn't make sense to reuse the functions names in common code, we have rename them to neutral names as well.
PXM is an ACPI specific item, we can't use it in common code directly. As an alternative, we extend the parameters of numa_update_node_memblks. The caller can pass the PXM as print messages' prefix or as architectural node id. In this case, we do not need to retain a lot of per-arch code but still can print architectural log messages for different NUMA implementations.
mem_hotplug also has been accessing by common code, except x86, other architectures like Arm will also want to implement memory hotplug in future. We export mem_hotplug to common will not bring any harm for Arm and we also can reduce some per-arch helpers to access mem_hotplug.
As asm/acpi.h has been removed from common/numa.c, we have to move NR_NODE_MEMBLKS from asm/acpi.h to xen/numa.h in this patch as well.
---
v2 -> v3:
1. Add __ro_after_init to proper variables.
2. Rename bad_srat to numa_fw_bad.
3. Rename node_to_pxm to numa_node_to_arch_nid.
4. Merge patch#7 and #8 into this patch.
5. Correct int to unsigned int in proper places.
6. Move NR_NODE_MEMBLKS from x86/acpi.h to common/numa.h
7. Drop helpers to access mem_hotplug, we export mem_hotplug from x86/mm.c to common/page_alloc.c
v1 -> v2:
1. Add code comment for numa_update_node_memblks to explain:
Assumes all memory regions belonging to a single node are in one chunk. Holes between them will be included in the node.
2. Merge this single patch instead of serval patches to move x86 SRAT code to common.
3. Export node_to_pxm to keep pxm information in NUMA scan nodes error messages.
4. Change the code style to target file's Xen code-style.
5. Adjust some __init and __initdata for some functions and variables.
6. Merge two patches into this patch:
1. replace CONFIG_ACPI_NUMA by CONFIG_NUMA.
2. replace "SRAT" texts.
7. Turn numa_scan_nodes to static.
--- xen/arch/x86/include/asm/acpi.h | 1 - xen/arch/x86/include/asm/mm.h | 2 - xen/arch/x86/include/asm/numa.h | 3 +- xen/arch/x86/mm.c | 2 - xen/arch/x86/srat.c | 311 +++---------------------------- xen/common/numa.c | 317 ++++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 2 + xen/include/xen/mm.h | 2 + xen/include/xen/numa.h | 11 +- 9 files changed, 357 insertions(+), 294 deletions(-)
xen/arch/x86/include/asm/acpi.h +0 -1
@@ -102,7 +102,6 @@ extern unsigned long acpi_wakeup_address;#define ARCH_HAS_POWER_INIT 1extern s8 acpi_numa; -#define NR_NODE_MEMBLKS (MAX_NUMNODES*2)extern struct acpi_sleep_info acpi_sinfo;#define acpi_video_flags bootsym(video_flags)
xen/arch/x86/include/asm/mm.h +0 -2
@@ -474,8 +474,6 @@ static inline int get_page_and_type(struct page_info *page,ASSERT (((_p)->count_info & PGC_count_mask) !=0 ); \ASSERT (page_get_owner (_p) == (_d)) -extern paddr_t mem_hotplug; -/****************************************************************************** * With shadow pagetables, the different kinds of address start * to get get confusing.
xen/arch/x86/include/asm/numa.h +1 -2
@@ -10,6 +10,7 @@ typedef u8 nodeid_t;extern int srat_rev;extern nodeid_t pxm_to_node (unsigned int pxm); +extern unsigned int numa_node_to_arch_nid (nodeid_t n);#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))
@@ -22,8 +23,6 @@ extern void init_cpu_to_node(void);#define arch_want_default_dmazone () (num_online_nodes() > 1) -extern int valid_numa_range (paddr_t start,paddr_t end,nodeid_t node); -void srat_parse_regions (paddr_t addr);extern u8 __node_distance (nodeid_t a,nodeid_t b);unsigned int arch_get_dma_bitsize (void );
xen/arch/x86/mm.c +0 -2
@@ -157,8 +157,6 @@ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap_x[L1_PAGETABLE_ENTRIES ]; -paddr_t __read_mostly mem_hotplug; -/* Frame table size in pages. */ unsigned long max_page;unsigned long total_pages;
xen/arch/x86/srat.c +25 -286
402 lines not on this page · raw message
xen/common/numa.c +317 -0
329 lines not on this page · raw message
xen/common/page_alloc.c +2 -0
@@ -159,6 +159,8 @@#define PGT_TYPE_INFO_INITIALIZER 0#endif +paddr_t __read_mostly mem_hotplug; +/* * Comma-separated list of hexadecimal page numbers containing bad bytes. * e.g. 'badpage=0x3f45,0x8a321'.
xen/include/xen/mm.h +2 -0
@@ -58,6 +58,8 @@#include <xen/perfc.h> #include <public/memory.h> +extern paddr_t mem_hotplug; +struct page_info ;void put_page (struct page_info *);
xen/include/xen/numa.h +10 -1
@@ -11,6 +11,7 @@#define NUMA_NO_DISTANCE 0xFF#define MAX_NUMNODES (1 << NODES_SHIFT) +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)#define vcpu_to_node (v) (cpu_to_node((v)->processor))
@@ -41,7 +42,7 @@ extern void numa_add_cpu(unsigned int cpu);extern void numa_init_array (void );extern void numa_set_node (unsigned int cpu,nodeid_t node);extern void numa_initmem_init (unsigned long start_pfn,unsigned long end_pfn); -extern int numa_scan_nodes (paddr_t start,paddr_t end); +extern void numa_fw_bad (void );extern int arch_numa_setup (const char *opt);extern bool arch_numa_disabled (bool init_as_disable);
@@ -82,6 +83,14 @@ static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t addr)extern int arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end); +extern unsigned int valid_numa_range (paddr_t start,paddr_t end, +nodeid_t node); +extern bool numa_memblks_available (void ); +extern int numa_update_node_memblks (nodeid_t node,unsigned int arch_nid, +paddr_t start,paddr_t size, +const char *prefix, +bool hotplug); +extern void numa_set_processor_nodes_parsed (nodeid_t node);#endif
Signature · 1 line
2.25.1
Re: [PATCH v3 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
xen/common/numa.c line 20
Quoted 11 lines · Wei Chen
xen/common/numa.c +5
-0@@ -13,6 +13,21 @@#include <xen/sched.h> #include <xen/softirq.h> +static nodemask_t __initdata processor_nodes_parsed; +static nodemask_t __initdata memory_nodes_parsed; +static struct node __initdata nodes[MAX_NUMNODES ]; + +static int __ro_after_init num_node_memblks;
unsigned int?
xen/common/numa.c bool numa_disabled(void) · line 59
Quoted 10 lines
xen/common/numa.c +6
-0@@ -36,6 +51,308 @@ bool numa_disabled(void)return numa_off ||arch_numa_disabled (false); } +void __init numa_set_processor_nodes_parsed (nodeid_t node) +{ +node_set (node, processor_nodes_parsed); +} + +unsigned int valid_numa_range (paddr_t start,paddr_t end,nodeid_t node)
bool (and then true/false below)?
xen/common/numa.c bool numa_disabled(void) · line 65
Quoted 6 lines
xen/common/numa.c +6
-0+{ +unsigned int i; + +for ( i =0 ; i < num_node_memblks; i++ ) + { +struct node *nd = &node_memblk_range[i];
const?
xen/common/numa.c bool numa_disabled(void) · line 76
Quoted 10 lines
xen/common/numa.c +10
-0+if ( nd->start <= start && nd->end >= end && + memblk_nodeid[i] == node ) +return 1 ; + } + +return 0 ; +} + +static +enum conflicts __init conflicting_memblks(nodeid_t nid, paddr_t start,
May I ask that you re-flow this to either
static enum conflicts __init
conflicting_memblks(nodeid_t nid, paddr_t start,
or
static enum conflicts __init conflicting_memblks(
nodeid_t nid, paddr_t start,
?
xen/common/numa.c bool numa_disabled(void) · line 88
Quoted 12 lines
xen/common/numa.c +12
-0+ paddr_t end, paddr_t nd_start, + paddr_t nd_end, unsigned int *mblkid) +{ + unsigned int i; + +/* +* Scan all recorded nodes' memory blocks to check conflicts: +* Overlap or interleave. +*/ +for ( i =0 ; i < num_node_memblks; i++ ) + { +struct node *nd = &node_memblk_range[i];
const?
xen/common/numa.c bool numa_disabled(void) · line 139
Quoted 4 lines
xen/common/numa.c +4
-0+bool __init numa_memblks_available (void ) +{ +return num_node_memblks <NR_NODE_MEMBLKS ; +}
This is kind of clumsy, but I have no better suggestion.
xen/common/numa.c bool numa_disabled(void) · line 151
Quoted 11 lines
xen/common/numa.c +11
-0+/* +* This function will be called by NUMA memory affinity initialization to +* update NUMA node's memory range. In this function, we assume all memory +* regions belonging to a single node are in one chunk. Holes (or MMIO +* ranges) between them will be included in the node. +* +* So in numa_update_node_memblks, if there are multiple banks for each +* node, start and end are stretched to cover the holes between them, and +* it works as long as memory banks of different NUMA nodes don't interleave. +*/ +int __init numa_update_node_memblks(nodeid_t node, unsigned int arch_nid,
The function only ever returns 0 or -EINVAL - please consider switching to "bool" return type.
Quoted 19 lines
xen/common/numa.c +19
-0+ paddr_t start, paddr_t size, + const char *prefix, + bool hotplug) +{ + unsigned int i; +paddr_t end = start + size; +paddr_t nd_start = start; +paddr_t nd_end = end; +struct node *nd = &nodes[node]; + +/* +* For the node that already has some memory blocks, we will +* expand the node memory range temporarily to check memory +* interleaves with other nodes. We will not use this node +* temp memory range to check overlaps, because it will mask +* the overlaps in same node. +* +* Node with 0 bytes memory doesn't need this expandsion. +*/
xen/common/numa.c bool numa_disabled(void) · line 180
Quoted 10 lines
xen/common/numa.c +10
-0+if ( nd->start != nd->end ) + { +if ( nd_start > nd->start ) + nd_start = nd->start; + +if ( nd_end < nd->end ) + nd_end = nd->end; + } + +/* It is fine to add this area to the nodes data it will be used later*/
Please adjust style here.
Quoted 40 lines
xen/common/numa.c +40
-0+switch (conflicting_memblks (node, start, end, nd_start, nd_end, &i) ) + { +case OVERLAP : +if ( memblk_nodeid[i] == node ) + { +bool mismatch = !(hotplug) != !test_bit (i, memblk_hotplug); + +printk ("%sNUMA: %s %u [%" PRIpaddr", %" PRIpaddr"] overlaps with itself [%" PRIpaddr", %" PRIpaddr"]\n" , + mismatch ?KERN_ERR :KERN_WARNING , prefix, + arch_nid, start, end -1 , + node_memblk_range[i].start, node_memblk_range[i].end -1 ); +if ( mismatch ) +return -EINVAL ; +break ; + } + +printk (KERN_ERR +"NUMA: %s %u [%" PRIpaddr", %" PRIpaddr"] overlaps with %s %u [%" PRIpaddr", %" PRIpaddr"]\n" , + prefix, arch_nid, start, end -1 , prefix, +numa_node_to_arch_nid (memblk_nodeid[i]), + node_memblk_range[i].start, node_memblk_range[i].end -1 ); +return -EINVAL ; + + +case INTERLEAVE : +printk (KERN_ERR +"NUMA: %s %u: [%" PRIpaddr", %" PRIpaddr"] interleaves with %s %u memblk [%" PRIpaddr", %" PRIpaddr"]\n" , + prefix, arch_nid, nd_start, nd_end -1 , + prefix,numa_node_to_arch_nid (memblk_nodeid[i]), + node_memblk_range[i].start, node_memblk_range[i].end -1 ); +return -EINVAL ; + +case NO_CONFLICT : +break ; + } + +if ( !hotplug ) + { +node_set (node, memory_nodes_parsed); + nd->start = nd_start;
xen/common/numa.c bool numa_disabled(void) · line 230
Quoted 10 lines
xen/common/numa.c +10
-0+ nd->end = nd_end; + } + +if (strcasecmp ("Node" , prefix) ) +printk (KERN_INFO "NUMA: Node %u %s %u [%" PRIpaddr", %" PRIpaddr"]%s\n" , + node, prefix, arch_nid, start, end -1 , + hotplug ?" (hotplug)" :"" ); +else +printk (KERN_INFO "NUMA: Node %u [%" PRIpaddr", %" PRIpaddr"]%s\n" , + node, start, end -1 , hotplug ?" (hotplug)" :"" );
Hmm, if I'm not mistaken one of the two printk()s and hence also one of the two format strings will be dead code / data on every archiecture. I wonder if we don't want to have a HAS_NUMA_FW_NODE_ID (name subject to improvment) Kconfig setting to avoid such. I could imagine this to become relevant also in other code.
xen/common/numa.c bool numa_disabled(void) · line 302
Quoted 1 line
xen/common/numa.c +1
-0+static int __init numa_scan_nodes (paddr_t start,paddr_t end)
This function returns only 0 or -1, i.e. is even more of a candidate for having "bool" return type than numa_update_node_memblks().
Quoted 31 lines
xen/common/numa.c +31
-0+{ +unsigned int i; +nodemask_t all_nodes_parsed; + +/* First clean up the node list */ +for ( i =0 ; i <MAX_NUMNODES ; i++ ) +cutoff_node (i, start, end); + +/* When numa is on with good firmware, we can do numa scan nodes. */ +if (arch_numa_disabled (true) ) +return -1 ; + +if ( !nodes_cover_memory () ) + { +numa_fw_bad (); +return -1 ; + } + + memnode_shift =compute_hash_shift (node_memblk_range, num_node_memblks, + memblk_nodeid); + +if ( memnode_shift <0 ) + { +printk (KERN_ERR +"NUMA: No NUMA node hash function found. Contact maintainer\n" ); +numa_fw_bad (); +return -1 ; + } + +nodes_or (all_nodes_parsed, memory_nodes_parsed, processor_nodes_parsed); +
xen/common/numa.c bool numa_disabled(void) · line 343
Quoted 10 lines
xen/common/numa.c +10
-0+/* Finally register nodes */ +for_each_node_mask ( i, all_nodes_parsed ) + { +paddr_t size = nodes[i].end - nodes[i].start; + +if ( size ==0 ) +printk (KERN_INFO "NUMA: node %u has no memory\n" , i); + +setup_node_bootmem (i, nodes[i].start, nodes[i].end); + }
May I suggest to eliminate "size" at this occasion, for being used only once and rather not helping readability (imo at least)?
xen/include/xen/mm.h line 65
Quoted 11 lines
xen/include/xen/mm.h +2
-0@@ -58,6 +58,8 @@#include <xen/perfc.h> #include <public/memory.h> +extern paddr_t mem_hotplug; +struct page_info ;void put_page (struct page_info *);
I'm sorry, but I guess this may go about anywhere in the file, but not right at the top. I would probably have put it ahead of npfec_kind_t or right after dom_cow.
Jan
RE: [PATCH v3 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Hi Jan,
Quoted 18 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 20:50
To: Wei Chen <[email protected]>
Cc: nd <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Wei Liu <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v3 5/6] xen/x86: move NUMA scan nodes codes from x86 to commonQuoted 6 lines · Wei Chen
xen/common/numa.c +0
-0@@ -13,6 +13,21 @@#include <xen/sched.h> #include <xen/softirq.h>
Quoted 8 lines
xen/common/numa.c line 20
Quoted 5 lines
xen/common/numa.c +5
-0+static nodemask_t __initdata processor_nodes_parsed; +static nodemask_t __initdata memory_nodes_parsed; +static struct node __initdata nodes[MAX_NUMNODES ]; + +static int __ro_after_init num_node_memblks;unsigned int?
Yes, I will fix it.
Quoted 4 lines
Quoted 4 lines
xen/common/numa.c +0
-0@@ -36,6 +51,308 @@ bool numa_disabled(void)return numa_off ||arch_numa_disabled (false); }
Quoted 9 lines
xen/common/numa.c bool numa_disabled(void) · line 59
Quoted 6 lines
xen/common/numa.c +6
-0+void __init numa_set_processor_nodes_parsed (nodeid_t node) +{ +node_set (node, processor_nodes_parsed); +} + +unsigned int valid_numa_range (paddr_t start,paddr_t end,nodeid_t node)bool (and then true/false below)?
Ok.
Quoted 25 lines
xen/common/numa.c bool numa_disabled(void) · line 65
Quoted 6 lines
xen/common/numa.c +6
-0+{ +unsigned int i; + +for ( i =0 ; i < num_node_memblks; i++ ) + { +struct node *nd = &node_memblk_range[i];const?
xen/common/numa.c bool numa_disabled(void) · line 76
Quoted 10 lines
xen/common/numa.c +10
-0+if ( nd->start <= start && nd->end >= end && + memblk_nodeid[i] == node ) +return 1 ; + } + +return 0 ; +} + +static +enum conflicts __init conflicting_memblks(nodeid_t nid, paddr_t start,May I ask that you re-flow this to either
static enum conflicts
__init
conflicting_memblks(nodeid_t nid,paddr_tstart,
Quoted 7 lines
or
static enum conflicts
__initconflicting_memblks(
nodeid_tnid,paddr_tstart,?
Ok.
Quoted 16 lines
xen/common/numa.c bool numa_disabled(void) · line 77
Quoted 2 lines
xen/common/numa.c +2
-0+ paddr_t end, paddr_t nd_start, + paddr_t nd_end, unsigned int*mblkid)
xen/common/numa.c bool numa_disabled(void) · line 88
Quoted 10 lines
xen/common/numa.c +10
-0+{ +unsigned int i; + +/* +* Scan all recorded nodes' memory blocks to check conflicts: +* Overlap or interleave. +*/ +for ( i =0 ; i < num_node_memblks; i++ ) + { +struct node *nd = &node_memblk_range[i];const?
Ack.
Quoted 7 lines
xen/common/numa.c bool numa_disabled(void) · line 139
Quoted 4 lines
xen/common/numa.c +4
-0+bool __init numa_memblks_available (void ) +{ +return num_node_memblks <NR_NODE_MEMBLKS ; +}This is kind of clumsy, but I have no better suggestion.
Did you mean the whole function or just the name?
Quoted 11 lines
xen/common/numa.c bool numa_disabled(void) · line 93
Quoted 2 lines
xen/common/numa.c +2
-0+/* +* This function will be called by NUMA memory affinity initialization to
xen/common/numa.c bool numa_disabled(void) · line 94
Quoted 1 line
xen/common/numa.c +1
-0+* update NUMA node's memory range. In this function, we assume all memory
xen/common/numa.c bool numa_disabled(void)
Quoted 5 lines
xen/common/numa.c +5
-0+* regions belonging to a single node are in one chunk. Holes (or MMIO +* ranges) between them will be included in the node. +* +* So in numa_update_node_memblks, if there are multiple banks for each +* node, start and end are stretched to cover the holes between them, and
Quoted 8 lines
xen/common/numa.c bool numa_disabled(void) · line 100
Quoted 1 line
xen/common/numa.c +1
-0+* it works as long as memory banks of different NUMA nodes don't interleave.
xen/common/numa.c bool numa_disabled(void) · line 102
Quoted 2 lines
xen/common/numa.c +2
-0+*/ +int __init numa_update_node_memblks(nodeid_t node, unsigned int
arch_nid,The function only ever returns 0 or
-EINVAL- please consider switching to "bool" return type.
Ok.
Quoted 32 lines
Quoted 20 lines
xen/common/numa.c +19
-0+ paddr_t start, paddr_t size, + const char *prefix, + bool hotplug) +{ + unsigned int i; +paddr_t end = start + size; +paddr_t nd_start = start; +paddr_t nd_end = end; +struct node *nd = &nodes[node]; + +/* +* For the node that already has some memory blocks, we will +* expand the node memory range temporarily to check memory +* interleaves with other nodes. We will not use this node +* temp memory range to check overlaps, because it will mask +* the overlaps in same node. +* +* Node with 0 bytes memory doesn't need this expandsion. +*/ xen/common/numa.c bool numa_disabled(void)
Quoted 10 lines
xen/common/numa.c +10
-0+if ( nd->start != nd->end ) + { +if ( nd_start > nd->start ) + nd_start = nd->start; + +if ( nd_end < nd->end ) + nd_end = nd->end; + } + +/* It is fine to add this area to the nodes data it will be used later*/
Quoted 2 lines
Please adjust style here.
Ok.
Quoted 59 lines
xen/common/numa.c bool numa_disabled(void) · line 132
Quoted 1 line
xen/common/numa.c +1
-0+ switch ( conflicting_memblks(node, start, end, nd_start, nd_end,&i) )
xen/common/numa.c bool numa_disabled(void)
Quoted 7 lines
xen/common/numa.c +7
-0+ { + case OVERLAP: + if ( memblk_nodeid[i] == node ) + { + bool mismatch = !(hotplug) != !test_bit(i, memblk_hotplug); + + printk("%sNUMA: %s %u [%"PRIpaddr", %"PRIpaddr"] overlapswith itself [%"PRIpaddr", %"PRIpaddr"]\n",
xen/common/numa.c bool numa_disabled(void)
Quoted 3 lines
xen/common/numa.c +3
-0+ mismatch ?KERN_ERR :KERN_WARNING , prefix, + arch_nid, start, end -1 , + node_memblk_range[i].start, node_memblk_range[i].end- 1);
xen/common/numa.c bool numa_disabled(void)
Quoted 7 lines
xen/common/numa.c +7
-0+if ( mismatch ) +return -EINVAL ; +break ; + } + +printk (KERN_ERR + "NUMA: %s %u [%"PRIpaddr", %"PRIpaddr"] overlapswith %s %u [%"PRIpaddr", %"PRIpaddr"]\n",
xen/common/numa.c bool numa_disabled(void)
Quoted 3 lines
xen/common/numa.c +3
-0+ prefix, arch_nid, start, end -1 , prefix, +numa_node_to_arch_nid (memblk_nodeid[i]), + node_memblk_range[i].start, node_memblk_range[i].end -1);
xen/common/numa.c bool numa_disabled(void)
Quoted 6 lines
xen/common/numa.c +6
-0+return -EINVAL ; + + +case INTERLEAVE : +printk (KERN_ERR + "NUMA: %s %u: [%"PRIpaddr", %"PRIpaddr"] interleaveswith %s %u memblk [%"PRIpaddr", %"PRIpaddr"]\n",
xen/common/numa.c bool numa_disabled(void)
Quoted 3 lines
xen/common/numa.c +3
-0+ prefix, arch_nid, nd_start, nd_end -1 , + prefix,numa_node_to_arch_nid (memblk_nodeid[i]), + node_memblk_range[i].start, node_memblk_range[i].end -1);
Quoted 5 lines
xen/common/numa.c +5
-0+return -EINVAL ; + +case NO_CONFLICT : +break ; + }xen/common/numa.c bool numa_disabled(void)
Quoted 10 lines
xen/common/numa.c +10
-0+ +if ( !hotplug ) + { +node_set (node, memory_nodes_parsed); + nd->start = nd_start; + nd->end = nd_end; + } + +if (strcasecmp ("Node" , prefix) ) + printk(KERN_INFO "NUMA: Node %u %s %u[%"PRIpaddr", %"PRIpaddr"]%s\n",
xen/common/numa.c bool numa_disabled(void) · line 230
Quoted 5 lines
xen/common/numa.c +5
-0+ node, prefix, arch_nid, start, end - 1, + hotplug ? " (hotplug)" : ""); + else + printk(KERN_INFO "NUMA: Node %u [%" PRIpaddr", %" PRIpaddr"]%s\n" , + node, start, end -1 , hotplug ?" (hotplug)" :"" );
Quoted 6 lines
Hmm, if I'm not mistaken one of the two printk()s and hence also one of the two format strings will be dead code / data on every archiecture. I wonder if we don't want to have a
HAS_NUMA_FW_NODE_ID(name subject to improvment)Kconfigsetting to avoid such. I could imagine this to become relevant also in other code.
If HAS_NUMA_FW_NODE_ID can avoid such kind of code, I will try to use it in next version.
Quoted 5 lines
xen/common/numa.c bool numa_disabled(void) · line 302
Quoted 1 line
xen/common/numa.c +1
-0+static int __init numa_scan_nodes (paddr_t start,paddr_t end)This function returns only 0 or -1, i.e. is even more of a candidate for having "bool" return type than
numa_update_node_memblks().
Ok, I will try it.
Quoted 34 lines
xen/common/numa.c bool numa_disabled(void)
Quoted 9 lines
xen/common/numa.c +9
-0+{ +unsigned int i; +nodemask_t all_nodes_parsed; + +/* First clean up the node list */ +for ( i =0 ; i <MAX_NUMNODES ; i++ ) +cutoff_node (i, start, end); + +/* When numa is on with good firmware, we can do numa scan nodes. */
xen/common/numa.c bool numa_disabled(void)
Quoted 10 lines
xen/common/numa.c +10
-0+if (arch_numa_disabled (true) ) +return -1 ; + +if ( !nodes_cover_memory () ) + { +numa_fw_bad (); +return -1 ; + } + + memnode_shift = compute_hash_shift(node_memblk_range,
num_node_memblks,xen/common/numa.c bool numa_disabled(void)
Quoted 6 lines
xen/common/numa.c +6
-0+ memblk_nodeid); + + if ( memnode_shift < 0 ) + { + printk(KERN_ERR + "NUMA: No NUMA node hash function found. Contactmaintainer\n");
xen/common/numa.c bool numa_disabled(void)
Quoted 5 lines
xen/common/numa.c +5
-0+numa_fw_bad (); +return -1 ; + } + + nodes_or(all_nodes_parsed, memory_nodes_parsed,
processor_nodes_parsed);
Quoted 15 lines
xen/common/numa.c bool numa_disabled(void) · line 343
Quoted 11 lines
xen/common/numa.c +11
-0+ +/* Finally register nodes */ +for_each_node_mask ( i, all_nodes_parsed ) + { +paddr_t size = nodes[i].end - nodes[i].start; + +if ( size ==0 ) +printk (KERN_INFO "NUMA: node %u has no memory\n" , i); + +setup_node_bootmem (i, nodes[i].start, nodes[i].end); + }May I suggest to eliminate "size" at this occasion, for being used only once and rather not helping readability (imo at least)?
Ok.
Quoted 10 lines
Quoted 10 lines
xen/include/xen/mm.h +2
-0@@ -58,6 +58,8 @@#include <xen/perfc.h> #include <public/memory.h> +extern paddr_t mem_hotplug; +struct page_info ;
Quoted 5 lines
xen/include/xen/mm.h line 65
Quoted 1 line
xen/include/xen/mm.h +0
-0void put_page (struct page_info *);I'm sorry, but I guess this may go about anywhere in the file, but not right at the top. I would probably have put it ahead of
npfec_kind_tor right afterdom_cow.
Ok, I will move the place of it.
Thanks,
Wei Chen
Quoted 2 lines
Jan
Re: [PATCH v3 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Quoted 13 lines · Wei Chen
Quoted 4 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 20:50Quoted 8 lines
xen/common/numa.c bool numa_disabled(void) · line 139
Quoted 4 lines · Wei Chen
xen/common/numa.c +4
-0+bool __init numa_memblks_available (void ) +{ +return num_node_memblks <NR_NODE_MEMBLKS ; +}This is kind of clumsy, but I have no better suggestion.
Quoted 1 line
Did you mean the whole function or just the name?
The need for it (as even a non-inline function) primarily. Its name at least reflects its purpose, so would be okay-ish.
Jan
PATCH v3 6/6 xen: introduce a Kconfig option to configure NUMA nodes number
In reply to Wei ChenCurrent NUMA nodes number is a hardcode configuration. This configuration is difficult for an administrator to change unless changing the code.
So in this patch, we introduce this new Kconfig option for administrators to change NUMA nodes number conveniently. Also considering that not all architectures support NUMA, this Kconfig option only can be visible on NUMA enabled architectures. Non-NUMA supported architectures can still use 1 as MAX_NUMNODES.
As NODES_SHIFT is currently unused, we're taking this opportunity to remove it.
---
v2 -> v3:
1. Fix indent.
2. Use 2-64 for node range.
v1 -> v2:
1. Add NODES_SHIFT remove message in commit log
2. Change NR_NUMA_NODES upper bound from 4095 to 255.
--- xen/arch/Kconfig | 11 +++++++++++ xen/arch/x86/include/asm/numa.h | 2 -- xen/include/xen/numa.h | 11 ++++++----- 3 files changed, 17 insertions(+), 7 deletions(-)
xen/arch/Kconfig +11 -0
@@ -17,3 +17,14 @@ config NR_CPUS For CPU cores which support Simultaneous Multi-Threading or similar technologies, this the number of logical threads which Xen will support. + +config NR_NUMA_NODES + int "Maximum number of NUMA nodes supported" + range 2 64 + default "64" + depends on NUMA + help + Controls the build-time size of various arrays and bitmaps + associated with multiple-nodes management. It is the upper bound of + the number of NUMA nodes that the scheduler, memory allocation and + other NUMA-aware components can handle.
xen/arch/x86/include/asm/numa.h +0 -2
@@ -3,8 +3,6 @@#include <xen/cpumask.h> -#define NODES_SHIFT 6 -typedef u8 nodeid_t ;extern int srat_rev;
xen/include/xen/numa.h +6 -5
@@ -3,14 +3,15 @@#include <asm/numa.h> -#ifndef NODES_SHIFT -#define NODES_SHIFT 0 -#endif -#define NUMA_NO_NODE 0xFF#define NUMA_NO_DISTANCE 0xFF -#define MAX_NUMNODES (1 << NODES_SHIFT) +#ifdef CONFIG_NR_NUMA_NODES +#define MAX_NUMNODES CONFIG_NR_NUMA_NODES +#else +#define MAX_NUMNODES 1 +#endif +#define NR_NODE_MEMBLKS (MAX_NUMNODES * 2)#define vcpu_to_node (v) (cpu_to_node((v)->processor))
Signature · 1 line
2.25.1
Re: [PATCH v3 6/6] xen: introduce a Kconfig option to configure NUMA nodes number
Quoted 10 lines · Wei Chen
Current NUMA nodes number is a hardcode configuration. This configuration is difficult for an administrator to change unless changing the code.
So in this patch, we introduce this new
Kconfigoption for administrators to change NUMA nodes number conveniently. Also considering that not all architectures support NUMA, thisKconfigoption only can be visible on NUMA enabled architectures. Non-NUMA supported architectures can still use 1 asMAX_NUMNODES.
Especially the uses of "NUMA nodes number" make this read somewhat odd. If I was to re-write all of this, it would become something like:
Currently the maximum number of NUMA nodes is a hardcoded value. This provides little flexibility unless changing the code.
Introduce a new Kconfig option to change the maximum number of NUMA nodes conveniently. Also considering that not all architectures support NUMA, this Kconfig option is only visible on NUMA enabled architectures. Architectures not supporting NUMA still use 1 for MAX_NUMNODES.
Quoted 4 lines
As
NODES_SHIFTis currently unused, we're taking this opportunity to remove it.Signed-off-by Wei Chen <[email protected]>
Note that there's an alternative with less #ifdef-ary:
config NR_NUMA_NODES
int "Maximum number of NUMA nodes supported" if NUMA range 2 64 if NUMA
default "1" if !NUMA
default "64"
But I can see reasons why one might deem it better for there to not be any CONFIG_NR_NUMA_NODES in the resulting .config when !NUMA.
Jan
RE: [PATCH v3 6/6] xen: introduce a Kconfig option to configure NUMA nodes number
Hi Jan,
Quoted 27 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 21:06
To: Wei Chen <[email protected]>
Cc: nd <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monné <[email protected]>; [email protected]
Subject: Re: [PATCH v3 6/6] xen: introduce aKconfigoption to configure NUMA nodes numberQuoted 10 lines · Wei Chen
Current NUMA nodes number is a hardcode configuration. This configuration is difficult for an administrator to change unless changing the code.
So in this patch, we introduce this new
Kconfigoption for administrators to change NUMA nodes number conveniently. Also considering that not all architectures support NUMA, thisKconfigoption only can be visible on NUMA enabled architectures. Non-NUMA supported architectures can still use 1 asMAX_NUMNODES.Especially the uses of "NUMA nodes number" make this read somewhat odd. If I was to re-write all of this, it would become something like:
Quoted 9 lines
Currently the maximum number of NUMA nodes is a hardcoded value. This provides little flexibility unless changing the code.
Introduce a new
Kconfigoption to change the maximum number of NUMA nodes conveniently. Also considering that not all architectures support NUMA, thisKconfigoption is only visible on NUMA enabled architectures. Architectures not supporting NUMA still use 1 forMAX_NUMNODES.
Thanks, I will update the commit log.
Quoted 7 lines
Quoted 4 lines
As
NODES_SHIFTis currently unused, we're taking this opportunity to remove it.Signed-off-by Wei Chen <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks!
Quoted 8 lines
Note that there's an alternative with less #ifdef-ary:
config
NR_NUMA_NODES
int "Maximum number of NUMA nodes supported" if NUMA range 2 64 if NUMA
default "1" if !NUMA
default "64"
Quoted 4 lines
But I can see reasons why one might deem it better for there to not be any
CONFIG_NR_NUMA_NODESin the resulting .config when !NUMA.
Is it because there are many places where alternative patches need to be added for #ifndef CONFIG_NR_NUMA_NODES?
Cheers,
Wei Chen
Quoted 1 line
Jan
Re: [PATCH v3 6/6] xen: introduce a Kconfig option to configure NUMA nodes number
Quoted 12 lines · Wei Chen
Quoted 12 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年8月25日 21:06Note that there's an alternative with less #ifdef-ary:
config
NR_NUMA_NODES
int "Maximum number of NUMA nodes supported" if NUMA range 2 64 if NUMA
default "1" if !NUMA
default "64"
Quoted 7 lines
Quoted 4 lines
But I can see reasons why one might deem it better for there to not be any
CONFIG_NR_NUMA_NODESin the resulting .config when !NUMA.Is it because there are many places where alternative patches need to be added for #ifndef
CONFIG_NR_NUMA_NODES?
Well, yes - that's why I said "with less #ifdef-ary". As you may have noticed, excessive use of #ifdef easily makes code hard to read.
Jan