Introduce Device Tree based NUMA support for ARM Xen
v2 cover Introduce Device Tree based NUMA support for ARM Xen
Hello,
Regarding the configuration, we now select CONFIG_ARM_NUMA when using NUMA on ARM Xen. Eventually, it would be great to have NUMA enabled by default, just like it is on x86.
I also fixed a bug in the DomU memory layout creation where an x86 dependency was breaking memory allocation for vNUMA nodes. With this fix, it correctly references the domain's vNUMA node information and performs NUMA-aware memory allocation. For now, I've applied a simple fix using #ifdef, but I'm wondering if we should make this more generic.
Additionally, some code borrowed from the Linux kernel doesn't strictly follow the Xen coding style. I've left it as-is for now because I want to avoid creating unnecessary diffs against the original Linux kernel code.
Changes in v2:
- Fix vNUMA memory allocation algorithm to support ARM
- Allocate vNUMA memory from the associated pNUMA memory
- Include the XSM Policy module size in the required memory calculation for Dom0 Bank 0.
- Enforce a minimum chunk size of 4MB during Dom0 memory allocation.
- Define the cpu_to_core() and cpu_to_socket() macros in cpu-topology.h instead of processor.h, as processor.h should strictly focus on processor hardware information.
- Make cpu_nr_siblings() an architecture-specific function.
- Refine the code to conform with the Xen coding style guidelines.
Thanks,
Hirokazu Takahashi
Hirokazu Takahashi (24):
xen/device-tree: Initial framework for Device Tree NUMA support xen/arm: NUMA helper functions via Device Tree helpers xen/arm: Introduce CONFIG_DEVICE_TREE_NUMA config option xen/arm: Configure NUMA affinity for populated memory banks xen/arm: Map populated CPUs to their respective NUMA nodes xen/device-tree: Read NUMA node distance from Device Tree
'distance-map'
xen/device-tree: Parse 'cpu-map' node for CPU topology exploration xen/sched: Link CPU topology to scheduler and display via xl info xen/sched: Make cpu_nr_siblings() architecture-specific xen/common: Allow building ARM32 Xen with CONFIG_NUMA tools/libxl: Fix vNUMA memory allocation algorithm to support ARM tools/libs/guest: Allocate vNUMA memory from associated pNUMA nodes tools/libxl: Add 'numa-node-id' property to DomU memory nodes tools/libxl: Add 'numa-node-id' property to DomU CPU nodes tools/libxl: Create 'distance-map' node in DomU Device Tree xen/arm: Introduce dom0_nodes boot command option xen/arm: Set Domain-0 node affinity from dom0_nodes option xen/arm: Reflect physical NUMA node IDs in Dom0 memory DT nodes xen/arm: Balance Dom0 vCPU assignment across NUMA nodes xen/arm: Export Dom0 vCPU-to-NUMA node mapping to Device Tree xen/arm: Generate distance-map node for Dom0 Device Tree xen/arm: Balance Dom0 memory allocation across allowed NUMA nodes xen/arm: Use dedicated function for Static SHM Device Tree creation xen/arm: Support numa and dom0_nodes boot options
docs/misc/xen-command-line.pandoc | 9 +- tools/libs/guest/xg_dom_arm.c | 62 +++- tools/libs/light/libxl_arm.c | 103 ++++++- tools/libs/light/libxl_vnuma.c | 13 +- xen/arch/arm/Kconfig | 9 + xen/arch/arm/Makefile | 1 + xen/arch/arm/domain_build.c | 428 +++++++++++++++++++------- xen/arch/arm/include/asm/numa.h | 19 ++ xen/arch/arm/include/asm/processor.h | 4 - xen/arch/arm/numa.c | 62 ++++ xen/arch/arm/setup.c | 4 + xen/arch/arm/smpboot.c | 35 ++- xen/arch/x86/include/asm/processor.h | 1 + xen/common/Kconfig | 7 + xen/common/device-tree/Makefile | 2 + xen/common/device-tree/bootinfo-fdt.c | 8 + xen/common/device-tree/cpu-topology.c | 360 ++++++++++++++++++++++ xen/common/device-tree/domain-build.c | 99 +++--- xen/common/device-tree/numa.c | 142 +++++++++ xen/common/numa.c | 2 +- xen/common/sched/credit2.c | 22 +- xen/common/sysctl.c | 1 + xen/include/xen/bootinfo.h | 37 +++ xen/include/xen/cpu-topology.h | 53 ++++ xen/include/xen/dt-numa.h | 31 ++ xen/include/xen/fdt-domain-build.h | 2 + 26 files changed, 1310 insertions(+), 206 deletions(-) create mode 100644 xen/arch/arm/include/asm/numa.h create mode 100644 xen/arch/arm/numa.c create mode 100644 xen/common/device-tree/cpu-topology.c create mode 100644 xen/common/device-tree/numa.c create mode 100644 xen/include/xen/cpu-topology.h create mode 100644 xen/include/xen/dt-numa.h
Signature · 1 line
2.43.0
PATCH v2 1/24 xen/device-tree: Initial framework for Device Tree NUMA support
Introduce the initial framework for Device Tree-based NUMA support on ARM Xen. This patch adds the required Device Tree-dependent helper functions needed for NUMA configuration. Note that some functions currently contain stub implementations.
--- xen/common/device-tree/Makefile | 1 + xen/common/device-tree/numa.c | 24 ++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 14 ++++++++++++++ xen/include/xen/dt-numa.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 xen/common/device-tree/numa.c create mode 100644 xen/include/xen/dt-numa.h
xen/common/device-tree/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-bindings.init.o obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += intc.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o +obj-$(CONFIG_DEVICE_TREE_NUMA) += numa.o obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o obj-$(CONFIG_STATIC_MEMORY) += static-memory.init.o obj-$(CONFIG_STATIC_SHM) += static-shmem.init.o
xen/common/device-tree/numa.c new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <xen/bootinfo.h> +#include <xen/device_tree.h> +#include <xen/libfdt/libfdt.h> +#include <xen/bootfdt.h> +#include <xen/errno.h> +#include <xen/init.h> +#include <xen/nodemask.h> +#include <xen/numa.h> + +#define LOCAL_DISTANCE 10 +#define REMOTE_DISTANCE 20 + +/* +* Get the distance between node 'a' and node 'b'. +*/ +u8 dt_node_distance (u8 a,u8 b) +{ +if ( a != b ) +return REMOTE_DISTANCE ; +return LOCAL_DISTANCE ; +} +
xen/include/xen/bootinfo.h +14 -0
@@ -6,6 +6,7 @@#include <xen/kernel.h> #include <xen/macros.h> #include <xen/xmalloc.h> +#include <xen/errno.h> #define NR_MEM_BANKS 256#define NR_SHMEM_BANKS 32
@@ -214,4 +215,17 @@ void fw_unreserved_regions(paddr_t s, paddr_t e,void (*cb)(paddr_t ps,paddr_t pe), unsigned int first); +static inline int bootinfo_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end) +{ +struct membanks *mem =bootinfo_get_mem (); + +if ( idx >= mem->nr_banks) +return -ENOENT ; + + *start = mem->bank[idx].start; + *end = *start + mem->bank[idx].size; + +return 0 ; +} +#endif /* XEN_BOOTINFO_H */
xen/include/xen/dt-numa.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_DT_NUMA_H +#define XEN_DT_NUMA_H + +#include <xen/types.h> +#include <xen/device_tree.h> + +static inline unsigned int numa_node_to_dt_nid (u32 n) +{ +return n; +} + +#ifdef CONFIG_DEVICE_TREE_NUMA + +u8 dt_node_distance (u8 a,u8 b); + +#endif /* CONFIG_DEVICE_TREE_NUMA */ + +#endif /* XEN_DT_NUMA_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v2 2/24 xen/arm: NUMA helper functions via Device Tree helpers
In reply to Hirokazu TakahashiImplement the NUMA helper functions for ARM Xen by invoking the Device Tree-based NUMA helper functions.
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/include/asm/numa.h | 18 +++++++++++ xen/arch/arm/numa.c | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 xen/arch/arm/include/asm/numa.h create mode 100644 xen/arch/arm/numa.c
xen/arch/arm/Makefile +1 -0
@@ -51,6 +51,7 @@ obj-y += setup.o obj-y += shutdown.o obj-y += smp.o obj-y += smpboot.o +obj-$(CONFIG_NUMA) += numa.o obj-$(CONFIG_SYSCTL) += sysctl.o obj-y += time.o obj-y += traps.o
xen/arch/arm/include/asm/numa.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef _ASM_ARM_NUMA_H +#define _ASM_ARM_NUMA_H 1 + +#include <xen/cpumask.h> +#include <xen/vmap.h> +#include <xen/dt-numa.h> + +typedef u8 nodeid_t ; + +#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT)) + +extern bool numa_disabled (void ); +extern unsigned int numa_node_to_arch_nid (nodeid_t n); +extern u8 __node_distance (nodeid_t a,nodeid_t b); + +#define arch_want_default_dmazone () (num_online_nodes() > 1) + +#endif /* _ASM_ARM_NUMA_H */
xen/arch/arm/numa.c new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 3/24 xen/arm: Introduce CONFIG_DEVICE_TREE_NUMA config option
In reply to Hirokazu TakahashiIntroduce the CONFIG_CONFIG_DEVICE_TREE_NUMA configuration option for Device Tree-based NUMA support. Selecting CONFIG_ARM_NUMA enables CONFIG_DEVICE_TREE_NUMA, which in turn automatically selects CONFIG_NUMA. While this option is currently restricted to the ARM architecture, it is designed to be selectable for RISC-V and PPC in the future.
This patch also includes the necessary compilation fixes required when building with CONFIG_NUMA, and creates a single fake NUMA node to ensure Xen can boot successfully at this stage.
--- xen/arch/arm/Kconfig | 8 ++++++++ xen/arch/arm/setup.c | 4 ++++ xen/arch/arm/smpboot.c | 2 ++ xen/common/Kconfig | 4 ++++ 4 files changed, 18 insertions(+)
xen/arch/arm/Kconfig +8 -0
@@ -99,6 +99,14 @@ config MPU systems supporting EL2. (UNSUPPORTED) endchoice +config ARM_NUMA + bool "Device tree based NUMA support (UNSUPPORTED)" if UNSUPPORTED + select DEVICE_TREE_NUMA + help + Device tree based NUMA support. The "numa-node-id" property in + the CPU and memory nodes of a Device Tree defines the NUMA node + to which they belong. + source "arch/Kconfig" config ACPI
xen/arch/arm/setup.c +4 -0
@@ -351,6 +351,10 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)/* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init (); +#ifdef CONFIG_NUMA +numa_initmem_init (0x0UL ,0x1UL << (PADDR_BITS -12 )); +#endif /* CONFIG_NUMA */ +end_boot_allocator ();/*
xen/arch/arm/smpboot.c +2 -0
@@ -47,8 +47,10 @@ integer_param("maxcpus", max_cpus);/* CPU logical map: map xen cpuid to an MPIDR */ register_t __cpu_logical_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =MPIDR_INVALID }; +#ifndef CONFIG_NUMA /* Fake one node for now. See also xen/numa.h */ nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } }; +#endif /* CONFIG_NUMA */ /* Xen stack for bringing up the first CPU. */ static unsigned char __initdata cpu0_boot_stack[STACK_SIZE ]
xen/common/Kconfig +4 -0
@@ -188,6 +188,10 @@ config VM_EVENT config NEEDS_LIBELF bool +config DEVICE_TREE_NUMA + select NUMA + bool + config NUMA bool
Signature · 1 line
2.43.0
Re: [PATCH v2 03/24] xen/arm: Introduce CONFIG_DEVICE_TREE_NUMA config option
xen/arch/arm/Kconfig config MPU · line 104
Quoted 9 lines · Hirokazu Takahashi
xen/arch/arm/Kconfig +3
-0@@ -99,6 +99,14 @@ config MPU systems supporting EL2. (UNSUPPORTED) endchoice +config ARM_NUMA + bool "Device tree based NUMA support (UNSUPPORTED)" if UNSUPPORTED + select DEVICE_TREE_NUMA
Nit: Indentation.
xen/common/Kconfig config VM_EVENT · line 193
Quoted 9 lines
xen/common/Kconfig +3
-0@@ -188,6 +188,10 @@ config VM_EVENT config NEEDS_LIBELF bool +config DEVICE_TREE_NUMA + select NUMA + bool
Nit: Can we have type ("bool") first, with "select" (or "depends on") coming afterwards?
Jan
RE: [PATCH v2 03/24] xen/arm: Introduce CONFIG_DEVICE_TREE_NUMA config option
Hello,
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+config ARM_NUMA + bool "Device tree based NUMA support (UNSUPPORTED)" ifUNSUPPORTED
Quoted 1 line
+ select
DEVICE_TREE_NUMANit: Indentation.
Ok, I will fix it.
Quoted 6 lines
Quoted 6 lines
xen/common/Kconfig +0
-0@@ -188,6 +188,10 @@ config VM_EVENT config NEEDS_LIBELF bool
Quoted 6 lines
xen/common/Kconfig config VM_EVENT · line 193
Quoted 3 lines
xen/common/Kconfig +3
-0+config DEVICE_TREE_NUMA + select NUMA + boolNit: Can we have type ("bool") first, with "select" (or "depends on") coming afterwards?
Ok.
Re: [PATCH v2 03/24] xen/arm: Introduce CONFIG_DEVICE_TREE_NUMA config option
In reply to Jan BeulichHello,
Quoted 11 lines
xen/arch/arm/Kconfig config MPU · line 104
Quoted 9 lines
xen/arch/arm/Kconfig +3
-0@@ -99,6 +99,14 @@ config MPU systems supporting EL2. (UNSUPPORTED) endchoice +config ARM_NUMA + bool "Device tree based NUMA support (UNSUPPORTED)" if UNSUPPORTED + select DEVICE_TREE_NUMANit: Indentation.
ok, I wiil fix it.
Quoted 6 lines
Quoted 6 lines
xen/common/Kconfig +0
-0@@ -188,6 +188,10 @@ config VM_EVENT config NEEDS_LIBELF bool
Quoted 6 lines
xen/common/Kconfig config VM_EVENT · line 193
Quoted 3 lines
xen/common/Kconfig +3
-0+config DEVICE_TREE_NUMA + select NUMA + boolNit: Can we have type ("bool") first, with "select" (or "depends on") coming afterwards?
ok. I will.
PATCH v2 4/24 xen/arm: Configure NUMA affinity for populated memory banks
In reply to Hirokazu TakahashiConfigure NUMA affinity for the populated memory banks. The NUMA node ID for each memory bank is retrieved from the Device Tree.
--- xen/arch/arm/include/asm/numa.h | 1 + xen/arch/arm/numa.c | 7 +++++++ xen/arch/arm/setup.c | 2 +- xen/common/device-tree/bootinfo-fdt.c | 8 ++++++++ xen/common/device-tree/numa.c | 29 +++++++++++++++++++++++++++ xen/include/xen/bootinfo.h | 23 +++++++++++++++++++++ xen/include/xen/dt-numa.h | 1 + 7 files changed, 70 insertions(+), 1 deletion(-)
xen/arch/arm/include/asm/numa.h +1 -0
@@ -12,6 +12,7 @@ typedef u8 nodeid_t;extern bool numa_disabled (void );extern unsigned int numa_node_to_arch_nid (nodeid_t n);extern u8 __node_distance (nodeid_t a,nodeid_t b); +extern void numa_memory_affinity_init (void );#define arch_want_default_dmazone () (num_online_nodes() > 1)
xen/arch/arm/numa.c +7 -0
@@ -36,6 +36,13 @@ int __init arch_numa_setup(const char *opt)return 0 ; } +void __init numa_memory_affinity_init (void ) +{ +dt_numa_memory_affinity_init (); + +numa_initmem_init (0x0UL ,0x1UL << (PADDR_BITS -12 )); +} +int __init arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end) {return bootinfo_get_ram_range (idx, start, end);
xen/arch/arm/setup.c +1 -1
@@ -352,7 +352,7 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)acpi_boot_table_init ();#ifdef CONFIG_NUMA -numa_initmem_init (0x0UL ,0x1UL << (PADDR_BITS -12 )); +numa_memory_affinity_init ();#endif /* CONFIG_NUMA */ end_boot_allocator ();
xen/common/device-tree/bootinfo-fdt.c +8 -0
@@ -121,6 +121,9 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,const __be32 *cell;u32 reg_cells = address_cells + size_cells;paddr_t start, size; +#ifdef CONFIG_DEVICE_TREE_NUMA +uint32_t nid; +#endif /* CONFIG_DEVICE_TREE_NUMA */ if ( !device_tree_node_is_available (fdt, node) )return 0 ;
@@ -136,6 +139,10 @@ static int __init device_tree_get_meminfo(const void *fdt, int node,if ( !prop )return -ENOENT ; +#ifdef CONFIG_DEVICE_TREE_NUMA + nid =device_tree_get_u32 (fdt, node,"numa-node-id" ,0U ); +#endif /* CONFIG_DEVICE_TREE_NUMA */ + cell = (const __be32 *)prop->data; banks =fdt32_to_cpu (prop->len) / (reg_cells *sizeof (u32));
@@ -158,6 +165,7 @@ static int __init device_tree_get_meminfo(const void *fdt, int node, mem->bank[mem->nr_banks].start = start; mem->bank[mem->nr_banks].size = size; mem->bank[mem->nr_banks].type = type; +set_numa_nodeid (&mem->bank[mem->nr_banks], nid); mem->nr_banks++; }
xen/common/device-tree/numa.c +29 -0
@@ -22,3 +22,32 @@ u8 dt_node_distance(u8 a, u8 b)return LOCAL_DISTANCE ; } +/* +* Initialize memory affinity by registering bootinfo memory banks into Xen's +* NUMA subsystem. +*/ +void __init dt_numa_memory_affinity_init (void ) +{ +const struct membanks *mem =bootinfo_get_mem (); +unsigned int bank; +nodeid_t nid; + + numa_fw_nid_name ="DT" ; + +for ( bank =0 ; bank < mem->nr_banks; bank++ ) + { + nid =get_numa_nodeid (&mem->bank[bank]); + +if (numa_memblks_available ()) + { +numa_update_node_memblks (nid, nid, mem->bank[bank].start, mem->bank[bank].size, false); + } +else + { +dprintk (XENLOG_WARNING , +"Too many numa entries, try bigger NR_NODE_MEMBLKS!\n" ); +numa_fw_bad (); +break ; + } + } +}
xen/include/xen/bootinfo.h +23 -0
@@ -7,6 +7,7 @@#include <xen/macros.h> #include <xen/xmalloc.h> #include <xen/errno.h> +#include <xen/numa.h> #define NR_MEM_BANKS 256#define NR_SHMEM_BANKS 32
@@ -56,6 +57,9 @@ struct shmem_membank_extra {struct membank {paddr_t start;paddr_t size; +#ifdef CONFIG_DEVICE_TREE_NUMA +uint32_t numa_id; +#endif /* CONFIG_DEVICE_TREE_NUMA */ union {enum membank_type type;#ifdef CONFIG_STATIC_SHM
@@ -228,4 +232,23 @@ static inline int bootinfo_get_ram_range(unsigned int idx, paddr_t *start, paddr return 0; } +#ifdef CONFIG_DEVICE_TREE_NUMA +static inline uint32_t get_numa_nodeid (const struct membank *bank) +{ +if (numa_disabled () )return 0U ; + +return bank->numa_id; +} + +static inline void set_numa_nodeid (struct membank *bank,uint32_t nid) +{ +if (numa_disabled () ) nid =0U ; + + bank->numa_id = nid; +} +#else /* CONFIG_DEVICE_TREE_NUMA */ +#define get_numa_nodeid (bank) (0) +#define set_numa_nodeid (bank, nid) {} +#endif /* CONFIG_DEVICE_TREE_NUMA */ +#endif /* XEN_BOOTINFO_H */
xen/include/xen/dt-numa.h +1 -0
@@ -14,6 +14,7 @@ static inline unsigned int numa_node_to_dt_nid(u32 n)#ifdef CONFIG_DEVICE_TREE_NUMA u8 dt_node_distance (u8 a,u8 b); +void dt_numa_memory_affinity_init (void );#endif /* CONFIG_DEVICE_TREE_NUMA */
Signature · 1 line
2.43.0
PATCH v2 5/24 xen/arm: Map populated CPUs to their respective NUMA nodes
In reply to Hirokazu TakahashiMap the populated CPUs to their respective NUMA nodes. The NUMA node ID for each CPU is retrieved from the Device Tree.
--- xen/arch/arm/smpboot.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
xen/arch/arm/smpboot.c +17 -0
@@ -133,6 +133,9 @@ static void __init dt_smp_init_cpus(void) };bool bootcpu_valid = false;int rc; +#ifdef CONFIG_DEVICE_TREE_NUMA +nodeid_t cpu_to_numa[NR_CPUS ]; +#endif /* CONFIG_DEVICE_TREE_NUMA */ mpidr = system_cpuinfo.mpidr.bits &MPIDR_HWID_MASK ;
@@ -244,6 +247,16 @@ static void __init dt_smp_init_cpus(void) }else tmp_map[i] = hwid; + +#ifdef CONFIG_DEVICE_TREE_NUMA +if ( tmp_map[i] !=MPIDR_INVALID ) + { +uint32_t nid; +if (numa_disabled () || !dt_property_read_u32 (cpu,"numa-node-id" , &nid) ) + nid =0U ;/* default node */ + cpu_to_numa[i] = nid >=MAX_NUMNODES ?0U : nid; + } +#endif /* CONFIG_DEVICE_TREE_NUMA */ }if ( !bootcpu_valid )
@@ -259,6 +272,10 @@ static void __init dt_smp_init_cpus(void)continue ;cpumask_set_cpu (i, &cpu_possible_map);cpu_logical_map (i) = tmp_map[i]; +#ifdef CONFIG_DEVICE_TREE_NUMA +numa_set_node (i, cpu_to_numa[i]); +numa_add_cpu (i); +#endif /* CONFIG_DEVICE_TREE_NUMA */ } }
Signature · 1 line
2.43.0
PATCH v2 6/24 xen/device-tree: Read NUMA node distance from Device Tree 'distance-map'
In reply to Hirokazu TakahashiRead the distance between NUMA nodes from the Device Tree's 'distance-map' node.
--- xen/arch/arm/numa.c | 2 + xen/common/device-tree/numa.c | 93 ++++++++++++++++++++++++++++++++++- xen/include/xen/dt-numa.h | 1 + 3 files changed, 94 insertions(+), 2 deletions(-)
xen/arch/arm/numa.c +2 -0
@@ -41,6 +41,8 @@ void __init numa_memory_affinity_init(void)dt_numa_memory_affinity_init ();numa_initmem_init (0x0UL ,0x1UL << (PADDR_BITS -12 )); + +dt_numa_distance_table_init (); }int __init arch_get_ram_range (unsigned int idx,paddr_t *start,paddr_t *end)
xen/common/device-tree/numa.c +91 -2
109 lines not on this page · raw message
xen/include/xen/dt-numa.h +1 -0
@@ -15,6 +15,7 @@ static inline unsigned int numa_node_to_dt_nid(u32 n)u8 dt_node_distance (u8 a,u8 b);void dt_numa_memory_affinity_init (void ); +void dt_numa_distance_table_init (void );#endif /* CONFIG_DEVICE_TREE_NUMA */
Signature · 1 line
2.43.0
PATCH v2 7/24 xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
In reply to Hirokazu TakahashiParse the 'cpu-map' node in the Device Tree to extract CPU topology information. If the 'cpu-map' node is absent, fall back to generating the topology data from the NUMA information. This generation assumes exactly one socket per NUMA node and that SMT is unsupported.
--- xen/arch/arm/Kconfig | 1 + xen/arch/arm/smpboot.c | 6 + xen/common/Kconfig | 3 + xen/common/device-tree/Makefile | 1 + xen/common/device-tree/cpu-topology.c | 306 ++++++++++++++++++++++++++ xen/include/xen/cpu-topology.h | 42 ++++ 6 files changed, 359 insertions(+) create mode 100644 xen/common/device-tree/cpu-topology.c create mode 100644 xen/include/xen/cpu-topology.h
xen/arch/arm/Kconfig +1 -0
@@ -102,6 +102,7 @@ endchoice config ARM_NUMA bool "Device tree based NUMA support (UNSUPPORTED)" if UNSUPPORTED select DEVICE_TREE_NUMA + select DT_CPU_TOPOLOGY help Device tree based NUMA support. The "numa-node-id" property in the CPU and memory nodes of a Device Tree defines the NUMA node
xen/arch/arm/smpboot.c +6 -0
@@ -24,6 +24,7 @@#include <xen/warning.h> #include <xen/irq.h> #include <xen/console.h> +#include <xen/cpu-topology.h> #include <asm/cpuerrata.h> #include <asm/gic.h> #include <asm/procinfo.h>
@@ -248,6 +249,8 @@ static void __init dt_smp_init_cpus(void)else tmp_map[i] = hwid; +map_cpuid_to_node (i, cpu);/* pass the info to dt_init_cpu_topology() */ +#ifdef CONFIG_DEVICE_TREE_NUMA if ( tmp_map[i] !=MPIDR_INVALID ) {
@@ -294,7 +297,10 @@ void __init smp_init_cpus(void) }if ( acpi_disabled ) + {dt_smp_init_cpus (); +dt_init_cpu_topology (); + }else acpi_smp_init_cpus ();
xen/common/Kconfig +3 -0
@@ -188,6 +188,9 @@ config VM_EVENT config NEEDS_LIBELF bool +config DT_CPU_TOPOLOGY + bool + config DEVICE_TREE_NUMA select NUMA bool
xen/common/device-tree/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-y += bootfdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo-fdt.init.o obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo.init.o +obj-$(CONFIG_DT_CPU_TOPOLOGY) += cpu-topology.o obj-y += device-tree.o obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += domain-build.init.o obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) += dom0less-build.init.o
xen/common/device-tree/cpu-topology.c new file +306 -0
306 lines not on this page · raw message
xen/include/xen/cpu-topology.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Quoted 6 lines · Hirokazu Takahashi
xen/include/xen/cpu-topology.h new file +3
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_CPU_TOPOLOGY_H
xen/include/xen/cpu-topology.h line 13
Quoted 10 lines
xen/include/xen/cpu-topology.h new file +10
-0+#define XEN_CPU_TOPOLOGY_H + +#include <xen/types.h> +#include <xen/device_tree.h> + +struct cpu_topology { +int thread_id; +int core_id; +int cluster_id; +int package_id;
Can any of these go negative? If not, "unsigned int" please. Iirc I said the same elsewhere on v1. Please apply such comments throughout the series.
xen/include/xen/cpu-topology.h line 21
Quoted 8 lines
xen/include/xen/cpu-topology.h new file +8
-0+cpumask_t thread_sibling; +cpumask_t core_sibling; +cpumask_t cluster_sibling; +}; + + +#ifdef CONFIG_DT_CPU_TOPOLOGY +extern struct cpu_topology cpu_topology[NR_CPUS ];
If at all possible, no new NR_CPUS dimensioned arrays please.
xen/include/xen/cpu-topology.h line 28
Quoted 6 lines
xen/include/xen/cpu-topology.h new file +6
-0+void map_cpuid_to_node (u32 cpuid,struct dt_device_node *cpu_node); +void dt_init_cpu_topology (void ); + +#elif CONFIG_DEVICE_TREE_PARSE + +static inline void map_cpuid_to_node (u32 cpuid,struct dt_device_node *cpu_node) {}
No new uses of u32 please. As to use of fixed-width type, please see ./CODING_STYLE.
Jan
RE: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Hello,
Quoted 11 lines
Quoted 11 lines
xen/include/xen/cpu-topology.h new file +8
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_CPU_TOPOLOGY_H +#define XEN_CPU_TOPOLOGY_H + +#include <xen/types.h> +#include <xen/device_tree.h> +
Quoted 8 lines
xen/include/xen/cpu-topology.h line 13
Quoted 5 lines
xen/include/xen/cpu-topology.h new file +5
-0+struct cpu_topology { +int thread_id; +int core_id; +int cluster_id; +int package_id;Can any of these go negative? If not, "unsigned int" please. Iirc I said the same elsewhere on v1. Please apply such comments throughout the series.
These members can actually be '-1' to represent a missing entry when parsing the Device Tree's 'cpu-map' node.
Since I imported this directly from Linux kernel 7.0 (specifically from include/linux/arch_topology.h and drivers/base/arch_topology.c), I would lean toward keeping them as 'int' to minimize any divergence from the original Linux implementation.
Would that be acceptable?
Quoted 5 lines
xen/include/xen/cpu-topology.h line 21
Quoted 3 lines
xen/include/xen/cpu-topology.h new file +3
-0+ +#ifdef CONFIG_DT_CPU_TOPOLOGY +extern struct cpu_topology cpu_topology[NR_CPUS ];If at all possible, no new
NR_CPUSdimensioned arrays please.
This is also part of the code imported from Linux kernel 7.0, which is used to store unique topology data per CPU.
I kept it as an array to match the original Linux source, but I understand the concern about adding new NR_CPUS dimensioned arrays in Xen. I can refactor it to use Xen's per-CPU infrastructure instead.
Quoted 10 lines
xen/include/xen/cpu-topology.h
Quoted 6 lines
xen/include/xen/cpu-topology.h new file +6
-0+void map_cpuid_to_node (u32 cpuid,struct dt_device_node *cpu_node); +void dt_init_cpu_topology (void ); + +#elif CONFIG_DEVICE_TREE_PARSE + +static inline void map_cpuid_to_node(u32 cpuid, struct dt_device_node
*cpu_node) {}No new uses of u32 please. As to use of fixed-width type, please see ./CODING_STYLE.
Ok, I will use unsigned int instead.
Thank you,
Hirokazu Takahashi.
Re: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Quoted 20 lines · Hirokazu Takahashi
Quoted 11 lines
Quoted 11 lines
xen/include/xen/cpu-topology.h new file +8
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef XEN_CPU_TOPOLOGY_H +#define XEN_CPU_TOPOLOGY_H + +#include <xen/types.h> +#include <xen/device_tree.h> +Quoted 8 lines
xen/include/xen/cpu-topology.h line 13
Quoted 5 lines
xen/include/xen/cpu-topology.h new file +5
-0+struct cpu_topology { +int thread_id; +int core_id; +int cluster_id; +int package_id;Can any of these go negative? If not, "unsigned int" please. Iirc I said the same elsewhere on v1. Please apply such comments throughout the series.
Quoted 2 lines
These members can actually be '-1' to represent a missing entry when parsing the Device Tree's 'cpu-map' node.
Yet that sentinel doesn't need to be -1, does it? Any unsigned value greater or equal to NR_CPUS will do, I suppose.
Quoted 3 lines
Since I imported this directly from Linux kernel 7.0 (specifically from
include/linux/arch_topology.handdrivers/base/arch_topology.c), I would lean toward keeping them as 'int' to minimize any divergence from the original Linux implementation.
Linux is quite a bit more lax though with use of (appropriate) types.
Jan
RE: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Hello,
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/cpu-topology.h line 13
Quoted 8 lines
xen/include/xen/cpu-topology.h new file +8
-0+#include <xen/types.h> +#include <xen/device_tree.h> + +struct cpu_topology { +int thread_id; +int core_id; +int cluster_id; +int package_id;Can any of these go negative? If not, "unsigned int" please. Iirc I said the same elsewhere on v1. Please apply such comments throughout the series.
Quoted 6 lines
Quoted 1 line
These members can actually be '-1' to represent a missing entry when
parsing the Device Tree's
Quoted 1 line
'cpu-map' node.
Yet that sentinel doesn't need to be -1, does it? Any unsigned value greater or equal to
NR_CPUSwill do, I suppose.
Ok, I will make then unsigned int.
Quoted 7 lines
Quoted 1 line
Since I imported this directly from Linux kernel 7.0 (specifically from
include/linux/arch_topology.hQuoted 1 line
and
drivers/base/arch_topology.c), I would lean toward keeping them as 'int'to minimize
Quoted 1 line
any divergence from the original Linux implementation.
Linux is quite a bit more lax though with use of (appropriate) types.
I agree with you at this point.
Thank you,
Hirokazu Takahashi.
RE: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
In reply to Hirokazu TakahashiHello,
Quoted 10 lines
Quoted 5 lines
xen/include/xen/cpu-topology.h line 21
Quoted 3 lines
xen/include/xen/cpu-topology.h new file +3
-0+ +#ifdef CONFIG_DT_CPU_TOPOLOGY +extern struct cpu_topology cpu_topology[NR_CPUS ];If at all possible, no new
NR_CPUSdimensioned arrays please.This is also part of the code imported from Linux kernel 7.0, which is used to store
unique topology data per CPU.
Quoted 5 lines
I kept it as an array to match the original Linux source, but I understand the concern
about adding newNR_CPUSdimensioned arrays in Xen. I can refactor it to use Xen's
per-CPU infrastructure instead.
Just a quick follow-up to my previous email:
While I was looking into moving the topology data to a per-CPU variable, I remembered the ongoing effort by the team working on CPU hotplug.
This introduces a dilemma: during the early boot phase when we parse the Device Tree topology, the per-CPU areas for CPUs that are not yet active (or yet to be hotplugged) have not been allocated yet. Therefore, we wouldn't have a place to record the topology information for those inactive CPUs at boot time.
Should we have the hotplug team parse the Device Tree topology information on-demand when a CPU is hot-plugged?
Currently, the functions used to read the topology from the Device Tree are marked with '__init'. Removing '__init' to keep these functions resident in memory feels like a waste of memory.
What do you think would be the best approach here?
Thank you,
Hirokazu Takahashi.
Re: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Quoted 29 lines · Hirokazu Takahashi
Hello,
Quoted 10 lines
Quoted 5 lines
xen/include/xen/cpu-topology.h line 21
Quoted 3 lines
xen/include/xen/cpu-topology.h new file +3
-0+ +#ifdef CONFIG_DT_CPU_TOPOLOGY +extern struct cpu_topology cpu_topology[NR_CPUS ];If at all possible, no new
NR_CPUSdimensioned arrays please.This is also part of the code imported from Linux kernel 7.0, which is used to store
unique topology data per CPU.Quoted 5 lines
I kept it as an array to match the original Linux source, but I understand the concern
about adding newNR_CPUSdimensioned arrays in Xen. I can refactor it to use Xen's
per-CPU infrastructure instead.Just a quick follow-up to my previous email:
While I was looking into moving the topology data to a per-CPU variable, I remembered the ongoing effort by the team working on CPU hotplug.
This introduces a dilemma: during the early boot phase when we parse the Device Tree topology, the per-CPU areas for CPUs that are not yet active (or yet to be hotplugged) have not been allocated yet. Therefore, we wouldn't have a place to record the topology information for those inactive CPUs at boot time.
Quoted 6 lines
Should we have the hotplug team parse the Device Tree topology information on-demand when a CPU is hot-plugged?
Currently, the functions used to read the topology from the Device Tree are marked with '
__init'. Removing '__init' to keep these functions resident in memory feels like a waste of memory.
Indeed.
Quoted 1 line
What do you think would be the best approach here?
Can you know early enough how many CPUs there are going to be? If so, allocate the array just at the size needed. Next best option may be to have a NR_CPUS-dimensioned array in .init.data, for the used part then to be moved to a dynamically allocated, generally much smaller one.
Jan
RE: [PATCH v2 07/24] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
Hello,
Quoted 34 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/include/xen/cpu-topology.h line 21
Quoted 2 lines
xen/include/xen/cpu-topology.h new file +2
-0+#ifdef CONFIG_DT_CPU_TOPOLOGY +extern struct cpu_topology cpu_topology[NR_CPUS ];If at all possible, no new
NR_CPUSdimensioned arrays please.Quoted 7 lines
Quoted 7 lines
This is also part of the code imported from Linux kernel 7.0, which is used to store
unique topology data per CPU.I kept it as an array to match the original Linux source, but I understand the concern
about adding newNR_CPUSdimensioned arrays in Xen. I can refactor it touse
Quoted 14 lines
Quoted 2 lines
Xen's
per-CPU infrastructure instead.Just a quick follow-up to my previous email:
While I was looking into moving the topology data to a per-CPU variable, I remembered the ongoing effort by the team working on CPU hotplug.
This introduces a dilemma: during the early boot phase when we parse the Device Tree topology, the per-CPU areas for CPUs that are not yet active (or yet to be hotplugged) have not been allocated yet. Therefore, we wouldn't have a place to record the topology information for those inactive CPUs at boot time.
Quoted 6 lines
Should we have the hotplug team parse the Device Tree topology information on-demand when a CPU is hot-plugged?
Currently, the functions used to read the topology from the Device Tree are marked with '
__init'. Removing '__init' to keep these functions resident in memory feels like a waste of memory.
Quoted 8 lines
Indeed.
Quoted 1 line
What do you think would be the best approach here?
Can you know early enough how many CPUs there are going to be? If so, allocate the array just at the size needed. Next best option may be to have a NR_CPUS-dimensioned array in .init.data, for the used part then to be moved to a dynamically allocated, generally much smaller one.
Okay, I can use num_possible_cpus() for the size of the array.
Thank you,
Hirokazu Takahashi.
PATCH v2 8/24 xen/sched: Link CPU topology to scheduler and display via xl info
In reply to Hirokazu TakahashiMake CPU topology information available to the Xen scheduler. Additionally, ensure that this topology information is displayed when executing the 'xl info -n' command.
--- xen/arch/arm/include/asm/processor.h | 4 -- xen/arch/arm/smpboot.c | 10 +++-- xen/common/device-tree/cpu-topology.c | 54 +++++++++++++++++++++++++++ xen/common/sched/credit2.c | 3 ++ xen/common/sysctl.c | 1 + xen/include/xen/cpu-topology.h | 11 ++++++ 6 files changed, 76 insertions(+), 7 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -4
@@ -591,10 +591,6 @@ void show_stack(const struct cpu_user_regs *regs);#define cpu_relax () barrier()/* Could yield? */ -/* All a bit UP for the moment */ -#define cpu_to_core (_cpu) (0) -#define cpu_to_socket (_cpu) (0) -struct vcpu ;void vcpu_regs_hyp_to_user (const struct vcpu *vcpu,struct vcpu_guest_core_regs *regs);
xen/arch/arm/smpboot.c +7 -3
@@ -93,13 +93,17 @@ static int setup_cpu_sibling_map(int cpu) !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) ) return -ENOMEM; +#ifdef CONFIG_DT_CPU_TOPOLOGY +cpumask_copy (per_cpu (cpu_sibling_mask, cpu), &cpu_topology[cpu].thread_sibling); +cpumask_copy (per_cpu (cpu_core_mask, cpu), &cpu_topology[cpu].core_sibling); +#else /* CONFIG_DT_CPU_TOPOLOGY */ /* -* Currently we assume there is no multithread and NUMA, so -* a CPU is a sibling with itself, and the all possible CPUs -* are supposed to belong to the same socket (NUMA node). +* If CONFIG_DT_CPU_TOPOLOGY is disabled, it is assumed that +* all CPUs reside in the same socket and that SMT is not used. */ cpumask_set_cpu (cpu,per_cpu (cpu_sibling_mask, cpu));cpumask_copy (per_cpu (cpu_core_mask, cpu), &cpu_possible_map); +#endif /* CONFIG_DT_CPU_TOPOLOGY */ return 0 ; }
xen/common/device-tree/cpu-topology.c +54 -0
64 lines not on this page · raw message
xen/common/sched/credit2.c +3 -0
@@ -19,6 +19,7 @@#include <xen/softirq.h> #include <xen/time.h> #include <xen/trace.h> +#include <xen/cpu-topology.h> #include <asm/div64.h>
@@ -37,6 +38,8 @@ static unsigned int cpu_nr_siblings(unsigned int cpu) {#ifdef CONFIG_X86 return cpu_data[cpu].x86_num_siblings; +#elif CONFIG_DT_CPU_TOPOLOGY +return cpu_topology[cpu].num_siblings;#else return 1 ;#endif
xen/common/sysctl.c +1 -0
@@ -28,6 +28,7 @@#include <xen/pmstat.h> #include <xen/livepatch.h> #include <xen/coverage.h> +#include <xen/cpu-topology.h> long do_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t) u_sysctl) {
xen/include/xen/cpu-topology.h +11 -0
@@ -14,6 +14,9 @@ struct cpu_topology {cpumask_t thread_sibling;cpumask_t core_sibling;cpumask_t cluster_sibling; +unsigned int phys_core_id; +unsigned int phys_socket_id; +unsigned int num_siblings; };
@@ -23,11 +26,19 @@ extern struct cpu_topology cpu_topology[NR_CPUS];void map_cpuid_to_node (u32 cpuid,struct dt_device_node *cpu_node);void dt_init_cpu_topology (void ); +#define cpu_to_core (_cpu) (cpu_topology[_cpu].phys_core_id) +#define cpu_to_socket (_cpu) (cpu_topology[_cpu].phys_socket_id) +#define cpu_nr_siblings (_cpu) (cpu_topology[_cpu].num_siblings) +#elif CONFIG_DEVICE_TREE_PARSE static inline void map_cpuid_to_node (u32 cpuid,struct dt_device_node *cpu_node) {}static inline void dt_init_cpu_topology (void ) {} +#define cpu_to_core (_cpu) (0) +#define cpu_to_socket (_cpu) (0) +#define cpu_nr_siblings (_cpu) (1) +#endif /* CONFIG_DEVICE_TREE_PARSE */ #endif /* XEN_CPU_TOPOLOGY_H */
Signature · 1 line
2.43.0
PATCH v2 9/24 xen/sched: Make cpu_nr_siblings() architecture-specific
In reply to Hirokazu TakahashiMake cpu_nr_siblings() an architecture-specific function. This patch provides the implementation for x86 and a common version for Device Tree-based architectures.
--- xen/arch/x86/include/asm/processor.h | 1 + xen/common/sched/credit2.c | 23 +++++------------------ 2 files changed, 6 insertions(+), 18 deletions(-)
xen/arch/x86/include/asm/processor.h +1 -0
@@ -106,6 +106,7 @@ extern void intel_init_arat(void);#define cpu_to_core (_cpu) (cpu_data[_cpu].cpu_core_id)#define cpu_to_socket (_cpu) (cpu_data[_cpu].phys_proc_id) +#define cpu_nr_siblings (_cpu) (cpu_data[_cpu].x86_num_siblings)unsigned int apicid_to_socket (unsigned int apicid);
xen/common/sched/credit2.c +5 -18
@@ -29,22 +29,6 @@/* #define d2printk printk */ #define d2printk(x...) -/* -* TODO: Abstract this properly, and figure out what Credit2 wants to do with -* the fact that x86_num_siblings doesn't even have the same meaning -* between x86 vendors. -*/ -static unsigned int cpu_nr_siblings (unsigned int cpu) -{ -#ifdef CONFIG_X86 -return cpu_data[cpu].x86_num_siblings; -#elif CONFIG_DT_CPU_TOPOLOGY -return cpu_topology[cpu].num_siblings; -#else -return 1 ; -#endif -} -/* * Credit2 tracing events ("only" 512 available!). Check * include/public/trace.h for more details.
@@ -884,8 +868,11 @@ cpu_runqueue_match(const struct csched2_runqueue_data *rqd, unsigned int cpu)* Additional checks, to avoid separating siblings in different runqueues. * This deals with both Intel's HTs and AMD's CUs. An arch that does not have * any similar concept will just have cpu_nr_siblings() always return 1, and -* setup the cpu_sibling_mask-s acordingly (as currently does ARM), and things -* will just work as well. +* setup the cpu_sibling_mask-s acordingly, and things will just work as well. +* +* TODO: Abstract cpu_nr_siblings properly, and figure out what Credit2 wants +* to do with the fact that x86_num_siblings doesn't even have the same +* meaning between x86 vendors. */ static bool cpu_runqueue_siblings_match(const struct csched2_runqueue_data *rqd,
Signature · 1 line
2.43.0
PATCH v2 10/24 xen/common: Allow building ARM32 Xen with CONFIG_NUMA
In reply to Hirokazu TakahashiAllow ARM32 Xen to be built with NUMA configurations.
--- xen/common/numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/numa.c +1 -1
@@ -431,7 +431,7 @@ static int __init allocate_cachealigned_memnodemap(void)if ( !memnodemap )panic ("Unable to map the NUMA node map. Retry with numa=off" ); size <<=PAGE_SHIFT ; -printk (KERN_DEBUG "NUMA: Allocated memnodemap from %lx - %lx\n" , +printk (KERN_DEBUG "NUMA: Allocated memnodemap from %" PRIpaddr" - %" PRIpaddr"\n" ,mfn_to_maddr (mfn),mfn_to_maddr (mfn) + size); memnodemapsize = size /sizeof (*memnodemap);
Signature · 1 line
2.43.0
PATCH v2 11/24 tools/libxl: Fix vNUMA memory allocation algorithm to support ARM
In reply to Hirokazu TakahashiWhen creating a domU with vNUMA enabled, the memory allocation algorithm was dependent on x86. Fix this logic to make it usable on ARM as well.
--- tools/libs/light/libxl_vnuma.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/libs/light/libxl_vnuma.c +11 -2
@@ -259,8 +259,12 @@ int libxl__vnuma_build_vmemrange_hvm(libxl__gc *gc,xen_vmemrange_t *vmemranges;int rc; -/* Derive vmemranges from vnode size and memory hole. -* +/* Derive vmemranges from vnode size and memory hole. */ +#if defined (__arm__) || defined(__aarch64__) + hole_start =GUEST_RAM0_BASE +GUEST_RAM0_SIZE ; + hole_end =GUEST_RAM1_BASE ; +#else +/* * Guest physical address space layout: * [0, hole_start) [hole_start, hole_end) [hole_end, highmem_end) */
@@ -268,10 +272,15 @@ int libxl__vnuma_build_vmemrange_hvm(libxl__gc *gc, dom->lowmem_end : dom->mmio_start; hole_end = (dom->mmio_start + dom->mmio_size) > (1ULL <<32 ) ? (dom->mmio_start + dom->mmio_size) : (1ULL <<32 ); +#endif assert (state->vmemranges ==NULL ); +#if defined (__arm__) || defined(__aarch64__) + next =GUEST_RAM0_BASE ; +#else next =0 ; +#endif nr_vmemrange =0 ; vmemranges =NULL ;for (nid =0 ; nid < b_info->num_vnuma_nodes; nid++) {
Signature · 1 line
2.43.0
PATCH v2 12/24 tools/libs/guest: Allocate vNUMA memory from associated pNUMA nodes
In reply to Hirokazu TakahashiAllocate memory for domU vNUMA nodes from the physical NUMA nodes specified in the domU configuration file.
--- tools/libs/guest/xg_dom_arm.c | 62 +++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 13 deletions(-)
tools/libs/guest/xg_dom_arm.c +49 -13
@@ -236,7 +236,7 @@ static int set_mode(xc_interface *xch, uint32_t domid, const char *guest_type)*/ static int populate_one_size (struct xc_dom_image *dom,int pfn_shift,xen_pfn_t base_pfn,xen_pfn_t *nr_pfns, -xen_pfn_t *extents) +xen_pfn_t *extents,unsigned int memflags) {/* The mask for this level */ const uint64_t mask = ((uint64_t )1 <<(pfn_shift))-1 ;
@@ -274,7 +274,7 @@ static int populate_one_size(struct xc_dom_image *dom, int pfn_shift, extents[i] = base_pfn + (i<<pfn_shift); nr =xc_domain_populate_physmap (dom->xch, dom->guest_domid, count, - pfn_shift,0 , extents); + pfn_shift, memflags, extents);if ( nr <=0 )return nr;DOMPRINTF ("%s: populated %#x/%#x entries with shift %d" , __FUNCTION__, nr, count, pfn_shift);
@@ -285,10 +285,12 @@ static int populate_one_size(struct xc_dom_image *dom, int pfn_shift, }static int populate_guest_memory (struct xc_dom_image *dom, -xen_pfn_t base_pfn,xen_pfn_t nr_pfns) +xen_pfn_t base_pfn,xen_pfn_t nr_pfns, +unsigned int nid) {int rc =0 ;xen_pfn_t allocsz, pfn, *extents; +unsigned int memflags =0U ; extents =calloc (1024 *1024 ,sizeof (xen_pfn_t));if ( extents ==NULL )
@@ -303,6 +305,16 @@ static int populate_guest_memory(struct xc_dom_image *dom, (uint64_t )(base_pfn + nr_pfns) <<XC_PAGE_SHIFT , (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT)); +if ( dom->nr_vmemranges >0 ) + { + memflags =XENMEMF_exact_node (dom->vnode_to_pnode[nid]); + +DOMPRINTF ("%s: on pNODE%u for vNODE%u" , + __FUNCTION__, + dom->vnode_to_pnode[nid], + nid); + } +for ( pfn =0 ; pfn < nr_pfns; pfn += allocsz ) { allocsz =min_t (int,1024 *1024 , nr_pfns - pfn);
@@ -312,7 +324,7 @@ static int populate_guest_memory(struct xc_dom_image *dom, { allocsz =1 ; rc =populate_one_size (dom,PFN_4K_SHIFT , - base_pfn + pfn, &allocsz, extents); + base_pfn + pfn, &allocsz, extents, memflags);if (rc <0 )break ;if (rc >0 )continue ;/* Failed to allocate a single page? */
@@ -321,22 +333,22 @@ static int populate_guest_memory(struct xc_dom_image *dom,#endif rc =populate_one_size (dom,PFN_512G_SHIFT , - base_pfn + pfn, &allocsz, extents); + base_pfn + pfn, &allocsz, extents, memflags);if ( rc <0 )break ;if ( rc >0 )continue ; rc =populate_one_size (dom,PFN_1G_SHIFT , - base_pfn + pfn, &allocsz, extents); + base_pfn + pfn, &allocsz, extents, memflags);if ( rc <0 )break ;if ( rc >0 )continue ; rc =populate_one_size (dom,PFN_2M_SHIFT , - base_pfn + pfn, &allocsz, extents); + base_pfn + pfn, &allocsz, extents, memflags);if ( rc <0 )break ;if ( rc >0 )continue ; rc =populate_one_size (dom,PFN_4K_SHIFT , - base_pfn + pfn, &allocsz, extents); + base_pfn + pfn, &allocsz, extents, memflags);if ( rc <0 )break ;if ( rc ==0 ) {
@@ -415,12 +427,36 @@ static int meminit(struct xc_dom_image *dom)assert (ramsize ==0 );/* Too much RAM is rejected above */ /* setup initial p2m and allocate guest memory */ -for ( i =0 ; i <GUEST_RAM_BANKS && dom->rambank_size[i]; i++ ) +if ( dom->nr_vmemranges >0 ) { -if ((rc =populate_guest_memory (dom, - bankbase[i] >>XC_PAGE_SHIFT , - dom->rambank_size[i]))) -return rc; + ramsize = (uint64_t )dom->total_pages <<XC_PAGE_SHIFT ; + +for ( i =0 ; i < dom->nr_vmemranges; i++ ) + { + ramsize -= dom->vmemranges[i].end - dom->vmemranges[i].start; + } + +assert (ramsize ==0 ); + +for ( i =0 ; i < dom->nr_vmemranges; i++ ) + { +if ((rc =populate_guest_memory (dom, + dom->vmemranges[i].start >>XC_PAGE_SHIFT , + (dom->vmemranges[i].end - dom->vmemranges[i].start) >>XC_PAGE_SHIFT , + dom->vmemranges[i].nid))) +return rc; + } + } +else + { +for ( i =0 ; i <GUEST_RAM_BANKS && dom->rambank_size[i]; i++ ) + { +if ((rc =populate_guest_memory (dom, + bankbase[i] >>XC_PAGE_SHIFT , + dom->rambank_size[i], +0U ))) +return rc; + } }/*
Signature · 1 line
2.43.0
PATCH v2 13/24 tools/libxl: Add 'numa-node-id' property to DomU memory nodes
In reply to Hirokazu TakahashiAdd the 'numa-node-id' property to the memory nodes in the Device Tree passed to DomU. The NUMA node to which each memory node belongs is determined based on the virtual NUMA configuration specified in the xl domain configuration file.
--- tools/libs/light/libxl_arm.c | 50 +++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 9 deletions(-)
tools/libs/light/libxl_arm.c +41 -9
@@ -670,25 +670,53 @@ static int make_optee_node(libxl__gc *gc, void *fdt) }static int make_memory_nodes (libxl__gc *gc,void *fdt, +const libxl_domain_build_info *b_info,const struct xc_dom_image *dom) {int res, i;const char *name;const uint64_t bankbase[] =GUEST_RAM_BANK_BASES ; -for (i =0 ; i <GUEST_RAM_BANKS ; i++) { - name =GCSPRINTF ("memory@%" PRIx64, bankbase[i]); +if (dom->nr_vmemranges ==0 ) { +for (i =0 ; i <GUEST_RAM_BANKS ; i++) { + name =GCSPRINTF ("memory@%" PRIx64, bankbase[i]); -LOG (DEBUG ,"Creating placeholder node /%s" , name); +LOG (DEBUG ,"Creating placeholder node /%s" , name); + res =fdt_begin_node (fdt, name); +if (res)return res; + + res =fdt_property_string (fdt,"device_type" ,"memory" ); +if (res)return res; + + res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , +1 ,0 ,0 ); +if (res)return res; + + res =fdt_end_node (fdt); +if (res)return res; + } + +return 0 ; + } + +for (i =0 ; i < dom->nr_vmemranges; i++) { +uint64_t start_addr = dom->vmemranges[i].start; +uint64_t size = dom->vmemranges[i].end - start_addr; +uint32_t nid = dom->vmemranges[i].nid; +uint64_t regs[2 ] = {cpu_to_fdt64 (start_addr),cpu_to_fdt64 (size) }; + + name =GCSPRINTF ("memory@%" PRIx64, start_addr); res =fdt_begin_node (fdt, name);if (res)return res; res =fdt_property_string (fdt,"device_type" ,"memory" );if (res)return res; - res =fdt_property_regs (gc, fdt,GUEST_ROOT_ADDRESS_CELLS ,GUEST_ROOT_SIZE_CELLS , -1 ,0 ,0 ); + res =fdt_property (fdt,"reg" , regs,sizeof (uint64_t ) *2 ); +if (res)return res; + + res =fdt_property_u32 (fdt,"numa-node-id" , nid);if (res)return res; res =fdt_end_node (fdt);
@@ -1365,7 +1393,7 @@ next_resize:FDT (make_cpus_node (gc, fdt, info->max_vcpus, ainfo) );FDT (make_psci_node (gc, fdt) ); -FDT (make_memory_nodes (gc, fdt, dom) ); +FDT (make_memory_nodes (gc, fdt, info, dom) );switch (info->arch_arm.gic_version) {case LIBXL_GIC_VERSION_V2 :
@@ -1716,10 +1744,14 @@ int libxl__arch_domain_finalise_hw_description(libxl__gc *gc,if (res)return res; -for (i =0 ; i <GUEST_RAM_BANKS ; i++) { -const uint64_t size = (uint64_t )dom->rambank_size[i] <<XC_PAGE_SHIFT ; +if (d_config->b_info.num_vnuma_nodes ==0 ) { +for (i =0 ; i <GUEST_RAM_BANKS ; i++) { +const uint64_t size = (uint64_t )dom->rambank_size[i] <<XC_PAGE_SHIFT ; -finalise_one_node (gc, fdt,"/memory" , bankbase[i], size); +finalise_one_node (gc, fdt,"/memory" , bankbase[i], size); + } + }else { +LOG (DEBUG ,"vNUMA enabled: skipping memory node finalisation as nodes are already populated" ); }if (dom->acpi_modules[0 ].data) {
Signature · 1 line
2.43.0
PATCH v2 14/24 tools/libxl: Add 'numa-node-id' property to DomU CPU nodes
In reply to Hirokazu TakahashiAdd the 'numa-node-id' property to the cpu nodes in the Device Tree passed to DomU. This information is retrieved from the virtual NUMA configuration in the xl domain configuration file.
--- tools/libs/light/libxl_arm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
tools/libs/light/libxl_arm.c +15 -3
@@ -571,7 +571,8 @@ static int make_chosen_node(libxl__gc *gc, void *fdt, bool ramdisk,return 0 ; } -static int make_cpus_node (libxl__gc *gc,void *fdt,int nr_cpus, +static int make_cpus_node (libxl__gc *gc,void *fdt, +const libxl_domain_build_info *b_info,const struct arch_info *ainfo) {int res, i;
@@ -586,7 +587,7 @@ static int make_cpus_node(libxl__gc *gc, void *fdt, int nr_cpus, res =fdt_property_cell (fdt,"#size-cells" ,0 );if (res)return res; -for (i =0 ; i < nr_cpus; i++) { +for (i =0 ; i < b_info->max_vcpus; i++) {const char *name; mpidr_aff =libxl__compute_mpdir (i);
@@ -607,6 +608,17 @@ static int make_cpus_node(libxl__gc *gc, void *fdt, int nr_cpus, res =fdt_property_regs (gc, fdt,1 ,0 ,1 , mpidr_aff);if (res)return res; +if (b_info->num_vnuma_nodes) { +unsigned int vnode; +for (vnode =0 ; vnode < b_info->num_vnuma_nodes; vnode++) { +if (libxl_bitmap_test (&b_info->vnuma_nodes[vnode].vcpus, i)) { + res =fdt_property_u32 (fdt,"numa-node-id" , vnode); +if (res)return res; +break ; + } + } + } + res =fdt_end_node (fdt);if (res)return res; }
@@ -1390,7 +1402,7 @@ next_resize:FDT (make_root_properties (gc, vers, fdt) );FDT (make_chosen_node (gc, fdt, !!dom->modules[0 ].blob, state, info) ); -FDT (make_cpus_node (gc, fdt, info->max_vcpus, ainfo) ); +FDT (make_cpus_node (gc, fdt, info, ainfo) );FDT (make_psci_node (gc, fdt) );FDT (make_memory_nodes (gc, fdt, info, dom) );
Signature · 1 line
2.43.0
PATCH v2 15/24 tools/libxl: Create 'distance-map' node in DomU Device Tree
In reply to Hirokazu TakahashiCreate the 'distance-map' node in the Device Tree passed to DomU. This information is retrieved from the virtual NUMA configuration in the xl domain configuration file.
--- tools/libs/light/libxl_arm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
tools/libs/light/libxl_arm.c +35 -0
@@ -738,6 +738,39 @@ static int make_memory_nodes(libxl__gc *gc, void *fdt,return 0 ; } +static int make_numa_distance_map (libxl__gc *gc,void *fdt, +const libxl_domain_build_info *b_info) +{ +int i, j; +uint32_t *matrix; +int nr_nodes = b_info->num_vnuma_nodes; +int idx =0 ; +int res; + +if (nr_nodes ==0 )return 0 ; + + res =fdt_begin_node (fdt,"distance-map" ); +if (res)return res; + + res =fdt_property_string (fdt,"compatible" ,"numa-distance-map-v1" ); +if (res)return res; + + matrix =libxl__malloc (gc,sizeof (uint32_t ) * nr_nodes * nr_nodes *3 ); + +for (i =0 ; i < nr_nodes; i++) { +for (j =0 ; j < nr_nodes; j++) { + matrix[idx++] =cpu_to_fdt32 (i); + matrix[idx++] =cpu_to_fdt32 (j); + matrix[idx++] =cpu_to_fdt32 (b_info->vnuma_nodes[i].distances[j]); + } + } + + res =fdt_property (fdt,"distance-matrix" , matrix,sizeof (uint32_t ) * idx); +if (res)return res; + +return fdt_end_node (fdt); +} +static int make_gicv2_node (libxl__gc *gc,void *fdt,uint64_t gicd_base,uint64_t gicd_size,uint64_t gicc_base,uint64_t gicc_size)
@@ -1407,6 +1440,8 @@ next_resize:FDT (make_memory_nodes (gc, fdt, info, dom) ); +FDT (make_numa_distance_map (gc, fdt, info) ); +switch (info->arch_arm.gic_version) {case LIBXL_GIC_VERSION_V2 : FDT( make_gicv2_node(gc, fdt,
Signature · 1 line
2.43.0
PATCH v2 16/24 xen/arm: Introduce dom0_nodes boot command option
In reply to Hirokazu TakahashiAllow ARM Xen to accept the 'dom0_nodes' command line option. The syntax and format of the parameters are identical to the x86 implementation. The logic that actually functions based on this argument will be provided in a follow-up patch.
--- xen/arch/arm/domain_build.c | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
xen/arch/arm/domain_build.c +43 -0
@@ -37,6 +37,7 @@#include <asm/cpufeature.h> #include <asm/domain_build.h> #include <xen/event.h> +#include <xen/ctype.h> #include <xen/irq.h> #include <xen/grant_table.h>
@@ -66,6 +67,48 @@ static int __init parse_dom0_mem(const char *s) }custom_param ("dom0_mem" , parse_dom0_mem); +static nodemask_t __initdata dom0_nodes; +bool __initdata dom0_affinity_relaxed; + +#ifdef CONFIG_NUMA + +static int __init cf_check parse_dom0_nodes(const char *s) +{ +const char *ss; +int rc =0 ; +unsigned int nid; + +do { + ss =strchr (s,',' ); +if ( !ss ) + ss =strchr (s,'\0' ); + +if (isdigit (*s) ) + { +const char *endp; + +if ( (nid =simple_strtoul (s, &endp,0 ), endp != ss) ) + rc = -EINVAL ; +else if ( nid >=MAX_NUMNODES ) + rc = -E2BIG ; +else +node_set (nid, dom0_nodes); + } +else if ( !cmdline_strcmp (s,"relaxed" ) ) + dom0_affinity_relaxed = true; +else if ( !cmdline_strcmp (s,"strict" ) ) + dom0_affinity_relaxed = false; +else + rc = -EINVAL ; + + s = ss +1 ; + }while ( *ss ); + +return rc; +} +custom_param ("dom0_nodes" , parse_dom0_nodes); +#endif /* CONFIG_NUMA */ +int __init parse_arch_dom0_param (const char *s,const char *e) {long long val;
Signature · 1 line
2.43.0
PATCH v2 17/24 xen/arm: Set Domain-0 node affinity from dom0_nodes option
In reply to Hirokazu TakahashiSet Domain-0's node affinity to run on the NUMA nodes specified via the 'dom0_nodes' boot command line option. If the option is omitted, the node affinity is configured to use all available NUMA nodes managed by Xen. When Xen is built with CONFIG_NUMA disabled, the node affinity falls back to using only NUMA node 0.
--- xen/arch/arm/domain_build.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/arch/arm/domain_build.c +7 -0
@@ -2027,6 +2027,13 @@ void __init create_dom0(void)if ( llc_coloring_enabled && (rc =dom0_set_llc_colors (dom0)) )panic ("Error initializing LLC coloring for %pd (rc = %d)\n" , dom0, rc); +nodes_and (dom0_nodes, dom0_nodes, node_online_map); +if (nodes_empty (dom0_nodes) ) + dom0_nodes = node_online_map; + + dom0->node_affinity = dom0_nodes; + dom0->auto_node_affinity = false; +if (vcpu_create (dom0,0 ) ==NULL )panic ("Error creating %pdv0\n" , dom0);
Signature · 1 line
2.43.0
PATCH v2 18/24 xen/arm: Reflect physical NUMA node IDs in Dom0 memory DT nodes
In reply to Hirokazu TakahashiExtract the physical NUMA node ID for each memory bank allocated for Dom0 and apply it to the corresponding memory node in the Dom0 Device Tree. This implementation maps the physical NUMA node IDs directly as Dom0's virtual NUMA node IDs.
--- xen/arch/arm/domain_build.c | 22 ++++++- xen/common/device-tree/domain-build.c | 88 +++++++++++++-------------- 2 files changed, 63 insertions(+), 47 deletions(-)
xen/arch/arm/domain_build.c +20 -2
@@ -187,11 +187,26 @@ static bool __init insert_11_bank(struct domain *d,int res;mfn_t smfn;paddr_t start, size; +nodeid_t node =0U ; smfn =page_to_mfn (pg); start =mfn_to_maddr (smfn); size =pfn_to_paddr (1UL << order); +/* This code is temporal */ + { +struct membanks *mem =bootinfo_get_mem (); +for ( i =0 ; i < mem->nr_banks; i++ ) + { +if ( start >= mem->bank[i].start && + start < (mem->bank[i].start + mem->bank[i].size) ) + { + node =get_numa_nodeid (&mem->bank[i]); +break ; + } + } + } + D11PRINT("Allocated %#"PRIpaddr"-%#"PRIpaddr" (%ldMB/%ldMB, order %d)\n", start, start + size, 1UL << (order + PAGE_SHIFT - 20),
@@ -217,6 +232,7 @@ static bool __init insert_11_bank(struct domain *d, { mem->bank[0 ].start = start; mem->bank[0 ].size = size; +set_numa_nodeid (&mem->bank[0 ], node); mem->nr_banks =1 ;return true; }
@@ -226,7 +242,7 @@ static bool __init insert_11_bank(struct domain *d,struct membank *bank = &mem->bank[i];/* If possible merge new memory into the start of the bank */ -if ( bank->start == start+size ) +if ( bank->start == start+size &&get_numa_nodeid (bank) == node ) { bank->start = start; bank->size += size;
@@ -234,7 +250,7 @@ static bool __init insert_11_bank(struct domain *d, }/* If possible merge new memory onto the end of the bank */ -if ( start == bank->start + bank->size ) +if ( start == bank->start + bank->size &&get_numa_nodeid (bank) == node ) { bank->size += size;return true;
@@ -253,6 +269,7 @@ static bool __init insert_11_bank(struct domain *d, mem->nr_banks++; bank->start = start; bank->size = size; +set_numa_nodeid (bank, node);return true; } }
@@ -263,6 +280,7 @@ static bool __init insert_11_bank(struct domain *d, bank->start = start; bank->size = size; +set_numa_nodeid (bank, node); mem->nr_banks++;return true; }
xen/common/device-tree/domain-build.c +43 -45
112 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 19/24 xen/arm: Balance Dom0 vCPU assignment across NUMA nodes
In reply to Hirokazu TakahashiConfigure the assignment of Dom0 vCPUs to NUMA nodes, aiming to balance the compute load across the available nodes.
--- xen/arch/arm/domain_build.c | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
xen/arch/arm/domain_build.c +46 -0
@@ -1225,6 +1225,34 @@ int __init make_psci_node(void *fdt)return res; } +/* +* Map a Dom0 vCPU ID to a target NUMA node ID. +*/ +static nodeid_t __init dom0_vcpu_to_node (const struct domain *d,unsigned int vcpu_id) +{ +nodeid_t nodes[MAX_NUMNODES ]; +unsigned int nr_nodes =0 ; +unsigned int vcpus_per_node; +unsigned int node_idx; +nodeid_t n; + +if (nodes_empty (d->node_affinity) ) +return 0 ; + +for_each_node_mask (n, d->node_affinity) + nodes[nr_nodes++] = n; + +if ( nr_nodes ==0 ) +return 0 ; + + vcpus_per_node = (d->max_vcpus + nr_nodes -1 ) / nr_nodes; + node_idx = vcpu_id / vcpus_per_node; + +ASSERT (node_idx < nr_nodes); + +return nodes[node_idx]; +} +int __init make_cpus_node (const struct domain *d,struct kernel_info *kinfo) {int res;
@@ -1907,6 +1935,24 @@ int __init construct_domain(struct domain *d, struct kernel_info *kinfo)vcpu_switch_to_aarch64_mode (d->vcpu[i]); } +/* +* If Dom0 has specific NUMA node affinity configured, bind each vCPU +* to its designated physical node. +*/ +for ( i =0 ; i < d->max_vcpus; i++ ) + { +struct vcpu *v = d->vcpu[i]; +nodeid_t pnode; +const cpumask_t *nodemask; + +if ( !v )continue ; + + pnode =dom0_vcpu_to_node (d, i); + nodemask = &node_to_cpumask (pnode); + +vcpu_set_hard_affinity (v, nodemask); + } +domain_update_node_affinity (d); v->is_initialised =1 ;
Signature · 1 line
2.43.0
PATCH v2 20/24 xen/arm: Export Dom0 vCPU-to-NUMA node mapping to Device Tree
In reply to Hirokazu TakahashiExport the mapping between Domain-0 vCPUs and their assigned NUMA nodes into the Device Tree generated for Domain-0.
--- xen/arch/arm/domain_build.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/arm/domain_build.c +8 -0
@@ -1373,6 +1373,14 @@ int __init make_cpus_node(const struct domain *d, struct kernel_info *kinfo)return res; } +if (IS_ENABLED (CONFIG_NUMA ) ) + { +nodeid_t target_node =dom0_vcpu_to_node (d, cpu); + res =fdt_property_u32 (fdt,"numa-node-id" , target_node); +if ( res ) +return res; + } + res =fdt_end_node (fdt);if ( res )return res;
Signature · 1 line
2.43.0
PATCH v2 21/24 xen/arm: Generate distance-map node for Dom0 Device Tree
In reply to Hirokazu TakahashiGenerate the 'distance-map' node within the Domain-0 Device Tree. This ensures that distances are populated only for the specific NUMA nodes assigned to Domain-0.
--- xen/arch/arm/domain_build.c | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
xen/arch/arm/domain_build.c +50 -0
@@ -718,6 +718,51 @@ static int __init fdt_property_interrupts(const struct kernel_info *kinfo,return res; } +#ifdef CONFIG_NUMA +static int __init make_distance_map_node (const struct domain *d,void *fdt) +{ +nodeid_t from, to; +unsigned int count =0 ; +int res; + +static uint32_t __initdata matrix[MAX_NUMNODES *MAX_NUMNODES *3 ]; + +if (nodes_weight (d->node_affinity) <=1 ) +return 0 ; + +for_each_node_mask (from, d->node_affinity) + { +for_each_node_mask (to, d->node_affinity) + { + matrix[count *3 +0 ] =cpu_to_fdt32 (from); + matrix[count *3 +1 ] =cpu_to_fdt32 (to); + matrix[count *3 +2 ] =cpu_to_fdt32 (__node_distance (from, to)); + count++; + } + } + + res =fdt_begin_node (fdt,"distance-map" ); +if ( res ) +return res; + + res =fdt_property_string (fdt,"compatible" ,"numa-distance-map-v1" ); +if ( res ) +return res; + + res =fdt_property (fdt,"distance-matrix" , matrix, count *3 *sizeof (uint32_t )); +if ( res ) +return res; + + res =fdt_end_node (fdt); +if ( res ) +return res; + +return 0 ; +} +#else /* CONFIG_NUMA */ +#define make_distance_map_node (d, fdt) (0) +#endif /* CONFIG_NUMA */ +int __init add_ext_regions (unsigned long s_gfn,unsigned long e_gfn,void *data) {
@@ -1568,6 +1613,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,DT_MATCH_TYPE ("memory" ),/* The memory mapped timer is not supported by Xen. */ DT_MATCH_COMPATIBLE ("arm,armv7-timer-mem" ), + DT_MATCH_COMPATIBLE("numa-distance-map-v1"), { /* sentinel */ }, }; static const struct dt_device_match timer_matches[] __initconst =
@@ -1733,6 +1779,10 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,if ( res )return res; + res =make_distance_map_node (d, kinfo->fdt); +if ( res ) +return res; + res =sci_dt_finalize (d, kinfo->fdt);if ( res )return res;
Signature · 1 line
2.43.0
PATCH v2 22/24 xen/arm: Balance Dom0 memory allocation across allowed NUMA nodes
In reply to Hirokazu TakahashiAllocate memory for Domain-0 exclusively from the permitted NUMA nodes. When multiple NUMA nodes are available, distribute the allocation in a balanced manner across each of these nodes.
--- xen/arch/arm/domain_build.c | 276 ++++++++++++++++++++---------------- 1 file changed, 152 insertions(+), 124 deletions(-)
xen/arch/arm/domain_build.c +152 -124
@@ -180,33 +180,19 @@ unsigned int __init dom0_max_vcpus(void)static bool __init insert_11_bank (struct domain *d,struct kernel_info *kinfo,struct page_info *pg, -unsigned int order) +unsigned int order, +nodeid_t node) {struct membanks *mem =kernel_info_get_mem (kinfo);unsigned int i;int res;mfn_t smfn;paddr_t start, size; -nodeid_t node =0U ; smfn =page_to_mfn (pg); start =mfn_to_maddr (smfn); size =pfn_to_paddr (1UL << order); -/* This code is temporal */ - { -struct membanks *mem =bootinfo_get_mem (); -for ( i =0 ; i < mem->nr_banks; i++ ) - { -if ( start >= mem->bank[i].start && - start < (mem->bank[i].start + mem->bank[i].size) ) - { - node =get_numa_nodeid (&mem->bank[i]); -break ; - } - } - } - D11PRINT("Allocated %#"PRIpaddr"-%#"PRIpaddr" (%ldMB/%ldMB, order %d)\n", start, start + size, 1UL << (order + PAGE_SHIFT - 20),
@@ -293,7 +279,13 @@ fail: }/* -* This is all pretty horrible. +* Allocate NUMA-aware memory for Dom0 with 1:1 mapping. +* +* This function distributes the requested Dom0 memory across the allowed +* physical NUMA nodes in a balanced manner. It implements a multi-pass +* scavenging loop to allow nodes to dynamically back up each other if a +* particular node runs out of memory, maintaining a balanced distribution +* while ensuring the maximum amount of requested memory is satisfied. * * Requirements: *
@@ -308,155 +300,190 @@ fail:* below 4GB, so that it can be used by non-LPAE enabled kernels (32-bit). * 4. Some devices assigned to dom0 can only do 32-bit DMA access or * even be more restricted. We want to allocate as much of the RAM -* as we reasonably can that can be accessed from all the devices.. +* as we reasonably can that can be accessed from all the devices. * 5. For 32-bit dom0 the kernel must be located below 4GB. -* 6. We want to have a few largers banks rather than many smaller ones. +* 6. We want to have a few larger banks rather than many smaller ones. * * For the first two requirements we need to make sure that the lowest -* bank is sufficiently large. -* -* For convenience we also sort the banks by physical address. -* -* The memory allocator does not really give us the flexibility to -* meet these requirements directly. So instead of proceed as follows: -* -* We first allocate the largest allocation we can as low as we -* can. This then becomes the first bank. This bank must be at least -* 128MB (or memory size requested for domain if that is smaller). +* bank (Bank 0) is sufficiently large to hold all boot modules. * -* Then we start allocating more memory, trying to allocate the -* largest possible size and trying smaller sizes until we -* successfully allocate something. +* The memory allocator does not really give us the flexibility to meet +* these requirements directly under NUMA topologies. So instead we proceed +* as follows: * -* We then try and insert this memory in to the list of banks. If it -* can be merged into an existing bank then this is trivial. +* We first calculate the total size required for the kernel, ramdisk, and +* DTB to establish a safe minimum size constraint for the first bank (Bank 0). * -* If the new memory is before the first bank (and cannot be merged into it) -* and is at least 128M then we allow it, otherwise we give up. Since the -* allocator prefers to allocate high addresses first and the first bank has -* already been allocated to be as low as possible this likely means we -* wouldn't have been able to allocate much more memory anyway. +* We then enter a multi-pass outer loop that runs until the full memory +* request is met. In each pass, we dynamically calculate the target allocation +* amount for each remaining active node to ensure a balanced distribution. * -* Otherwise we insert a new bank. If we've reached MAX_NR_BANKS then -* we give up. -* -* For 32-bit domain we require that the initial allocation for the -* first bank is part of the low mem. For 64-bit, the first bank is preferred -* to be allocated in the low mem. Then for subsequent allocation, we -* initially allocate memory only from low mem. Once that runs out out -* (as described above) we allow higher allocations and continue until -* that runs out (or we have allocated sufficient dom0 memory). +* For the initial chunk (Bank 0), we try to allocate the largest possible size +* as low as possible, honoring the 32-bit lowmem/DMA constraints. If it fails +* to find lowmem space and the domain is 64-bit, it falls back to highmem +* without violating the minimum size needed for the boot modules. */ static void __init allocate_memory_11 (struct domain *d,struct kernel_info *kinfo) { -const unsigned int min_low_order = -get_order_from_bytes (min_t (paddr_t, kinfo->unassigned_mem,MB (128 ))); +paddr_t todo = kinfo->unassigned_mem; +nodeid_t node; + +const unsigned int max_chunk_order =get_order_from_bytes (MB (128 ));const unsigned int min_order =get_order_from_bytes (MB (4 )); +const unsigned int lowmem_bitsize =arch_get_dma_bitsize (); +unsigned int min_bank0_order; +bool is_bank0 = true; + +const struct boot_module *kernel_mod =boot_module_find_by_kind (BOOTMOD_KERNEL ); +const struct boot_module *ramdisk_mod =boot_module_find_by_kind (BOOTMOD_RAMDISK ); +const struct boot_module *dtb_mod =boot_module_find_by_kind (BOOTMOD_FDT ); +const struct boot_module *xsm_policy_mod =boot_module_find_by_kind (BOOTMOD_XSM_POLICY ); +paddr_t required_size =0 ; + +nodemask_t exhausted_nodes; +nodemask_t valid_nodes; +struct membanks *mem =kernel_info_get_mem (kinfo); -struct page_info *pg; -unsigned int order =get_allocation_size (kinfo->unassigned_mem);unsigned int i; -bool lowmem = true; -unsigned int lowmem_bitsize =min (32U ,arch_get_dma_bitsize ()); -unsigned int bits; -/* * TODO: Implement memory bank allocation when DOM0 is not direct * mapped */ BUG_ON (!is_domain_direct_mapped (d)); -printk ("Allocating 1:1 mappings totalling %ldMB for %pd:\n" , +printk ("Allocating 1:1 mappings totalling %ldMB for dom0:\n" ,/* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long )(kinfo->unassigned_mem >>20 ), d); + (unsigned long )(kinfo->unassigned_mem >>20 )); mem->nr_banks =0 ;/* -* First try and allocate the largest thing we can as low as -* possible to be bank 0. +* Calculate the absolute minimum size required to fit the kernel, +* initrd, and DTB inside Bank 0 */ -while ( order >= min_low_order ) - { -for ( bits = order ; bits <= lowmem_bitsize; bits++ ) - { - pg =alloc_domheap_pages (d, order,MEMF_bits (bits)); -if ( pg !=NULL ) - { -if ( !insert_11_bank (d, kinfo, pg, order) ) -BUG ();/* Cannot fail for first bank */ +if ( kernel_mod ) + required_size += kernel_mod->size; +if ( ramdisk_mod ) + required_size += ramdisk_mod->size; +if ( dtb_mod ) + required_size += dtb_mod->size; +if ( xsm_policy_mod ) + required_size += xsm_policy_mod->size; - goto got_bank0; - } - } - order--; - } - -/* Failed to allocate bank0 in the lowmem region. */ -if (is_32bit_domain (d) ) -panic ("Unable to allocate first memory bank\n" ); + min_bank0_order =get_order_from_bytes (required_size); -/* Try to allocate memory from above the lowmem region */ -printk (XENLOG_INFO "No bank has been allocated below %u-bit.\n" , - lowmem_bitsize); - lowmem = false; +nodes_clear (exhausted_nodes); +nodes_and (valid_nodes, d->node_affinity, node_online_map); - got_bank0: +BUG_ON (nodes_empty (valid_nodes)); -/* -* If we failed to allocate bank0 in the lowmem region, -* continue allocating from above the lowmem and fill in banks. -*/ - order =get_allocation_size (kinfo->unassigned_mem); -while ( kinfo->unassigned_mem && mem->nr_banks < mem->max_banks ) +while ( todo >0 ) { - pg =alloc_domheap_pages (d, order, - lowmem ?MEMF_bits (lowmem_bitsize) :0 ); -if ( !pg ) - { - order --; +paddr_t last_todo = todo; +nodemask_t active_nodes; +unsigned int active_nodes_count; +unsigned int nodes_left; -if ( lowmem && order < min_low_order) - { -D11PRINT ("Failed at min_low_order, allow high allocations\n" ); - order =get_allocation_size (kinfo->unassigned_mem); - lowmem = false; -continue ; - } -if ( order >= min_order ) -continue ; +/* Filter out exhausted nodes to find active candidates */ +nodes_andnot (active_nodes, valid_nodes, exhausted_nodes); + active_nodes_count =nodes_weight (active_nodes); -/* No more we can do */ +if ( active_nodes_count ==0 ) + { +printk (XENLOG_WARNING "Dom0 NUMA: All specified nodes are completely exhausted.\n" );break ; } -if ( !insert_11_bank (d, kinfo, pg, order) ) + nodes_left = active_nodes_count; + +for_each_node_mask (node, active_nodes) { -if ( mem->nr_banks == mem->max_banks ) -/* Nothing more we can do. */ -break ; +paddr_t target_per_node; +paddr_t node_todo; -if ( lowmem ) - { -D11PRINT ("Allocation below bank 0, allow high allocations\n" ); - order =get_allocation_size (kinfo->unassigned_mem); - lowmem = false; -continue ; - } -else +/* Target chunk size per node */ + target_per_node =DIV_ROUND_UP (todo, nodes_left); + target_per_node =DIV_ROUND_UP (target_per_node,MB (128 )) *MB (128 ); + + node_todo =min (todo, target_per_node); + +while ( node_todo >0 ) { -D11PRINT ("Allocation below bank 0\n" ); -break ; +struct page_info *pg =NULL ; +unsigned int max_order =get_allocation_size (node_todo); +unsigned int order; +paddr_t bank_size; + +/* +* Enforce a maximum chunk cap of 128MB for all allocations +* except Bank 0 +*/ +if ( !is_bank0 && max_order > max_chunk_order ) + max_order = max_chunk_order; + +for ( order = max_order; order >= min_order; order-- ) + { +unsigned int memflags =MEMF_node (node); +if ( !dom0_affinity_relaxed ) + memflags |= MEMF_exact_node; + +if ( is_bank0 ) + { +unsigned int bits; +for ( bits = order; bits <= lowmem_bitsize; bits++ ) + { + pg =alloc_domheap_pages (d, order, memflags |MEMF_bits (bits)); +if ( pg !=NULL ) +break ; + } + +if ( !pg && order <= min_bank0_order ) + { +if (is_32bit_domain (d) ) +panic ("Unable to allocate first memory bank below %u-bit\n" , lowmem_bitsize); + + pg =alloc_domheap_pages (d, order, memflags); + } + } +else + { + pg =alloc_domheap_pages (d, order, memflags); + } + +if ( pg ) +break ; + } + +if ( !pg ) + { +node_set (node, exhausted_nodes); +break ; + } + + is_bank0 = false; + +if ( !insert_11_bank (d, kinfo, pg, order, node) ) +break ; + + bank_size =1ULL << (PAGE_SHIFT + order); + node_todo -= bank_size; + todo -= bank_size; + +if ( todo ==0 )break ; } + + nodes_left--; +if ( todo ==0 )break ; }/* -* Success, next time around try again to get the largest order -* allocation possible. +* Prevent infinite loop if a full pass across all active nodes +* yields zero progress */ - order =get_allocation_size (kinfo->unassigned_mem); +if ( todo == last_todo ) +break ; }if ( kinfo->unassigned_mem )
@@ -464,14 +491,15 @@ static void __init allocate_memory_11(struct domain *d,panic ("Failed to allocate requested dom0 memory. %ldMB unallocated\n" , (unsigned long )kinfo->unassigned_mem >>20 ); -for ( i =0 ; i < mem->nr_banks; i++ ) +for ( i =0 ; i < mem->nr_banks; i++ ) { -printk ("BANK[%d] %#" PRIpaddr"-%#" PRIpaddr" (%ldMB)\n" , +printk ("BANK[%d] %#" PRIpaddr"-%#" PRIpaddr" (%ldMB) NODE:%u\n" , i, mem->bank[i].start, mem->bank[i].start + mem->bank[i].size,/* Don't want format this as PRIpaddr (16 digit hex) */ - (unsigned long )(mem->bank[i].size >>20 )); + (unsigned long )(mem->bank[i].size >>20 ), +get_numa_nodeid (&mem->bank[i])); } }
Signature · 1 line
2.43.0
PATCH v2 23/24 xen/arm: Use dedicated function for Static SHM Device Tree creation
In reply to Hirokazu TakahashiUse a dedicated function to create Static SHM Device Tree nodes instead of reusing the generic memory node function.
Since the memory banks managing Static SHM repurpose the 'type' field for a different purpose via a union, separating this creation logic keeps the implementation clean and significantly improves maintainability.
--- xen/arch/arm/domain_build.c | 6 ++++++ xen/common/device-tree/domain-build.c | 21 +++++++++++++++++++++ xen/include/xen/fdt-domain-build.h | 2 ++ 3 files changed, 29 insertions(+)
xen/arch/arm/domain_build.c +6 -0
@@ -1807,6 +1807,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,if ( res )return res; +#ifdef CONFIG_STATIC_SHM + res =make_raw_memory_node (kinfo, addrcells, sizecells,kernel_info_get_shm_mem_const (kinfo)); +if ( res ) +return res; +#endif /* CONFIG_STATIC_SHM */ + res =make_distance_map_node (d, kinfo->fdt);if ( res )return res;
xen/common/device-tree/domain-build.c +21 -0
@@ -565,6 +565,27 @@ int __init make_memory_node(const struct kernel_info *kinfo, int addrcells,return res; } +int __init make_raw_memory_node (const struct kernel_info *kinfo,int addrcells, +int sizecells,const struct membanks *mem) +{ +unsigned int i; +int res =0 ; + +if ( mem->nr_banks ==0 ) +return 0 ; + +dt_dprintk ("Create raw memory nodes\n" ); + +for ( i =0 ; i < mem->nr_banks; i++ ) + { + res =make_memory_sibling_node (kinfo, addrcells, sizecells, &mem->bank[i]); +if ( res ) +return res; + } + +return res; +} +/* * Local variables: * mode: C
xen/include/xen/fdt-domain-build.h +2 -0
@@ -31,6 +31,8 @@ int make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells);int make_memory_node (const struct kernel_info *kinfo,int addrcells,int sizecells,const struct membanks *mem); +int make_raw_memory_node (const struct kernel_info *kinfo,int addrcells, +int sizecells,const struct membanks *mem);int make_timer_node (const struct kernel_info *kinfo);static inline int get_allocation_size (paddr_t size)
Signature · 1 line
2.43.0
PATCH v2 24/24 xen/arm: Support numa and dom0_nodes boot options
In reply to Hirokazu TakahashiThe numa_nodes command line option is now supported on ARM Xen. Its usage is almost identical to x86 Xen. The key difference is that while x86 uses ACPI PXM values to specify nodes, ARM uses the values defined in the device tree (numa-node-id).
--- docs/misc/xen-command-line.pandoc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
docs/misc/xen-command-line.pandoc +5 -4
@@ -1050,7 +1050,7 @@ Practices](https://wiki.xen.org/wiki/Xen_Best_Practices#Xen_dom0_dedicated_memor This option doesn't have effect if pv-shim mode is enabled. -### dom0_nodes (x86) +### dom0_nodes (x86, arm) > `= List of [ <integer> | relaxed | strict ]`
@@ -1059,8 +1059,9 @@ This option doesn't have effect if pv-shim mode is enabled. Specify the NUMA nodes to place Dom0 on. Defaults for vCPU-s created and memory assigned to Dom0 will be adjusted to match the node restrictions set up here. Note that the values to be specified here are -ACPI PXM ones, not Xen internal node numbers. `relaxed` sets up vCPU -affinities to prefer but be not limited to the specified node(s). +ACPI PXM ones, not Xen internal node numbers, or node IDs in the device +tree. `relaxed` sets up vCPU affinities to prefer but be not limited to +the specified node(s). ### dom0_vcpus_pin > `= <boolean>`
@@ -2017,7 +2018,7 @@ This option is ignored in **pv-shim** mode. ### nr_irqs (x86) > `= <integer>` -### numa (x86) +### numa (x86, arm) > `= on | off | fake=<integer> | noacpi` > Default: `on`
Signature · 1 line
2.43.0