Device tree based NUMA support for Arm - Part#2
v5 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 v5)
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
---
v4 -> v5:
1. Use arch_numa_broken instead of arch_numa_disabled for acpi_numa < 0 check. Because arch_numa_disabled might include acpi_numa < 0 (init failed) and acpi_numa == 0
(no data or data no init) cases.
2. Use nodeid_t instead of uint8_t for memnodemap.
3. Restore to use typeof(*memnodemap) for _memnodemap, this will avoid the further adjustments for _memnodemap's type.
4. Use __ro_after_init for numa_off.
5. Use pointer-to-const for proper function parameters.
6. Use unsigned int for variables that are not realy used for node ID.
7. Fix code comments code-style and adjust the length.
8. Fix code-styles.
9. Rename numa_scan_nodes to numa_process_nodes.
10. Defer introduce arch_numa_disabled for acpi_numa <= 0. And remove the paramter init_as_disable of arch_numa_disabled.
11. Fix typo "expandsion".
12. Fix Indentation for l1tf_safe_maddr.
13. Remove double blank lines.
14. Add a space between for_each_node_mask and '('.
Add a space page_list_for_each and '('.
15. Use bool for nodes_cover_memory return value.
16. Use a plain "int ret" to record compute_hash_shift return value.
17. Add a blank line before the function's main "return".
18. Add new Kconfig option HAS_NUMA_NODE_FWID to common/Kconfig.
v3 -> v4:
1. Add init_as_disable as arch_numa_disabled parameter in the patche where use it.
2. Drop unnecessary "else" from arch_numa_setup, and fix its indentation.
3. Restore compute_hash_shift's return value to int.
4. Remove unnecessary parentheses for macros.
5. Use unsigned int for proper variables.
6. Fix some code-style.
7. Move arch_get_ram_range function comment to header file.
8. Use bool for found, and add a new "err" for the return value of arch_get_ram_range.
9. Use -ENODATA instead of -EINVAL for non-RAM type ranges.
10. Use bool as return value for functions that only return
0/1 or 0/-EINVAL.
11. Move mem_hotplug to a proper place in mm.h
12. Remove useless "size" in numa_scan_nodes.
13. Add CONFIG_HAS_NUMA_NODE_FWID to gate print the mapping between node id and architectural node id (fw node id).
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 | 438 +---------------- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/srat.c | 311 ++---------- xen/common/Kconfig | 3 + xen/common/Makefile | 1 + xen/common/numa.c | 780 +++++++++++++++++++++++++++++++ xen/common/page_alloc.c | 2 + xen/drivers/acpi/Kconfig | 1 + xen/include/xen/mm.h | 2 + xen/include/xen/numa.h | 98 +++- 16 files changed, 943 insertions(+), 774 deletions(-) create mode 100644 xen/common/numa.c
Signature · 1 line
2.25.1
PATCH v5 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.
---
v4 -> v5:
1. Use arch_numa_broken instead of arch_numa_disabled for acpi_numa < 0 check. Because arch_numa_disabled might include acpi_numa < 0 (init failed) and acpi_numa == 0 (no data or data no init) cases.
v3 -> v4:
1. Drop parameter from arch_numa_disabled, the parameter will be introduced in later patch where use it.
2. Drop unnecessary "else" from arch_numa_setup, and fix its indentation.
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 | 38 ++++++++++++++++++++++----------- 2 files changed, 28 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_broken (void ); +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 +25 -13
@@ -50,9 +50,28 @@ nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };bool 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 ; + } +#endif + +return -EINVAL ; +} + +bool arch_numa_broken (void ) +{ +return acpi_numa <0 ; +} + +bool srat_disabled (void ) +{ +return numa_off ||arch_numa_broken (); }/*
@@ -291,28 +310,21 @@ void numa_set_node(int cpu, nodeid_t node)/* [numa=off] */ static int __init cf_check numa_setup(const char *opt) { -if ( !strncmp (opt,"off" ,3 ) ) +if ( !strncmp (opt,"off" ,3 ) ) numa_off = true; -else if ( !strncmp (opt,"on" ,2 ) ) +else if ( !strncmp (opt,"on" ,2 ) ) numa_off = false;#ifdef CONFIG_NUMA_EMU else if ( !strncmp(opt, "fake=", 5) ) { numa_off = false; - numa_fake =simple_strtoul (opt+5 ,NULL ,0 ); + numa_fake =simple_strtoul (opt +5 ,NULL ,0 );if ( numa_fake >=MAX_NUMNODES ) numa_fake =MAX_NUMNODES ; } -#endif -#ifdef CONFIG_ACPI_NUMA - else if ( !strncmp(opt,"noacpi",6) ) - { - numa_off = false; - acpi_numa =-1 ; - }#endif else - return -EINVAL; + return arch_numa_setup(opt);return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH v5 1/6] xen/x86: Provide helpers for common code to access acpi_numa
Quoted 5 lines · Wei Chen
xen/arch/x86/numa.c +0
-0@@ -50,9 +50,28 @@ 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 59
Quoted 10 lines
xen/arch/x86/numa.c +6
-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 ;
When making the v5 changes, did you go over the results to check they are actually consistent? I'm afraid they still aren't, because of the line
above: Here we disable NUMA, but that doesn't mean there's broken firmware. Therefore I guess I need to ask for another round of renaming of the two helper functions; I'm sorry for that. What you introduce ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 70
Quoted 11 lines
xen/arch/x86/numa.c +11
-0+ return 0; + } +#endif + +return -EINVAL ; +} + +bool arch_numa_broken (void ) +{ +return acpi_numa <0 ; +}
... here wants to be arch_numa_disabled(), whereas the function currently named this way (in patch 5) wants to be e.g. arch_numa_unavailable() (or, using inverted sense, arch_numa_available()). Of course I'll be happy to see other naming suggestions for both functions, as long as they reflect the respective purposes.
Alternatively, to retain the current naming, the assignments to acpi_numa would need revising. But I think that would be the more fragile approach.
Jan
Re: [PATCH v5 1/6] xen/x86: Provide helpers for common code to access acpi_numa
Hi Jan,
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Wei Chen
xen/arch/x86/numa.c +0
-0@@ -50,9 +50,28 @@ nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };bool numa_off;s8 acpi_numa =0 ;
Quoted 13 lines
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 59
Quoted 9 lines
xen/arch/x86/numa.c +6
-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 ;When making the v5 changes, did you go over the results to check they are actually consistent? I'm afraid they still aren't, because of the line
above: Here we disable NUMA, but that doesn't mean there's broken firmware.
Yes, you're right. I had not realized it while I was modifying this patch.
Quoted 21 lines
Therefore I guess I need to ask for another round of renaming of the two helper functions; I'm sorry for that. What you introduce ...
xen/arch/x86/numa.c nodemask_t __read_mostly node_online_map = { { [0] = 1UL } }; · line 70
Quoted 11 lines
xen/arch/x86/numa.c +11
-0+ return 0; + } +#endif + +return -EINVAL ; +} + +bool arch_numa_broken (void ) +{ +return acpi_numa <0 ; +}... here wants to be
arch_numa_disabled(), whereas the function currently named this way (in patch 5) wants to be e.g.arch_numa_unavailable()(or, using inverted sense,arch_numa_available()). Of course I'll be happy to see other naming suggestions for both functions, as long as they reflect the respective purposes.
Quoted 3 lines
Alternatively, to retain the current naming, the assignments to
acpi_numawould need revising. But I think that would be the more fragile approach.
Yes, I agree with you, I will rename these two functions. Your suggested names are reasonable, I will use them in next version.
Cheers,
Wei Chen
Quoted 1 line
Jan
PATCH v5 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.
---
v4 -> v5:
1. Use nodeid_t instead of uint8_t for memnodemap.
2. Restore to use typeof(*memnodemap) for _memnodemap, this will avoid the further adjustments for _memnodemap's type.
3. Use __ro_after_init for numa_off.
4. Use pointer-to-const for proper function parameters.
5. Use unsigned int for variables that are not realy used for node ID.
6. Fix code comments code-style and adjust the length.
7. Fix code-styles.
8. Rename numa_scan_nodes to numa_process_nodes.
9. Use a plain "int ret" to record compute_hash_shift return value.
v3 -> v4:
1. Restore compute_hash_shift's return value to int.
2. Remove unnecessary parentheses for macros.
3. Use unsigned int for proper variables.
4. Fix some code-style.
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 | 10 +- xen/common/Makefile | 1 + xen/common/numa.c | 460 +++++++++++++++++++++++++++++++ xen/include/xen/numa.h | 67 +++++ 9 files changed, 536 insertions(+), 493 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 +5 -5
@@ -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 ();
@@ -519,8 +519,8 @@ void __init srat_parse_regions(paddr_t addr)pfn_pdx_hole_setup (mask >>PAGE_SHIFT ); } -/* Use the information discovered above to actually set up the nodes. */ -int __init acpi_scan_nodes (paddr_t start,paddr_t end) +/* Use discovered information to actually set up the nodes. */ +int __init numa_process_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 +460 -0
460 lines not on this page · raw message
xen/include/xen/numa.h +67 -0
71 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
Quoted 11 lines · Wei Chen
There are some codes in
x86/numa.ccan 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.candxen/numa.hand use theCONFIG_NUMAto 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 toxen/numa.hat the same time.
Quoted 3 lines
As
acpi_scan_nodeshas been used in a common function, it doesn't make sense to useacpi_xxxin common code, so we rename it tonuma_scan_nodesin this patch too. After that
numa_process_nodes() now?
Quoted 8 lines
if we still use
CONFIG_ACPI_NUMAin to gatenuma_scan_nodesinnuma_initmem_init, that doesn't make sense. AsCONFIG_NUMAwill be selected byCONFIG_ACPI_NUMAfor x86. So, we replaceCONFIG_ACPI_NUMAbyCONFIG_NUMAto gatenuma_scan_nodes.As
arch_numa_disabledhas been implememnted for ACPI NUMA, we can renamesrat_disabledtonuma_disabledand move it to common code as well.
Please update the description: arch_numa_disabled() appears in patch 5 only. Of course if you follow the comments to patch 2, the wording here would be correct again.
Quoted 6 lines
xen/common/numa.c new file +6
-0+static unsigned int __init extract_lsb_from_nodes (const struct node *nodes, +nodeid_t numnodes) +{ +unsigned int i, nodes_used =0 ; +unsigned long spdx, epdx; +unsigned long bitfield =0 , memtop =0 ;
xen/common/numa.c line 119
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +for ( i =0 ; i < numnodes; i++ ) + { + spdx =paddr_to_pdx (nodes[i].start); + epdx =paddr_to_pdx (nodes[i].end -1 ) +1 ; + +if ( spdx >= epdx ) +continue ; + + bitfield |= spdx;
Perhaps to be taken care of in a separate patch: We accumulate only the bits from the start addresses here, contrary to what the comment ahead of the function says (and I think it is the comment which is putting things correctly).
xen/common/numa.c line 126
Quoted 7 lines
xen/common/numa.c new file +7
-0+ nodes_used++; +if ( epdx > memtop ) + memtop = epdx; + } + +if ( nodes_used <=1 ) + i =BITS_PER_LONG -1 ;
Is this actually going to be correct for all architectures? Aiui Arm64 has only up to 48 physical address bits, but what about an architecture allowing the use of all 64 bits? I think at the very least we want BUILD_BUG_ON(PADDR_BITS >= BITS_PER_LONG) here.
xen/common/numa.c line 130
Quoted 4 lines
xen/common/numa.c new file +4
-0+else + i =find_first_bit (&bitfield,sizeof (unsigned long ) *8 ); + + memnodemapsize = (memtop >> i) +1 ;
Again perhaps the subject of a separate patch: Isn't there an off-by-1 mistake here? memtop is the maximum of all epdx-es, which are calculated to be the first PDX following the region. Hence I'd expect
memnodemapsize = ((memtop - 1) >> i) + 1;
here. I guess I'll make patches for both issues, which you may then need to re-base over.
Quoted 11 lines
xen/common/numa.c new file +11
-0+static int __init cf_check numa_setup(const char *opt) +{ +if ( !strncmp (opt,"off" ,3 ) ) + numa_off = true; +else if ( !strncmp (opt,"on" ,2 ) ) + numa_off = false; +#ifdef CONFIG_NUMA_EMU + else if ( !strncmp(opt, "fake=", 5) ) + { + numa_off = false; + numa_fake =simple_strtoul (opt +5 ,NULL ,0 );
xen/common/numa.c line 318
Quoted 10 lines
xen/common/numa.c new file +10
-0+if ( numa_fake >=MAX_NUMNODES ) + numa_fake =MAX_NUMNODES ; + } +#endif + else + return arch_numa_setup(opt); + +return 0 ; +} +custom_param ("numa" , numa_setup);
Note that with this moved here at some point during your work (when allowing NUMA=y for Arm) you'll need to update the command line doc.
Quoted 47 lines
xen/common/numa.c new file +47
-0+static void cf_check dump_numa(unsigned char key) +{ +s_time_t now =NOW (); +unsigned int i, j, n; +struct domain *d; +const struct page_info *page; +unsigned int page_num_node[MAX_NUMNODES ]; +const struct vnuma_info *vnuma; + +printk ("'%c' pressed -> dumping numa info (now = %" PRI_stime")\n" , key, + now); + +for_each_online_node ( i ) + { +paddr_t pa =pfn_to_paddr (node_start_pfn (i) +1 ); + +printk ("NODE%u start->%lu size->%lu free->%lu\n" , + i,node_start_pfn (i),node_spanned_pages (i), +avail_node_heap_pages (i)); +/* Sanity check phys_to_nid() */ +if (phys_to_nid (pa) != i ) +printk ("phys_to_nid(%" PRIpaddr") -> %d should be %u\n" , + pa,phys_to_nid (pa), i); + } + + j =cpumask_first (&cpu_online_map); + n =0 ; +for_each_online_cpu ( i ) + { +if ( i != j + n || cpu_to_node[j] != cpu_to_node[i] ) + { +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + j = i; + n =1 ; + } +else + ++n; + } +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + +rcu_read_lock (&domlist_read_lock);
xen/common/numa.c line 376
Quoted 10 lines
xen/common/numa.c new file +10
-0+ +printk ("Memory location of each domain:\n" ); +for_each_domain ( d ) + { +process_pending_softirqs (); + +printk ("Domain %u (total: %u):\n" , d->domain_id,domain_tot_pages (d)); + +for_each_online_node ( i ) + page_num_node[i] =0 ;
I'd be inclined to suggest to use memset() here, but I won't insist on you doing this "on the fly". Along with this would likely go the request to limit the scope of page_num_node[] (and then perhaps also vnuma and page).
Quoted 34 lines
xen/common/numa.c new file +34
-0+spin_lock (&d->page_alloc_lock); + page_list_for_each ( page, &d->page_list ) + { + i =phys_to_nid (page_to_maddr (page)); + page_num_node[i]++; + } +spin_unlock (&d->page_alloc_lock); + + for_each_online_node ( i ) + printk(" Node %u: %u\n", i, page_num_node[i]); + +if ( !read_trylock (&d->vnuma_rwlock) ) +continue ; + +if ( !d->vnuma ) + { +read_unlock (&d->vnuma_rwlock); +continue ; + } + + vnuma = d->vnuma; +printk (" %u vnodes, %u vcpus, guest physical layout:\n" , + vnuma->nr_vnodes, d->max_vcpus); +for ( i =0 ; i < vnuma->nr_vnodes; i++ ) + { +unsigned int start_cpu = ~0U ; + +if ( vnuma->vnode_to_pnode[i] ==NUMA_NO_NODE ) +printk (" %3u: pnode ???," , i); +else +printk (" %3u: pnode %3u," , i, vnuma->vnode_to_pnode[i]); + +printk (" vcpus " ); +
xen/common/numa.c line 421
Quoted 10 lines
xen/common/numa.c new file +10
-0+for ( j =0 ; j < d->max_vcpus; j++ ) + { +if ( !(j &0x3f ) ) +process_pending_softirqs (); + +if ( vnuma->vcpu_to_vnode[j] == i ) + { +if ( start_cpu == ~0U ) + { +printk ("%d" , j);
j being "unsigned int", would you mind switching to %u here and below?
Quoted 5 lines
xen/include/xen/numa.h +0
-0@@ -18,4 +18,71 @@ (((d)->vcpu !=NULL && (d)->vcpu[0 ] !=NULL ) \ ?vcpu_to_node ((d)->vcpu[0 ]) :NUMA_NO_NODE )
xen/include/xen/numa.h line 29
Quoted 10 lines
xen/include/xen/numa.h +9
-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])
I can't spot a use of this - perhaps better drop than generalize (if done right here then along with mentioning this in the description)?
Jan
Re: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
Quoted 14 lines · Jan Beulich
Quoted 13 lines · Wei Chen
xen/common/numa.c new file +13
-0+static unsigned int __init extract_lsb_from_nodes (const struct node *nodes, +nodeid_t numnodes) +{ +unsigned int i, nodes_used =0 ; +unsigned long spdx, epdx; +unsigned long bitfield =0 , memtop =0 ; + +for ( i =0 ; i < numnodes; i++ ) + { + spdx =paddr_to_pdx (nodes[i].start); + epdx =paddr_to_pdx (nodes[i].end -1 ) +1 ; + +if ( spdx >= epdx )
Quoted 8 lines
xen/common/numa.c line 119
Quoted 3 lines
xen/common/numa.c new file +3
-0+continue ; + + bitfield |= spdx;Perhaps to be taken care of in a separate patch: We accumulate only the bits from the start addresses here, contrary to what the comment ahead of the function says (and I think it is the comment which is putting things correctly).
It's the comment which is wrong - it wasn't updated in Linux commit 54413927f022 ("x86-64: x86_64-make-the-numa-hash-function-nodemap-allocation fix fix"). Our code was cloned from Linux'es. In fact when memory is not contiguous, too small a shift value might be determined. This in particular also may matter for the lowest range covered by any node: On x86 this will always start at zero (and hence won't influence the final calculation), but iirc on Arm memory may (and typically will) start at non-zero addresses. In such a case the first node's start address should be ignored, as it's fine to (kind of) associate all lower addresses (where no memory is) with this same node. But that's now indeed something which will want taking care of while making the code usable for other architectures.
Jan
Re: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
Hi Jan,
Quoted 11 lines · Jan Beulich
It's the comment which is wrong - it wasn't updated in Linux commit
54413927f022("x86-64: x86_64-make-the-numa-hash-function-nodemap-allocation fix fix"). Our code was cloned from Linux'es. In fact when memory is not contiguous, too small a shift value might be determined. This in particular also may matter for the lowest range covered by any node: On x86 this will always start at zero (and hence won't influence the final calculation), but iirc on Arm memory may (and typically will) start at non-zero addresses. In such a case the first node's start address should be ignored, as it's fine to (kind of) associate all lower addresses (where no memory is) with this same node. But that's now indeed something which will want taking care of while making the code usable for other architectures
Sorry, I hadn't read this before my last reply. I think I kind of understand what you mean now. If we do not ignore the lowest memory start address in the node, then the shift we calculate may contain a part of non-ram physical addresses. But if we ignore it, which address should we start from? Counting from end may ignore most of the ram area on this node.
Cheers,
Wei Chen
Re: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
In reply to Jan BeulichHi Jan,
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Wei Chen
There are some codes in
x86/numa.ccan 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.candxen/numa.hand use theCONFIG_NUMAto 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 toxen/numa.hat the same time.
Quoted 5 lines
Quoted 3 lines
As
acpi_scan_nodeshas been used in a common function, it doesn't make sense to useacpi_xxxin common code, so we rename it tonuma_scan_nodesin this patch too. After that
numa_process_nodes()now?
Oh, yes, I will update it.
Quoted 6 lines
Quoted 6 lines
if we still use
CONFIG_ACPI_NUMAin to gatenuma_scan_nodesinnuma_initmem_init, that doesn't make sense. AsCONFIG_NUMAwill be selected byCONFIG_ACPI_NUMAfor x86. So, we replaceCONFIG_ACPI_NUMAbyCONFIG_NUMAto gatenuma_scan_nodes.
Quoted 8 lines
Quoted 3 lines
As
arch_numa_disabledhas been implememnted for ACPI NUMA, we can renamesrat_disabledtonuma_disabledand move it to common code as well.Please update the description:
arch_numa_disabled()appears in patch 5 only. Of course if you follow the comments to patch 2, the wording here would be correct again.
I will update the description.
Quoted 13 lines
Quoted 13 lines
xen/common/numa.c new file +13
-0+static unsigned int __init extract_lsb_from_nodes (const struct node *nodes, +nodeid_t numnodes) +{ +unsigned int i, nodes_used =0 ; +unsigned long spdx, epdx; +unsigned long bitfield =0 , memtop =0 ; + +for ( i =0 ; i < numnodes; i++ ) + { + spdx =paddr_to_pdx (nodes[i].start); + epdx =paddr_to_pdx (nodes[i].end -1 ) +1 ; + +if ( spdx >= epdx )
Quoted 8 lines
xen/common/numa.c line 119
Quoted 3 lines
xen/common/numa.c new file +3
-0+continue ; + + bitfield |= spdx;Perhaps to be taken care of in a separate patch: We accumulate only the bits from the start addresses here, contrary to what the comment ahead of the function says (and I think it is the comment which is putting things correctly).
If one node has non-zero memory, the bit of end will >= the bit of start. As we use this function to calculate LSB, I don't think only accumulate bits of start addresses will be a problem. Instead I think
we should modify this function comment to say why we only need to accumulate bits of start addresses.
Quoted 9 lines
xen/common/numa.c line 126
Quoted 8 lines
xen/common/numa.c new file +7
-0+ nodes_used++; +if ( epdx > memtop ) + memtop = epdx; + } + +if ( nodes_used <=1 ) + i =BITS_PER_LONG -1 ;
Quoted 5 lines
Is this actually going to be correct for all architectures? Aiui Arm64 has only up to 48 physical address bits, but what about an architecture allowing the use of all 64 bits? I think at the very least we want
BUILD_BUG_ON(PADDR_BITS >= BITS_PER_LONG)here.
Ok I will add above BUILD_BUG_ON. And I also have question why can't we use PADDR_BITS here directly?
Quoted 5 lines
xen/common/numa.c line 130
Quoted 4 lines
xen/common/numa.c new file +4
-0+else + i =find_first_bit (&bitfield,sizeof (unsigned long ) *8 ); + + memnodemapsize = (memtop >> i) +1 ;
Quoted 9 lines
Again perhaps the subject of a separate patch: Isn't there an off-by-1 mistake here? memtop is the maximum of all epdx-es, which are calculated to be the first PDX following the region. Hence I'd expect
memnodemapsize = ((memtop - 1) >> i) + 1;here. I guess I'll make patches for both issues, which you may then need to re-base over.
Thanks, I will wait your patches.
Quoted 16 lines
Quoted 16 lines
xen/common/numa.c new file +16
-0+static int __init cf_check numa_setup(const char *opt) +{ +if ( !strncmp (opt,"off" ,3 ) ) + numa_off = true; +else if ( !strncmp (opt,"on" ,2 ) ) + numa_off = false; +#ifdef CONFIG_NUMA_EMU + else if ( !strncmp(opt, "fake=", 5) ) + { + numa_off = false; + numa_fake =simple_strtoul (opt +5 ,NULL ,0 ); +if ( numa_fake >=MAX_NUMNODES ) + numa_fake =MAX_NUMNODES ; + } +#endif + else
Quoted 9 lines
xen/common/numa.c line 318
Quoted 5 lines
xen/common/numa.c new file +5
-0+return arch_numa_setup (opt); + +return 0 ; +} +custom_param ("numa" , numa_setup);Note that with this moved here at some point during your work (when allowing NUMA=y for Arm) you'll need to update the command line doc.
I have prepared a patch for this doc in part#3 Arm part code.
Quoted 54 lines
Quoted 54 lines
xen/common/numa.c new file +54
-0+static void cf_check dump_numa(unsigned char key) +{ +s_time_t now =NOW (); +unsigned int i, j, n; +struct domain *d; +const struct page_info *page; +unsigned int page_num_node[MAX_NUMNODES ]; +const struct vnuma_info *vnuma; + +printk ("'%c' pressed -> dumping numa info (now = %" PRI_stime")\n" , key, + now); + +for_each_online_node ( i ) + { +paddr_t pa =pfn_to_paddr (node_start_pfn (i) +1 ); + +printk ("NODE%u start->%lu size->%lu free->%lu\n" , + i,node_start_pfn (i),node_spanned_pages (i), +avail_node_heap_pages (i)); +/* Sanity check phys_to_nid() */ +if (phys_to_nid (pa) != i ) +printk ("phys_to_nid(%" PRIpaddr") -> %d should be %u\n" , + pa,phys_to_nid (pa), i); + } + + j =cpumask_first (&cpu_online_map); + n =0 ; +for_each_online_cpu ( i ) + { +if ( i != j + n || cpu_to_node[j] != cpu_to_node[i] ) + { +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + j = i; + n =1 ; + } +else + ++n; + } +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + +rcu_read_lock (&domlist_read_lock); + +printk ("Memory location of each domain:\n" ); +for_each_domain ( d ) + { +process_pending_softirqs (); + +printk ("Domain %u (total: %u):\n" , d->domain_id,domain_tot_pages (d));
Quoted 9 lines
xen/common/numa.c line 376
Quoted 3 lines
xen/common/numa.c new file +3
-0+ +for_each_online_node ( i ) + page_num_node[i] =0 ;I'd be inclined to suggest to use
memset()here, but I won't insist on you doing this "on the fly". Along with this would likely go the request to limit the scope of page_num_node[] (and then perhaps also vnuma and page).
memset for page_num_node makes sense, I will do it before for_each_domain ( d ). About limit the scope, did you mean, we should move:
"const struct page_info *page;
unsigned int page_num_node[MAX_NUMNODES];
const struct vnuma_info *vnuma;"
to the block of for_each_domain ( d )?
Quoted 38 lines
Quoted 38 lines
xen/common/numa.c new file +38
-0+spin_lock (&d->page_alloc_lock); + page_list_for_each ( page, &d->page_list ) + { + i =phys_to_nid (page_to_maddr (page)); + page_num_node[i]++; + } +spin_unlock (&d->page_alloc_lock); + + for_each_online_node ( i ) + printk(" Node %u: %u\n", i, page_num_node[i]); + +if ( !read_trylock (&d->vnuma_rwlock) ) +continue ; + +if ( !d->vnuma ) + { +read_unlock (&d->vnuma_rwlock); +continue ; + } + + vnuma = d->vnuma; +printk (" %u vnodes, %u vcpus, guest physical layout:\n" , + vnuma->nr_vnodes, d->max_vcpus); +for ( i =0 ; i < vnuma->nr_vnodes; i++ ) + { +unsigned int start_cpu = ~0U ; + +if ( vnuma->vnode_to_pnode[i] ==NUMA_NO_NODE ) +printk (" %3u: pnode ???," , i); +else +printk (" %3u: pnode %3u," , i, vnuma->vnode_to_pnode[i]); + +printk (" vcpus " ); + +for ( j =0 ; j < d->max_vcpus; j++ ) + { +if ( !(j &0x3f ) ) +process_pending_softirqs ();
Quoted 9 lines
xen/common/numa.c line 421
Quoted 6 lines
xen/common/numa.c new file +6
-0+ +if ( vnuma->vcpu_to_vnode[j] == i ) + { +if ( start_cpu == ~0U ) + { +printk ("%d" , j);j being "unsigned int", would you mind switching to %u here and below?
Ok, I will do it and below.
Quoted 6 lines
Quoted 6 lines
xen/include/xen/numa.h +0
-0@@ -18,4 +18,71 @@ (((d)->vcpu !=NULL && (d)->vcpu[0 ] !=NULL ) \ ?vcpu_to_node ((d)->vcpu[0 ]) :NUMA_NO_NODE )
Quoted 13 lines
xen/include/xen/numa.h line 29
Quoted 9 lines
xen/include/xen/numa.h +9
-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])I can't spot a use of this - perhaps better drop than generalize (if done right here then along with mentioning this in the description)?
Yes, there is no code using this macro anymore, I will delete it and mention it in the commit log.
Cheers,
Wei Chen
Quoted 1 line
Jan
Re: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
Quoted 10 lines · Wei Chen
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Wei Chen
xen/common/numa.c new file +7
-0+ nodes_used++; +if ( epdx > memtop ) + memtop = epdx; + } + +if ( nodes_used <=1 ) + i =BITS_PER_LONG -1 ;
Quoted 8 lines
Quoted 5 lines
Is this actually going to be correct for all architectures? Aiui Arm64 has only up to 48 physical address bits, but what about an architecture allowing the use of all 64 bits? I think at the very least we want
BUILD_BUG_ON(PADDR_BITS >= BITS_PER_LONG)here.Ok I will add above
BUILD_BUG_ON. And I also have question why can't we usePADDR_BITShere directly?
Well, if you used PADDR_BITS, then you would use it without subtracting 1, and you'd be in trouble again when PADDR_BITS == BITS_PER_LONG. What may be possible to do instead of BUILD_BUG_ON() is
if ( nodes_used <= 1 )
i = min(PADDR_BITS, BITS_PER_LONG - 1);Quoted 9 lines
Quoted 9 lines
xen/common/numa.c line 130
Quoted 4 lines
xen/common/numa.c new file +4
-0+else + i =find_first_bit (&bitfield,sizeof (unsigned long ) *8 ); + + memnodemapsize = (memtop >> i) +1 ;Again perhaps the subject of a separate patch: Isn't there an off-by-1 mistake here? memtop is the maximum of all epdx-es, which are calculated to be the first PDX following the region. Hence I'd expect
Quoted 7 lines
Quoted 5 lines
memnodemapsize = ((memtop - 1) >> i) + 1;here. I guess I'll make patches for both issues, which you may then need to re-base over.
Thanks, I will wait your patches.
Already sent out yesterday.
Quoted 64 lines
Quoted 54 lines
Quoted 54 lines
xen/common/numa.c new file +54
-0+static void cf_check dump_numa(unsigned char key) +{ +s_time_t now =NOW (); +unsigned int i, j, n; +struct domain *d; +const struct page_info *page; +unsigned int page_num_node[MAX_NUMNODES ]; +const struct vnuma_info *vnuma; + +printk ("'%c' pressed -> dumping numa info (now = %" PRI_stime")\n" , key, + now); + +for_each_online_node ( i ) + { +paddr_t pa =pfn_to_paddr (node_start_pfn (i) +1 ); + +printk ("NODE%u start->%lu size->%lu free->%lu\n" , + i,node_start_pfn (i),node_spanned_pages (i), +avail_node_heap_pages (i)); +/* Sanity check phys_to_nid() */ +if (phys_to_nid (pa) != i ) +printk ("phys_to_nid(%" PRIpaddr") -> %d should be %u\n" , + pa,phys_to_nid (pa), i); + } + + j =cpumask_first (&cpu_online_map); + n =0 ; +for_each_online_cpu ( i ) + { +if ( i != j + n || cpu_to_node[j] != cpu_to_node[i] ) + { +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + j = i; + n =1 ; + } +else + ++n; + } +if ( n >1 ) +printk ("CPU%u...%u -> NODE%d\n" , j, j + n -1 , cpu_to_node[j]); +else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + +rcu_read_lock (&domlist_read_lock); + +printk ("Memory location of each domain:\n" ); +for_each_domain ( d ) + { +process_pending_softirqs (); + +printk ("Domain %u (total: %u):\n" , d->domain_id,domain_tot_pages (d));Quoted 9 lines
xen/common/numa.c line 376
Quoted 3 lines
xen/common/numa.c new file +3
-0+ +for_each_online_node ( i ) + page_num_node[i] =0 ;I'd be inclined to suggest to use
memset()here, but I won't insist on you doing this "on the fly". Along with this would likely go the request to limit the scope of page_num_node[] (and then perhaps also vnuma and page).
Quoted 2 lines
memset for
page_num_nodemakes sense, I will do it beforefor_each_domain( d ).
That won't be right - array elements need clearing on every iteration. Plus ...
Quoted 7 lines
About limit the scope, did you mean, we should move:
"const struct
page_info*page;
unsigned int page_num_node[MAX_NUMNODES];
const structvnuma_info*vnuma;"to the block of
for_each_domain( d )?
... this limiting of scope (yes to your question) would also conflict with the movement you suggest. It is actually (among other things) such a mistaken movement which the more narrow scope is intended to prevent.
Jan
RE: [PATCH v5 2/6] xen/x86: move generically usable NUMA code from x86 to common
Hi Jan,
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年9月29日 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 v5 2/6] xen/x86: move generically usable NUMA code from x86 to commonQuoted 10 lines · Wei Chen
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Wei Chen
xen/common/numa.c new file +7
-0+ nodes_used++; +if ( epdx > memtop ) + memtop = epdx; + } + +if ( nodes_used <=1 ) + i =BITS_PER_LONG -1 ;Quoted 8 lines
Quoted 5 lines
Is this actually going to be correct for all architectures? Aiui Arm64 has only up to 48 physical address bits, but what about an architecture allowing the use of all 64 bits? I think at the very least we want
BUILD_BUG_ON(PADDR_BITS >= BITS_PER_LONG)here.Ok I will add above
BUILD_BUG_ON. And I also have question why can't we usePADDR_BITShere directly?
Quoted 7 lines
Well, if you used
PADDR_BITS, then you would use it without subtracting 1, and you'd be in trouble again whenPADDR_BITS==BITS_PER_LONG. What may be possible to do instead ofBUILD_BUG_ON()isif ( nodes_used <= 1 ) i = min(PADDR_BITS, BITS_PER_LONG - 1);
This one seems better, I will follow it.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
xen/common/numa.c line 130
Quoted 4 lines
xen/common/numa.c new file +4
-0+else + i =find_first_bit (&bitfield,sizeof (unsigned long ) *8 ); + + memnodemapsize = (memtop >> i) +1 ;Again perhaps the subject of a separate patch: Isn't there an off-by-1 mistake here? memtop is the maximum of all epdx-es, which are calculated to be the first PDX following the region. Hence I'd expect
memnodemapsize = ((memtop - 1) >> i) + 1;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
here. I guess I'll make patches for both issues, which you may then need to re-base over.
Thanks, I will wait your patches.
Already sent out yesterday.
Ok.
Quoted 68 lines
Quoted 10 lines
Quoted 10 lines
xen/common/numa.c
Quoted 10 lines
xen/common/numa.c new file +10
-0+static void cf_check dump_numa(unsigned char key) +{ +s_time_t now =NOW (); +unsigned int i, j, n; +struct domain *d; +const struct page_info *page; +unsigned int page_num_node[MAX_NUMNODES ]; +const struct vnuma_info *vnuma; + + printk("'%c' pressed -> dumping numa info (now = %"PRI_stime")\n",key,
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
xen/common/numa.c new file +15
-0+ now); + +for_each_online_node ( i ) + { +paddr_t pa =pfn_to_paddr (node_start_pfn (i) +1 ); + +printk ("NODE%u start->%lu size->%lu free->%lu\n" , + i,node_start_pfn (i),node_spanned_pages (i), +avail_node_heap_pages (i)); +/* Sanity check phys_to_nid() */ +if (phys_to_nid (pa) != i ) +printk ("phys_to_nid(%" PRIpaddr") -> %d should be %u\n" , + pa,phys_to_nid (pa), i); + } +Quoted 8 lines
Quoted 8 lines
xen/common/numa.c
Quoted 8 lines
xen/common/numa.c new file +8
-0+ j =cpumask_first (&cpu_online_map); + n =0 ; +for_each_online_cpu ( i ) + { +if ( i != j + n || cpu_to_node[j] != cpu_to_node[i] ) + { +if ( n >1 ) + printk("CPU%u...%u -> NODE%d\n", j, j + n - 1,cpu_to_node[j]);
Quoted 10 lines
Quoted 10 lines
xen/common/numa.c
Quoted 10 lines
xen/common/numa.c new file +10
-0+else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + j = i; + n =1 ; + } +else + ++n; + } +if ( n >1 ) + printk("CPU%u...%u -> NODE%d\n", j, j + n - 1,cpu_to_node[j]);
Quoted 11 lines
Quoted 11 lines
xen/common/numa.c
Quoted 11 lines
xen/common/numa.c new file +11
-0+else +printk ("CPU%u -> NODE%d\n" , j, cpu_to_node[j]); + +rcu_read_lock (&domlist_read_lock); + +printk ("Memory location of each domain:\n" ); +for_each_domain ( d ) + { +process_pending_softirqs (); + + printk("Domain %u (total: %u):\n", d->domain_id,
domain_tot_pages(d));Quoted 10 lines
Quoted 9 lines
xen/common/numa.c line 376
Quoted 3 lines
xen/common/numa.c new file +3
-0+ +for_each_online_node ( i ) + page_num_node[i] =0 ;I'd be inclined to suggest to use
memset()here, but I won't insist on you doing this "on the fly". Along with this would likely go the request to limit the scope of page_num_node[] (and then perhaps also vnuma and page).
Quoted 6 lines
Quoted 2 lines
memset for
page_num_nodemakes sense, I will do it beforefor_each_domain( d ).That won't be right - array elements need clearing on every iteration. Plus ...
Oh, Yes.
Quoted 6 lines
Quoted 6 lines
About limit the scope, did you mean, we should move:
"const struct
page_info*page;
unsigned int page_num_node[MAX_NUMNODES];
const structvnuma_info*vnuma;"
Quoted 7 lines
Quoted 1 line
to the block of
for_each_domain( d )?... this limiting of scope (yes to your question) would also conflict with the movement you suggest. It is actually (among other things) such a mistaken movement which the more narrow scope is intended to prevent.
Thanks,
Wei Chen
Quoted 1 line
Jan
PATCH v5 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.
---
v4 -> v5:
1. No change.
v3 -> v4:
1. No change.
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 int compute_hash_shift (const struct node *nodes,unsigned int numnodes,const nodeid_t *nodeids); -#define VIRTUAL_BUG_ON (x) -extern bool numa_off;extern void numa_add_cpu (unsigned int cpu);
@@ -70,9 +68,9 @@ extern struct node_data node_data[]; static inline nodeid_t __attribute_pure__ 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 v5 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.
---
v4 -> v5:
1. Add Rb.
2. Adjust the code comments.
v3 -> v4:
1. Move function comment to header file.
2. Use bool for found, and add a new "err" for the return value of arch_get_ram_range.
3. Use -ENODATA instead of -EINVAL for non-RAM type ranges. 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 | 15 +++++++++++++++ xen/arch/x86/srat.c | 30 ++++++++++++++++++------------ xen/include/xen/numa.h | 13 +++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-)
xen/arch/x86/numa.c +15 -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...)
@@ -93,3 +94,17 @@ unsigned int __init arch_get_dma_bitsize(void)flsl (node_start_pfn (node) +node_spanned_pages (node) /4 -1 ) + PAGE_SHIFT, 32); } + +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 -ENODATA ; + + *start = e820.map[idx].addr; + *end = *start + e820.map[idx].size; + +return 0 ; +}
xen/arch/x86/srat.c +18 -12
@@ -428,37 +428,43 @@ 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++) { -int j, found; +for (i =0 ; ; i++) { +int err; +unsigned int j; +bool found;paddr_t start, end; -if (e820.map[i].type !=E820_RAM ) { -continue ; - } +/* Try to loop memory map from index 0 to end to get RAM ranges. */ + err =arch_get_ram_range (i, &start, &end); - start = e820.map[i].addr; - end = e820.map[i].addr + e820.map[i].size; +/* Reached the end of the memory map? */ +if (err == -ENOENT ) +break ; + +/* Skip non-RAM entries. */ +if (err) +continue ;do { - found =0 ; + found = false;for_each_node_mask (j, memory_nodes_parsed)if (start < nodes[j].end && end > nodes[j].start) {if (start >= nodes[j].start) { start = nodes[j].end; - found =1 ; + found = true; }if (end <= nodes[j].end) { end = nodes[j].start; - found =1 ; + found = true; } } }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 +13 -0
@@ -81,6 +81,19 @@ static inline nodeid_t __attribute_pure__ phys_to_nid(paddr_t addr)#define node_end_pfn (nid) (NODE_DATA(nid)->node_start_pfn + \ NODE_DATA(nid)->node_spanned_pages) +/* +* 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 other +* error codes, e.g. return -ENODATA for non-RAM type memory entry. +* +* Note: the range is exclusive at the end, e.g. [*start, *end). +*/ +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
PATCH v5 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. And we introduced a CONFIG_HAS_NUMA_NODE_FWID to prevent print the mapping between node id and architectural node id for those architectures do not have 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.
---
v4 -> v5:
1. Introduce arch_numa_disabled for acpi_numa <= 0 in this patch.
2. Remove the paramter init_as_disable of arch_numa_disabled.
3. Fix typo "expandsion".
4. Add const to proper varibales.
5. Fix Indentation for l1tf_safe_maddr.
6. Remove double blank lines.
7. Add a space between for_each_node_mask and '('.
Add a space page_list_for_each and '('.
8. Use bool for nodes_cover_memory return value.
9. Use a plain "int ret" to record compute_hash_shift return value.
10. Add a blank line before the function's main "return".
11. Add new Kconfig option HAS_NUMA_NODE_FWID to common/Kconfig. v3 -> v4:
1. Use bool as return value for functions that only return 0/1 or 0/-EINVAL.
2. Move mem_hotplug to a proper place in mm.h
3. Remove useless "size" in numa_scan_nodes.
4. Use unsigned int or const for proper variables.
5. Fix code-style.
6. Add init_as_disable as arch_numa_disabled parameter.
7. Add CONFIG_HAS_NUMA_NODE_FWID to gate print the mapping between node id and architectural node id (fw node id).
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/numa.c | 5 + xen/arch/x86/srat.c | 311 +++--------------------------- xen/common/Kconfig | 3 + xen/common/numa.c | 322 +++++++++++++++++++++++++++++++- xen/common/page_alloc.c | 2 + xen/drivers/acpi/Kconfig | 1 + xen/include/xen/mm.h | 2 + xen/include/xen/numa.h | 11 +- 12 files changed, 368 insertions(+), 297 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/numa.c +5 -0
@@ -46,6 +46,11 @@ bool arch_numa_broken(void)return acpi_numa <0 ; } +bool arch_numa_disabled (void ) +{ +return acpi_numa <=0 ; +} +/* * Setup early cpu_to_node. *
xen/arch/x86/srat.c +23 -288
402 lines not on this page · raw message
xen/common/Kconfig +3 -0
@@ -49,6 +49,9 @@ config HAS_IOPORTS config HAS_KEXEC bool +config HAS_NUMA_NODE_FWID + bool + config HAS_PDX bool
xen/common/numa.c +321 -1
340 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/drivers/acpi/Kconfig +1 -0
@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUP config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMA
xen/include/xen/mm.h +2 -0
@@ -147,6 +147,8 @@ int assign_page(/* Dump info to serial console */ void arch_dump_shared_mem_info (void ); +extern paddr_t mem_hotplug; +/* * Extra fault info types which are used to further describe * the source of an access violation.
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))
@@ -42,10 +43,11 @@ 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_process_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_broken (void ); +extern bool arch_numa_disabled (void );extern void setup_node_bootmem (nodeid_t nodeid,paddr_t start,paddr_t end);static inline void clear_node_cpumask (unsigned int cpu)
@@ -93,6 +95,13 @@ static inline nodeid_t __attribute_pure__ phys_to_nid(paddr_t addr)*/ extern int arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end); +extern bool valid_numa_range (paddr_t start,paddr_t end,nodeid_t node); +extern bool numa_memblks_available (void ); +extern bool 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 v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Quoted 17 lines · Wei Chen
xen/common/numa.c +17
-0+static bool __init nodes_cover_memory (void ) +{ +unsigned int i; + +for ( i =0 ; ; i++ ) + { +int err; +bool found; +unsigned int j; +paddr_t start, end; + +/* Try to loop memory map from index 0 to end to get RAM ranges. */ + err =arch_get_ram_range (i, &start, &end); + +/* Reached the end of the memory map? */ +if ( err == -ENOENT ) +break ;
xen/common/numa.c bool numa_disabled(void) · line 276
Quoted 10 lines
xen/common/numa.c +10
-0+ +/* Skip non-RAM entries. */ +if ( err ) +continue ; + + do { + found = false; + for_each_node_mask ( j, memory_nodes_parsed ) + if ( start < nodes[j].end + && end > nodes[j].start )
Nit: Style (placement of && and indentation). Does this actually need splitting across two lines?
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 8 lines
xen/drivers/acpi/Kconfig +1
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUP config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMA
While I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
Jan
Re: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Hi Jan,
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Wei Chen
xen/common/numa.c +22
-0+static bool __init nodes_cover_memory (void ) +{ +unsigned int i; + +for ( i =0 ; ; i++ ) + { +int err; +bool found; +unsigned int j; +paddr_t start, end; + +/* Try to loop memory map from index 0 to end to get RAM ranges. */ + err =arch_get_ram_range (i, &start, &end); + +/* Reached the end of the memory map? */ +if ( err == -ENOENT ) +break ; + +/* Skip non-RAM entries. */ +if ( err ) +continue ; +
Quoted 9 lines
xen/common/numa.c bool numa_disabled(void) · line 276
Quoted 5 lines
xen/common/numa.c +5
-0+ do { + found = false; + for_each_node_mask ( j, memory_nodes_parsed ) + if ( start < nodes[j].end + && end > nodes[j].start )Nit: Style (placement of && and indentation). Does this actually need splitting across two lines?
After covert from tab to spaces, yes, it doesn't need split into two lines. I will fix it.
Quoted 4 lines
Quoted 4 lines
xen/drivers/acpi/Kconfig +0
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUP
Quoted 10 lines
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 4 lines
xen/drivers/acpi/Kconfig +1
-0config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMAWhile I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
Ok, I will adjust the order.
Quoted 5 lines
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
We are also working in this way. In part#3, we will check ACPI first,
only when ACPI is off, the DT NUMA will be used by Arm. If ACPI is on, we will skip DT NUMA.
Cheers,
Wei Chen
Quoted 2 lines
Jan
Re: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Quoted 25 lines · Wei Chen
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Wei Chen
xen/drivers/acpi/Kconfig +0
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUPQuoted 10 lines
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 4 lines
xen/drivers/acpi/Kconfig +1
-0config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMAWhile I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
Ok, I will adjust the order.
Quoted 5 lines
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
Quoted 3 lines
We are also working in this way. In part#3, we will check ACPI first, only when ACPI is off, the DT NUMA will be used by Arm. If ACPI is on, we will skip DT NUMA.
Even more so an answer to my question would be nice: You'll then have CONFIG_HAS_NUMA_NODE_FWID=y even on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).
Jan
RE: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Hi Jan,
Quoted 41 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年9月29日 20:21
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 v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to commonQuoted 25 lines · Wei Chen
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Wei Chen
xen/drivers/acpi/Kconfig +0
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUPQuoted 10 lines
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 4 lines
xen/drivers/acpi/Kconfig +1
-0config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMAWhile I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
Ok, I will adjust the order.
Quoted 5 lines
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
Quoted 3 lines
We are also working in this way. In part#3, we will check ACPI first, only when ACPI is off, the DT NUMA will be used by Arm. If ACPI is on, we will skip DT NUMA.
Quoted 5 lines
Even more so an answer to my question would be nice: You'll then have
CONFIG_HAS_NUMA_NODE_FWID=yeven on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).
How about introducing a flag for selected NUMA implementation to set it in runtime?
For example:
bool numa_has_fw_nodeid;
ACPI NUMA will set this flag to 1, but 0 for DT NUMA.
Cheers,
Wei Chen
Quoted 2 lines
Jan
Re: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Quoted 40 lines · Wei Chen
Quoted 34 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年9月29日 20:21Quoted 25 lines · Wei Chen
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Wei Chen
xen/drivers/acpi/Kconfig +0
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUPQuoted 10 lines
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 4 lines
xen/drivers/acpi/Kconfig +1
-0config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMAWhile I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
Ok, I will adjust the order.
Quoted 5 lines
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
Quoted 3 lines
We are also working in this way. In part#3, we will check ACPI first, only when ACPI is off, the DT NUMA will be used by Arm. If ACPI is on, we will skip DT NUMA.
Quoted 5 lines
Even more so an answer to my question would be nice: You'll then have
CONFIG_HAS_NUMA_NODE_FWID=yeven on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).
Quoted 6 lines
How about introducing a flag for selected NUMA implementation to set it in runtime?
For example:
boolnuma_has_fw_nodeid;ACPI NUMA will set this flag to 1, but 0 for DT NUMA.
That's an option alongside going back to what you had in an earlier version. Another would be (name subject to improvement)
const char *__ro_after_init numa_fw_nid_name;
which for ACPI would be set to "PXM" (eliminating the need to pass it to certain functions, albeit the fw_nid will continue to need to be passed anyway). I guess I'm not really certain which of this and your earlier approach I prefer; the boolean you suggest above looks less desirable to me, though.
Jan
RE: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Hi Jan,
Quoted 62 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年9月30日 14:03
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 v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to commonQuoted 40 lines · Wei Chen
Quoted 34 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 2022年9月29日 20:21Quoted 25 lines · Wei Chen
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Wei Chen
xen/drivers/acpi/Kconfig +0
-0@@ -7,4 +7,5 @@ config ACPI_LEGACY_TABLES_LOOKUPQuoted 10 lines
xen/drivers/acpi/Kconfig config ACPI_LEGACY_TABLES_LOOKUP · line 11
Quoted 4 lines
xen/drivers/acpi/Kconfig +1
-0config ACPI_NUMA bool + select HAS_NUMA_NODE_FWID select NUMAWhile I might guess that you've chosen the insertion point to have things sorted alphabetically, I think here it would be more natural to select the wider option first and then also select the more narrow one.
Ok, I will adjust the order.
Quoted 5 lines
One further question though: How is this going to work for Arm64 once it wants to support both the form of NUMA you're working to enable _and_ ACPI-based NUMA? There better wouldn't be a requirement to pick one of the two at build time - it would be nice for support of both forms to be able to co-exist in a single binary.
Quoted 3 lines
We are also working in this way. In part#3, we will check ACPI first, only when ACPI is off, the DT NUMA will be used by Arm. If ACPI is on, we will skip DT NUMA.
Quoted 5 lines
Even more so an answer to my question would be nice: You'll then have
CONFIG_HAS_NUMA_NODE_FWID=yeven on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).Quoted 6 lines
How about introducing a flag for selected NUMA implementation to set it in runtime?
For example:
boolnuma_has_fw_nodeid;ACPI NUMA will set this flag to 1, but 0 for DT NUMA.
That's an option alongside going back to what you had in an earlier version. Another would be (name subject to improvement)
Quoted 8 lines
const char
*__ro_after_initnuma_fw_nid_name;which for ACPI would be set to "PXM" (eliminating the need to pass it to certain functions, albeit the
fw_nidwill continue to need to be passed anyway). I guess I'm not really certain which of this and your earlier approach I prefer; the boolean you suggest above looks less desirable to me, though.
Ok, I will follow your suggestion.
Cheers,
Wei Chen
Quoted 1 line
Jan
Re: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Hi Jan,
Quoted 20 lines · Wei Chen
Hi Jan,
Quoted 19 lines
Quoted 7 lines
Quoted 6 lines
Even more so an answer to my question would be nice: You'll then have
CONFIG_HAS_NUMA_NODE_FWID=yeven on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).Quoted 6 lines
How about introducing a flag for selected NUMA implementation to set it in runtime?
For example:
boolnuma_has_fw_nodeid;ACPI NUMA will set this flag to 1, but 0 for DT NUMA.
That's an option alongside going back to what you had in an earlier version. Another would be (name subject to improvement)
const char
*__ro_after_initnuma_fw_nid_name;
When I was dealing with this comment, I found that I was still a little unclear:
When we were introducing "CONFIG_HAS_NUMA_NODE_FWID", we wanted to eliminate the redundant code of:
if ( fwid_name not equal to "node" )
printk(KERN_INFO "NUMA: Node %u %s %u [%"PRIpaddr"%"PRIpaddr"]%s\n",
node, fwid_name , arch_nid, start, end - 1,
hotplug ? " (hotplug)" : "");
else
printk(KERN_INFO "NUMA: Node %u [%"PRIpaddr", %"PRIpaddr"]%s\n",
node, start, end - 1, hotplug ? " (hotplug)" : "");But when I am working with numa_fw_nid_name, I find it's still not easy to reduce above redundant code. For example:
"NUMA: Node %u %s %u
When numa_fw_nid_name = NULL, we can print "" for %s, but can't reduce the second %u.
So can we split this message into 3 lines like:
printk(KERN_INFO "NUMA: Node %u"...);
if (numa_fw_nid_name)
printk(KERN_INFO " %s %u"...);
printk(KERN_INFO "[%"PRIpaddr"%"PRIpaddr"]%s\n"...);Or another option, we can force each NUMA implementation to assign a string for numa_fw_nid_name. For example, in DT NUMA, we can assign numa_fw_nid_name="SOCKET".
Cheers,
Wei Chen
Quoted 13 lines
Quoted 6 lines
which for ACPI would be set to "PXM" (eliminating the need to pass it to certain functions, albeit the
fw_nidwill continue to need to be passed anyway). I guess I'm not really certain which of this and your earlier approach I prefer; the boolean you suggest above looks less desirable to me, though.Ok, I will follow your suggestion.
Cheers,
Wei ChenQuoted 1 line
Jan
Re: [PATCH v5 5/6] xen/x86: move NUMA scan nodes codes from x86 to common
Quoted 33 lines · Wei Chen
Quoted 11 lines · Wei Chen
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Even more so an answer to my question would be nice: You'll then have
CONFIG_HAS_NUMA_NODE_FWID=yeven on Arm (using PXM as mandated by ACPI when in ACPI mode). But then what's the FWID for DT? I know it was me to suggest this build time distinction, but I'm afraid I wasn't doing much good with that (and I'm sorry).How about introducing a flag for selected NUMA implementation to set it in runtime?
For example:
boolnuma_has_fw_nodeid;Quoted 7 lines
Quoted 7 lines
Quoted 1 line
ACPI NUMA will set this flag to 1, but 0 for DT NUMA.
That's an option alongside going back to what you had in an earlier version. Another would be (name subject to improvement)
const char
*__ro_after_initnuma_fw_nid_name;When I was dealing with this comment, I found that I was still a little unclear:
When we were introducing "
CONFIG_HAS_NUMA_NODE_FWID", we wanted to eliminate the redundant code of:
if (fwid_namenot equal to "node" )printk(KERN_INFO "NUMA: Node %u %s %u [%"PRIpaddr"%"PRIpaddr"]%s\n", node, fwid_name , 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 2 lines
But when I am working with
numa_fw_nid_name, I find it's still not easy to reduce above redundant code. For example:
As said - this attempt to limit redundancy was a mistake when it comes to the existence of two models in parallel for an arch (with either one picked at runtime), unless ...
Quoted 5 lines
"NUMA: Node %u %s %u
Whennuma_fw_nid_name= NULL, we can print "" for %s, but can't reduce the second %u.So can we split this message into 3 lines like:
Quoted 8 lines
printk(KERN_INFO "NUMA: Node %u"...); if (numa_fw_nid_name) printk(KERN_INFO " %s %u"...); printk(KERN_INFO "[%"PRIpaddr"%"PRIpaddr"]%s\n"...);Or another option, we can force each NUMA implementation to assign a string for
numa_fw_nid_name. For example, in DT NUMA, we can assign numa_fw_nid_name="SOCKET".
... we can assume numa_fw_nid_name to always be non-NULL (is there's any way to reach this piece of code). I have no insight whether "socket" is a correct term to use in the DT case; that would need to be confirmed by an Arm person.
Jan
PATCH v5 6/6 xen: introduce a Kconfig option to configure NUMA nodes number
In reply to Wei ChenCurrently 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.
As NODES_SHIFT is currently unused, we're taking this opportunity to remove it.
---
v4 -> v5:
1. No change.
v3 -> v4:
1. Update the commit log to follow Jan's suggestion.
2. Add Ack-by.
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