Add ACPI NUMA support for RISC-V
Subsystems (3)
v2 cover Add ACPI NUMA support for RISC-V
This patch series enable RISC-V ACPI NUMA support which was based on the recently approved ACPI ECR[1].
Patch 1/6 is generated from the acpica PR[2] and should be merged through the acpica project. Due to this dependency, other 5 patches can only be merged after the corresponding ACPICA patch was pulled into linux.
Patch 2/6 add RISC-V specific acpi_numa.c file to parse NUMA information from SRAT and SLIT ACPI tables.
Patch 3/6 add the common SRAT RINTC affinity structure handler. Patch 4/6 remove the '#if defined(CONFIG_ARCH)' condition to make some NUMA related parse functions common for all current architectures that support ACPI_NUMA
Patch 5/6 remove ARCH depends option in ACPI_NUMA Kconfig which was no longer needed since all the current architectures that support ACPI would select ACPI_NUMA by default.
Patch 6/6 add corresponding ACPI_NUMA config for RISC-V Kconfig.
Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next
[1] https://drive.google.com/file/d/1YTdDx2IPm5IeZjAW932EYU-tUtgS08tX/view?usp=sharing
[2] https://github.com/acpica/acpica/pull/926
Testing:
Since the ACPI AIA/PLIC support patch set is still under upstream review, hence it is tested using the poll based HVC SBI console and RAM disk.
1) Build latest Qemu with the following patch backported
https://lore.kernel.org/all/[email protected]/
https://github.com/vlsunil/qemu/commit/42bd4eeefd5d4410a68f02d54fee406d8a1269b0
2) Build latest EDK-II
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md
3) Build Linux with the following configs enabled
CONFIG_RISCV_SBI_V01=y
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
CONFIG_HVC_RISCV_SBI=y
CONFIG_NUMA=y
CONFIG_ACPI_NUMA=y
4) Build buildroot rootfs.cpio
5) Launch the Qemu machine
qemu-system-riscv64 -nographic \
-machine virt,pflash0=pflash0,pflash1=pflash1 -smp 4 -m 8G \
-blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
-blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
-object memory-backend-ram,size=4G,id=m0 \
-object memory-backend-ram,size=4G,id=m1 \
-numa node,memdev=m0,cpus=0-1,nodeid=0 \
-numa node,memdev=m1,cpus=2-3,nodeid=1 \
-numa dist,src=0,dst=1,val=30 \
-kernel linux/arch/riscv/boot/Image \
-initrd buildroot/output/images/rootfs.cpio \
-append "root=/dev/ram ro console=hvc0 earlycon=sbi"
[ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x80000000-0x17fffffff] [ 0.000000] ACPI: SRAT: Node 1 PXM 1 [mem 0x180000000-0x27fffffff] [ 0.000000] NUMA: NODE_DATA [mem 0x17fe3bc40-0x17fe3cfff] [ 0.000000] NUMA: NODE_DATA [mem 0x27fff4c40-0x27fff5fff] ... [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x0 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x1 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x2 -> Node 1 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x3 -> Node 1
---
Changes since v1
- Switch the order of patch 2/4 and 3/4 - Per Sunil's suggestion
- Add a new patch 4/6 to make some NUMA related parse functions common for all the architectures that support ACPI NUMA - Per Sunil's suggestion
- Add a new patch 5/6 to remove ARCH depends option in ACPI_NUMA Kconfig since all the current architectures that support ACPI would select ACPI_NUMA by default - Per Arnd and Sunil's suggestion
- Other minor fix for code format - Per Sunil's comments
Haibo Xu (6):
ACPICA: SRAT: Add RISC-V RINTC affinity structure
ACPI: RISCV: Add NUMA support based on SRAT and SLIT
ACPI: NUMA: Add handler for SRAT RINTC affinity structure
ACPI: NUMA: Make some NUMA related parse functions common
ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
ACPI: RISCV: Enable ACPI based NUMA
arch/riscv/Kconfig | 1 + arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - drivers/acpi/numa/Kconfig | 1 - drivers/acpi/numa/srat.c | 40 ++++++++--- include/acpi/actbl3.h | 18 ++++- include/linux/acpi.h | 6 ++ 11 files changed, 203 insertions(+), 21 deletions(-) create mode 100644 arch/riscv/kernel/acpi_numa.c
Signature · 1 line
2.34.1
PATCH v2 1/6 ACPICA: SRAT: Add RISC-V RINTC affinity structure
ACPICA commit 93caddbf2f620769052c59ec471f018281dc3a24
Add definition of RISC-V Interrupt Controller(RINTC) affinity structure which was approved by UEFI forum and will be part of next ACPI spec version(6.6).
--- include/acpi/actbl3.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
include/acpi/actbl3.h +17 -1
@@ -192,7 +192,8 @@ enum acpi_srat_type {ACPI_SRAT_TYPE_GIC_ITS_AFFINITY =4 ,/* ACPI 6.2 */ ACPI_SRAT_TYPE_GENERIC_AFFINITY =5 ,/* ACPI 6.3 */ ACPI_SRAT_TYPE_GENERIC_PORT_AFFINITY =6 ,/* ACPI 6.4 */ - ACPI_SRAT_TYPE_RESERVED = 7 /* 7 and greater are reserved */ +ACPI_SRAT_TYPE_RINTC_AFFINITY =7 ,/* ACPI 6.6 */ + ACPI_SRAT_TYPE_RESERVED = 8 /* 8 and greater are reserved */ };/*
@@ -296,6 +297,21 @@ struct acpi_srat_generic_affinity {#define ACPI_SRAT_GENERIC_AFFINITY_ENABLED (1)/* 00: Use affinity structure */ #define ACPI_SRAT_ARCHITECTURAL_TRANSACTIONS (1<<1)/* ACPI 6.4 */ +/* 7: RINTC Affinity (ACPI 6.6) */ + +struct acpi_srat_rintc_affinity { +struct acpi_subtable_header header; +u16 reserved;/* Reserved, must be zero */ +u32 proximity_domain; +u32 acpi_processor_uid; +u32 flags; +u32 clock_domain; +}; + +/* Flags for struct acpi_srat_rintc_affinity */ + +#define ACPI_SRAT_RINTC_ENABLED (1)/* 00: Use affinity structure */ +/******************************************************************************* * * STAO - Status Override Table (_STA override) - ACPI 6.0
Signature · 1 line
2.34.1
PATCH v2 2/6 ACPI: RISCV: Add NUMA support based on SRAT and SLIT
In reply to Haibo XuAdd acpi_numa.c file to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains.
--- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 arch/riscv/kernel/acpi_numa.c
arch/riscv/include/asm/acpi.h +13 -2
@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }void acpi_init_rintc_map (void );struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); -u32 get_acpi_id_for_cpu (int cpu); +static inline u32 get_acpi_id_for_cpu (int cpu) +{ +return acpi_cpu_get_madt_rintc (cpu)->uid; +} +int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa); -static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; }void acpi_get_cbo_block_size (struct acpi_table_header *table,u32 *cbom_size,u32 *cboz_size,u32 *cbop_size);#else
@@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,#endif /* CONFIG_ACPI */ +#ifdef CONFIG_ACPI_NUMA +int acpi_numa_get_nid (unsigned int cpu); +void acpi_map_cpus_to_nodes (void ); +#else +static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; } +static inline void acpi_map_cpus_to_nodes (void ) { } +#endif /* CONFIG_ACPI_NUMA */ +#endif /*_ASM_ACPI_H*/
arch/riscv/kernel/Makefile +1 -0
@@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ obj-$(CONFIG_ACPI) += acpi.o +obj-$(CONFIG_ACPI_NUMA) += acpi_numa.o
arch/riscv/kernel/acpi.c +0 -5
@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)return &cpu_madt_rintc[cpu]; } -u32 get_acpi_id_for_cpu (int cpu) -{ -return acpi_cpu_get_madt_rintc (cpu)->uid; -} -/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping.
arch/riscv/kernel/acpi_numa.c new file +131 -0
131 lines not on this page · raw message
arch/riscv/kernel/setup.c +3 -1
@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)setup_smp ();#endif -if (!acpi_disabled) +if (!acpi_disabled) {acpi_init_rintc_map (); +acpi_map_cpus_to_nodes (); + }riscv_init_cbo_blocksizes ();riscv_fill_hwcap ();
arch/riscv/kernel/smpboot.c +0 -2
@@ -100,7 +100,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unif (hart ==cpuid_to_hartid_map (0 )) {BUG_ON (found_boot_cpu); found_boot_cpu = true; -early_map_cpu_to_node (0 ,acpi_numa_get_nid (cpu_count));return 0 ; }
@@ -110,7 +109,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un }cpuid_to_hartid_map (cpu_count) = hart; -early_map_cpu_to_node (cpu_count,acpi_numa_get_nid (cpu_count)); cpu_count++;return 0 ;
include/linux/acpi.h +6 -0
@@ -269,6 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma); +#ifdef CONFIG_RISCV +void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa); +#else +static inline void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) { } +#endif +#ifndef PHYS_CPUID_INVALID typedef u32 phys_cpuid_t ;#define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
Signature · 1 line
2.34.1
Re: [PATCH v2 2/6] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
Quoted 257 lines · Haibo Xu
Add
acpi_numa.cfile to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 arch/riscv/kernel/acpi_numa.carch/riscv/include/asm/acpi.h +13
-2@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }void acpi_init_rintc_map (void );struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); -u32 get_acpi_id_for_cpu (int cpu); +static inline u32 get_acpi_id_for_cpu (int cpu) +{ +return acpi_cpu_get_madt_rintc (cpu)->uid; +} +int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa); -static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; }void acpi_get_cbo_block_size (struct acpi_table_header *table,u32 *cbom_size,u32 *cboz_size,u32 *cbop_size);#else @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,#endif /* CONFIG_ACPI */ +#ifdef CONFIG_ACPI_NUMA +int acpi_numa_get_nid (unsigned int cpu); +void acpi_map_cpus_to_nodes (void ); +#else +static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; } +static inline void acpi_map_cpus_to_nodes (void ) { } +#endif /* CONFIG_ACPI_NUMA */ +#endif /*_ASM_ACPI_H*/ arch/riscv/kernel/Makefile +1
-0@@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ obj-$(CONFIG_ACPI) += acpi.o +obj-$(CONFIG_ACPI_NUMA) += acpi_numa.oarch/riscv/kernel/acpi.c +0
-5@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)return &cpu_madt_rintc[cpu]; } -u32 get_acpi_id_for_cpu (int cpu) -{ -return acpi_cpu_get_madt_rintc (cpu)->uid; -} -/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. arch/riscv/kernel/acpi_numa.c new file +131
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* ACPI 6.6 based NUMA setup for RISCV +* Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c +* +* Copyright 2004 Andi Kleen, SuSE Labs. +* Copyright (C) 2013-2016, Linaro Ltd. +* Author: Hanjun Guo <[email protected]> +* Copyright (C) 2024 Intel Corporation. +* +* Reads the ACPI SRAT table to figure out what memory belongs to which CPUs. +* +* Called from acpi_numa_init while reading the SRAT and SLIT tables. +* Assumes all memory regions belonging to a single proximity domain +* are in one chunk. Holes between them will be included in the node. +*/ + +#define pr_fmt (fmt) "ACPI: NUMA: " fmt + +#include <linux/acpi.h> +#include <linux/bitmap.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/mmzone.h> +#include <linux/module.h> +#include <linux/topology.h> + +#include <asm/numa.h> + +static int acpi_early_node_map[NR_CPUS ]__initdata = {NUMA_NO_NODE }; + +int __init acpi_numa_get_nid (unsigned int cpu) +{ +return acpi_early_node_map[cpu]; +} + +static inline int get_cpu_for_acpi_id (u32 uid) +{ +int cpu; + +for (cpu =0 ; cpu < nr_cpu_ids; cpu++) +if (uid ==get_acpi_id_for_cpu (cpu)) +return cpu; + +return -EINVAL ; +} + +static int __init acpi_parse_rintc_pxm (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_srat_rintc_affinity *pa; +int cpu, pxm, node; + +if (srat_disabled ()) +return -EINVAL ; + + pa = (struct acpi_srat_rintc_affinity *)header; +if (!pa) +return -EINVAL ; + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return 0 ; + + pxm = pa->proximity_domain; + node =pxm_to_node (pxm); + +/* +* If we can't map the UID to a logical cpu this +* means that the UID is not part of possible cpus +* so we do not need a NUMA mapping for it, skip +* the SRAT entry and keep parsing. +*/ + cpu =get_cpu_for_acpi_id (pa->acpi_processor_uid); +if (cpu <0 ) +return 0 ; + + acpi_early_node_map[cpu] = node; +pr_info ("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n" , pxm, +cpuid_to_hartid_map (cpu), node); + +return 0 ; +} + +void __init acpi_map_cpus_to_nodes (void ) +{ +int i; + +/* +* In ACPI, SMP and CPU NUMA information is provided in separate +* static tables, namely the MADT and the SRAT. +* +* Thus, it is simpler to first create the cpu logical map through +* an MADT walk and then map the logical cpus to their node ids +* as separate steps. +*/ +acpi_table_parse_entries (ACPI_SIG_SRAT ,sizeof (struct acpi_table_srat ), +ACPI_SRAT_TYPE_RINTC_AFFINITY , acpi_parse_rintc_pxm,0 ); + +for (i =0 ; i < nr_cpu_ids; i++) +early_map_cpu_to_node (i,acpi_numa_get_nid (i)); +} + +/* Callback for Proximity Domain -> logical node ID mapping */ +void __init acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) +{ +int pxm, node; + +if (srat_disabled ()) +return ; + +if (pa->header.length <sizeof (struct acpi_srat_rintc_affinity )) { +pr_err ("SRAT: Invalid SRAT header length: %d\n" , pa->header.length); +bad_srat (); +return ; + } + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return ; + + pxm = pa->proximity_domain; + node =acpi_map_pxm_to_node (pxm); + +if (node ==NUMA_NO_NODE ) { +pr_err ("SRAT: Too many proximity domains %d\n" , pxm); +bad_srat (); +return ; + } + +node_set (node, numa_nodes_parsed); +}arch/riscv/kernel/setup.c +3
-1@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)setup_smp ();#endif -if (!acpi_disabled) +if (!acpi_disabled) {acpi_init_rintc_map (); +acpi_map_cpus_to_nodes (); + }riscv_init_cbo_blocksizes ();riscv_fill_hwcap ();arch/riscv/kernel/smpboot.c +0
-2@@ -100,7 +100,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unif (hart ==cpuid_to_hartid_map (0 )) {BUG_ON (found_boot_cpu); found_boot_cpu = true; -early_map_cpu_to_node (0 ,acpi_numa_get_nid (cpu_count));return 0 ; }@@ -110,7 +109,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un }cpuid_to_hartid_map (cpu_count) = hart; -early_map_cpu_to_node (cpu_count,acpi_numa_get_nid (cpu_count)); cpu_count++;return 0 ;include/linux/acpi.h +0
-0@@ -269,6 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
include/linux/acpi.h acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { } · line 280
Quoted 10 lines
include/linux/acpi.h +6
-0+#ifdef CONFIG_RISCV +void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa); +#else +static inline void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) { } +#endif +#ifndef PHYS_CPUID_INVALID typedef u32 phys_cpuid_t ;#define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
This is a large patch spanning across multiple files. Can we split this into multiple smaller patches? Changes look fine to me though.
Re: [PATCH v2 2/6] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
Quoted 18 lines · Sunil V L
Quoted 15 lines · Haibo Xu
Add
acpi_numa.cfile to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-)
Quoted 7 lines
Quoted 4 lines
#ifndef
PHYS_CPUID_INVALID
typedef u32phys_cpuid_t;
#definePHYS_CPUID_INVALID(phys_cpuid_t)(-1)
--This is a large patch spanning across multiple files. Can we split this into multiple smaller patches? Changes look fine to me though.
Thanks for the review!
I will try to break them in v3.
Quoted 1 line
Reviewed-by Sunil V L <[email protected]>
Alexandre Ghiti
reviewerRe: [PATCH v2 2/6] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
In reply to Haibo XuHi Haibo,
Quoted 203 lines · Haibo Xu
Add
acpi_numa.cfile to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-)create mode 100644
arch/riscv/kernel/acpi_numa.carch/riscv/include/asm/acpi.h +13
-2@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }void acpi_init_rintc_map (void );struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); -u32 get_acpi_id_for_cpu (int cpu); +static inline u32 get_acpi_id_for_cpu (int cpu) +{ +return acpi_cpu_get_madt_rintc (cpu)->uid; +} +int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa); -static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; }void acpi_get_cbo_block_size (struct acpi_table_header *table,u32 *cbom_size,u32 *cboz_size,u32 *cbop_size);#else @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,#endif /* CONFIG_ACPI */ +#ifdef CONFIG_ACPI_NUMA +int acpi_numa_get_nid (unsigned int cpu); +void acpi_map_cpus_to_nodes (void ); +#else +static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; } +static inline void acpi_map_cpus_to_nodes (void ) { } +#endif /* CONFIG_ACPI_NUMA */ +#endif /*_ASM_ACPI_H*/ arch/riscv/kernel/Makefile +1
-0@@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ obj-$(CONFIG_ACPI) += acpi.o +obj-$(CONFIG_ACPI_NUMA) += acpi_numa.oarch/riscv/kernel/acpi.c +0
-5@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)return &cpu_madt_rintc[cpu]; } -u32 get_acpi_id_for_cpu (int cpu) -{ -return acpi_cpu_get_madt_rintc (cpu)->uid; -} -/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. arch/riscv/kernel/acpi_numa.c new file +121
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* ACPI 6.6 based NUMA setup for RISCV +* Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c +* +* Copyright 2004 Andi Kleen, SuSE Labs. +* Copyright (C) 2013-2016, Linaro Ltd. +* Author: Hanjun Guo <[email protected]> +* Copyright (C) 2024 Intel Corporation. +* +* Reads the ACPI SRAT table to figure out what memory belongs to which CPUs. +* +* Called from acpi_numa_init while reading the SRAT and SLIT tables. +* Assumes all memory regions belonging to a single proximity domain +* are in one chunk. Holes between them will be included in the node. +*/ + +#define pr_fmt (fmt) "ACPI: NUMA: " fmt + +#include <linux/acpi.h> +#include <linux/bitmap.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/mmzone.h> +#include <linux/module.h> +#include <linux/topology.h> + +#include <asm/numa.h> + +static int acpi_early_node_map[NR_CPUS ]__initdata = {NUMA_NO_NODE }; + +int __init acpi_numa_get_nid (unsigned int cpu) +{ +return acpi_early_node_map[cpu]; +} + +static inline int get_cpu_for_acpi_id (u32 uid) +{ +int cpu; + +for (cpu =0 ; cpu < nr_cpu_ids; cpu++) +if (uid ==get_acpi_id_for_cpu (cpu)) +return cpu; + +return -EINVAL ; +} + +static int __init acpi_parse_rintc_pxm (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_srat_rintc_affinity *pa; +int cpu, pxm, node; + +if (srat_disabled ()) +return -EINVAL ; + + pa = (struct acpi_srat_rintc_affinity *)header; +if (!pa) +return -EINVAL ; + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return 0 ; + + pxm = pa->proximity_domain; + node =pxm_to_node (pxm); + +/* +* If we can't map the UID to a logical cpu this +* means that the UID is not part of possible cpus +* so we do not need a NUMA mapping for it, skip +* the SRAT entry and keep parsing. +*/ + cpu =get_cpu_for_acpi_id (pa->acpi_processor_uid); +if (cpu <0 ) +return 0 ; + + acpi_early_node_map[cpu] = node; +pr_info ("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n" , pxm, +cpuid_to_hartid_map (cpu), node); + +return 0 ; +} + +void __init acpi_map_cpus_to_nodes (void ) +{ +int i; + +/* +* In ACPI, SMP and CPU NUMA information is provided in separate +* static tables, namely the MADT and the SRAT. +* +* Thus, it is simpler to first create the cpu logical map through +* an MADT walk and then map the logical cpus to their node ids +* as separate steps. +*/ +acpi_table_parse_entries (ACPI_SIG_SRAT ,sizeof (struct acpi_table_srat ), +ACPI_SRAT_TYPE_RINTC_AFFINITY , acpi_parse_rintc_pxm,0 ); + +for (i =0 ; i < nr_cpu_ids; i++) +early_map_cpu_to_node (i,acpi_numa_get_nid (i)); +} + +/* Callback for Proximity Domain -> logical node ID mapping */ +void __init acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) +{ +int pxm, node; + +if (srat_disabled ()) +return ; + +if (pa->header.length <sizeof (struct acpi_srat_rintc_affinity )) { +pr_err ("SRAT: Invalid SRAT header length: %d\n" , pa->header.length); +bad_srat (); +return ; + } + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return ; + + pxm = pa->proximity_domain;
arch/riscv/kernel/acpi_numa.c line 131
Quoted 10 lines
arch/riscv/kernel/acpi_numa.c new file +10
-0+ node =acpi_map_pxm_to_node (pxm); + +if (node ==NUMA_NO_NODE ) { +pr_err ("SRAT: Too many proximity domains %d\n" , pxm); +bad_srat (); +return ; + } + +node_set (node, numa_nodes_parsed); +}
What is riscv specific in the parsing of those tables? Can't we try to merge this into generic ACPI code? I know that's a burden to try and factorize code with other architectures instead of reusing it, but it showed numerous times that duplicating was even worse (I have the NAPOT code in mind).
Thanks,
Alex
Quoted 53 lines
arch/riscv/kernel/setup.c +3
-1@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)setup_smp ();#endif -if (!acpi_disabled) +if (!acpi_disabled) {acpi_init_rintc_map (); +acpi_map_cpus_to_nodes (); + }riscv_init_cbo_blocksizes ();riscv_fill_hwcap ();arch/riscv/kernel/smpboot.c +0
-2@@ -100,7 +100,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unif (hart ==cpuid_to_hartid_map (0 )) {BUG_ON (found_boot_cpu); found_boot_cpu = true; -early_map_cpu_to_node (0 ,acpi_numa_get_nid (cpu_count));return 0 ; }@@ -110,7 +109,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un }cpuid_to_hartid_map (cpu_count) = hart; -early_map_cpu_to_node (cpu_count,acpi_numa_get_nid (cpu_count)); cpu_count++;return 0 ;include/linux/acpi.h +6
-0@@ -269,6 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma); +#ifdef CONFIG_RISCV +void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa); +#else +static inline void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) { } +#endif +#ifndef PHYS_CPUID_INVALID typedef u32 phys_cpuid_t ;#define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
Re: [PATCH v2 2/6] ACPI: RISCV: Add NUMA support based on SRAT and SLIT
Quoted 216 lines · Alexandre Ghiti
Hi Haibo,
Quoted 212 lines · Haibo Xu
Add
acpi_numa.cfile to enable parse NUMA information from ACPI SRAT and SLIT tables. SRAT table provide CPUs(Hart) and memory nodes to proximity domain mapping, while SLIT table provide the distance metrics between proximity domains.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - include/linux/acpi.h | 6 ++ 7 files changed, 154 insertions(+), 10 deletions(-)create mode 100644
arch/riscv/kernel/acpi_numa.carch/riscv/include/asm/acpi.h +13
-2@@ -61,11 +61,14 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }void acpi_init_rintc_map (void );struct acpi_madt_rintc *acpi_cpu_get_madt_rintc (int cpu); -u32 get_acpi_id_for_cpu (int cpu); +static inline u32 get_acpi_id_for_cpu (int cpu) +{ +return acpi_cpu_get_madt_rintc (cpu)->uid; +} +int acpi_get_riscv_isa (struct acpi_table_header *table,unsigned int cpu,const char **isa); -static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; }void acpi_get_cbo_block_size (struct acpi_table_header *table,u32 *cbom_size,u32 *cboz_size,u32 *cbop_size);#else @@ -87,4 +90,12 @@ static inline void acpi_get_cbo_block_size(struct acpi_table_header *table,#endif /* CONFIG_ACPI */ +#ifdef CONFIG_ACPI_NUMA +int acpi_numa_get_nid (unsigned int cpu); +void acpi_map_cpus_to_nodes (void ); +#else +static inline int acpi_numa_get_nid (unsigned int cpu) {return NUMA_NO_NODE ; } +static inline void acpi_map_cpus_to_nodes (void ) { } +#endif /* CONFIG_ACPI_NUMA */ +#endif /*_ASM_ACPI_H*/ arch/riscv/kernel/Makefile +1
-0@@ -105,3 +105,4 @@ obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ obj-$(CONFIG_ACPI) += acpi.o +obj-$(CONFIG_ACPI_NUMA) += acpi_numa.oarch/riscv/kernel/acpi.c +0
-5@@ -191,11 +191,6 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)return &cpu_madt_rintc[cpu]; } -u32 get_acpi_id_for_cpu (int cpu) -{ -return acpi_cpu_get_madt_rintc (cpu)->uid; -} -/* * __acpi_map_table() will be called before paging_init(), so early_ioremap() * or early_memremap() should be called here to for ACPI table mapping. arch/riscv/kernel/acpi_numa.c new file +130
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* ACPI 6.6 based NUMA setup for RISCV +* Lots of code was borrowed from arch/arm64/kernel/acpi_numa.c +* +* Copyright 2004 Andi Kleen, SuSE Labs. +* Copyright (C) 2013-2016, Linaro Ltd. +* Author: Hanjun Guo <[email protected]> +* Copyright (C) 2024 Intel Corporation. +* +* Reads the ACPI SRAT table to figure out what memory belongs to which CPUs. +* +* Called from acpi_numa_init while reading the SRAT and SLIT tables. +* Assumes all memory regions belonging to a single proximity domain +* are in one chunk. Holes between them will be included in the node. +*/ + +#define pr_fmt (fmt) "ACPI: NUMA: " fmt + +#include <linux/acpi.h> +#include <linux/bitmap.h> +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/memblock.h> +#include <linux/mmzone.h> +#include <linux/module.h> +#include <linux/topology.h> + +#include <asm/numa.h> + +static int acpi_early_node_map[NR_CPUS ]__initdata = {NUMA_NO_NODE }; + +int __init acpi_numa_get_nid (unsigned int cpu) +{ +return acpi_early_node_map[cpu]; +} + +static inline int get_cpu_for_acpi_id (u32 uid) +{ +int cpu; + +for (cpu =0 ; cpu < nr_cpu_ids; cpu++) +if (uid ==get_acpi_id_for_cpu (cpu)) +return cpu; + +return -EINVAL ; +} + +static int __init acpi_parse_rintc_pxm (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_srat_rintc_affinity *pa; +int cpu, pxm, node; + +if (srat_disabled ()) +return -EINVAL ; + + pa = (struct acpi_srat_rintc_affinity *)header; +if (!pa) +return -EINVAL ; + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return 0 ; + + pxm = pa->proximity_domain; + node =pxm_to_node (pxm); + +/* +* If we can't map the UID to a logical cpu this +* means that the UID is not part of possible cpus +* so we do not need a NUMA mapping for it, skip +* the SRAT entry and keep parsing. +*/ + cpu =get_cpu_for_acpi_id (pa->acpi_processor_uid); +if (cpu <0 ) +return 0 ; + + acpi_early_node_map[cpu] = node; +pr_info ("SRAT: PXM %d -> HARTID 0x%lx -> Node %d\n" , pxm, +cpuid_to_hartid_map (cpu), node); + +return 0 ; +} + +void __init acpi_map_cpus_to_nodes (void ) +{ +int i; + +/* +* In ACPI, SMP and CPU NUMA information is provided in separate +* static tables, namely the MADT and the SRAT. +* +* Thus, it is simpler to first create the cpu logical map through +* an MADT walk and then map the logical cpus to their node ids +* as separate steps. +*/ +acpi_table_parse_entries (ACPI_SIG_SRAT ,sizeof (struct acpi_table_srat ), +ACPI_SRAT_TYPE_RINTC_AFFINITY , acpi_parse_rintc_pxm,0 ); + +for (i =0 ; i < nr_cpu_ids; i++) +early_map_cpu_to_node (i,acpi_numa_get_nid (i)); +} + +/* Callback for Proximity Domain -> logical node ID mapping */ +void __init acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) +{ +int pxm, node; + +if (srat_disabled ()) +return ; + +if (pa->header.length <sizeof (struct acpi_srat_rintc_affinity )) { +pr_err ("SRAT: Invalid SRAT header length: %d\n" , pa->header.length); +bad_srat (); +return ; + } + +if (!(pa->flags &ACPI_SRAT_RINTC_ENABLED )) +return ; + + pxm = pa->proximity_domain; + node =acpi_map_pxm_to_node (pxm); + +if (node ==NUMA_NO_NODE ) { +pr_err ("SRAT: Too many proximity domains %d\n" , pxm); +bad_srat (); +return ; + } + +node_set (node, numa_nodes_parsed);
Quoted 9 lines
arch/riscv/kernel/acpi_numa.c line 131
Quoted 1 line
arch/riscv/kernel/acpi_numa.c new file +1
-0+}What is riscv specific in the parsing of those tables? Can't we try to merge this into generic ACPI code? I know that's a burden to try and factorize code with other architectures instead of reusing it, but it showed numerous times that duplicating was even worse (I have the NAPOT code in mind).
Hi Alex,
The acpi_srat_rintc_affinity structure is RISC-V specific and that's why I put the
callback in arch/riscv/kernel/acpi_numa.c.
Thanks,
Haibo
Quoted 58 lines
Thanks,
Alex
Quoted 53 lines
arch/riscv/kernel/setup.c +3
-1@@ -281,8 +281,10 @@ void __init setup_arch(char **cmdline_p)setup_smp ();#endif -if (!acpi_disabled) +if (!acpi_disabled) {acpi_init_rintc_map (); +acpi_map_cpus_to_nodes (); + }riscv_init_cbo_blocksizes ();riscv_fill_hwcap ();arch/riscv/kernel/smpboot.c +0
-2@@ -100,7 +100,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unif (hart ==cpuid_to_hartid_map (0 )) {BUG_ON (found_boot_cpu); found_boot_cpu = true; -early_map_cpu_to_node (0 ,acpi_numa_get_nid (cpu_count));return 0 ; }@@ -110,7 +109,6 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un }cpuid_to_hartid_map (cpu_count) = hart; -early_map_cpu_to_node (cpu_count,acpi_numa_get_nid (cpu_count)); cpu_count++;return 0 ;include/linux/acpi.h +6
-0@@ -269,6 +269,12 @@ acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma); +#ifdef CONFIG_RISCV +void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa); +#else +static inline void acpi_numa_rintc_affinity_init (struct acpi_srat_rintc_affinity *pa) { } +#endif +#ifndef PHYS_CPUID_INVALID typedef u32 phys_cpuid_t ;#define PHYS_CPUID_INVALID (phys_cpuid_t)(-1)
PATCH v2 3/6 ACPI: NUMA: Add handler for SRAT RINTC affinity structure
In reply to Haibo XuAdd RINTC affinity structure handler during parsing SRAT table.
--- drivers/acpi/numa/srat.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/acpi/numa/srat.c +31 -1
@@ -165,6 +165,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header) } }break ; + +case ACPI_SRAT_TYPE_RINTC_AFFINITY : + { +struct acpi_srat_rintc_affinity *p = + (struct acpi_srat_rintc_affinity *)header; +pr_debug ("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n" , + p->acpi_processor_uid, + p->proximity_domain, + (p->flags &ACPI_SRAT_RINTC_ENABLED ) ? +"enabled" :"disabled" ); + } +break ; +default :pr_warn ("Found unsupported SRAT entry (type = 0x%x)\n" , header->type);
@@ -448,6 +461,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header, }#endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */ +static int __init +acpi_parse_rintc_affinity (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_srat_rintc_affinity *rintc_affinity; + + rintc_affinity = (struct acpi_srat_rintc_affinity *)header; +acpi_table_print_srat_entry (&header->common); + +/* let architecture-dependent part to do it */ +acpi_numa_rintc_affinity_init (rintc_affinity); + +return 0 ; +} +static int __initdata parsed_numa_memblks; static int __init
@@ -501,7 +529,7 @@ int __init acpi_numa_init(void)/* SRAT: System Resource Affinity Table */ if (!acpi_table_parse (ACPI_SIG_SRAT , acpi_parse_srat)) { -struct acpi_subtable_proc srat_proc[4 ]; +struct acpi_subtable_proc srat_proc[5 ];memset (srat_proc,0 ,sizeof (srat_proc)); srat_proc[0 ].id =ACPI_SRAT_TYPE_CPU_AFFINITY ;
@@ -512,6 +540,8 @@ int __init acpi_numa_init(void) srat_proc[2 ].handler = acpi_parse_gicc_affinity; srat_proc[3 ].id =ACPI_SRAT_TYPE_GENERIC_AFFINITY ; srat_proc[3 ].handler = acpi_parse_gi_affinity; + srat_proc[4 ].id =ACPI_SRAT_TYPE_RINTC_AFFINITY ; + srat_proc[4 ].handler = acpi_parse_rintc_affinity; acpi_table_parse_entries_array(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
Signature · 1 line
2.34.1
Re: [PATCH v2 3/6] ACPI: NUMA: Add handler for SRAT RINTC affinity structure
Quoted 63 lines · Haibo Xu
Add RINTC affinity structure handler during parsing SRAT table.
Signed-off-by Haibo Xu <[email protected]>--- drivers/acpi/numa/srat.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)drivers/acpi/numa/srat.c +29
-1@@ -165,6 +165,19 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header) } }break ; + +case ACPI_SRAT_TYPE_RINTC_AFFINITY : + { +struct acpi_srat_rintc_affinity *p = + (struct acpi_srat_rintc_affinity *)header; +pr_debug ("SRAT Processor (acpi id[0x%04x]) in proximity domain %d %s\n" , + p->acpi_processor_uid, + p->proximity_domain, + (p->flags &ACPI_SRAT_RINTC_ENABLED ) ? +"enabled" :"disabled" ); + } +break ; +default :pr_warn ("Found unsupported SRAT entry (type = 0x%x)\n" , header->type);@@ -448,6 +461,21 @@ acpi_parse_gi_affinity(union acpi_subtable_headers *header, }#endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */ +static int __init +acpi_parse_rintc_affinity (union acpi_subtable_headers *header, +const unsigned long end) +{ +struct acpi_srat_rintc_affinity *rintc_affinity; + + rintc_affinity = (struct acpi_srat_rintc_affinity *)header; +acpi_table_print_srat_entry (&header->common); + +/* let architecture-dependent part to do it */ +acpi_numa_rintc_affinity_init (rintc_affinity); + +return 0 ; +} +static int __initdata parsed_numa_memblks; static int __init@@ -501,7 +529,7 @@ int __init acpi_numa_init(void)/* SRAT: System Resource Affinity Table */ if (!acpi_table_parse (ACPI_SIG_SRAT , acpi_parse_srat)) { -struct acpi_subtable_proc srat_proc[4 ]; +struct acpi_subtable_proc srat_proc[5 ];memset (srat_proc,0 ,sizeof (srat_proc)); srat_proc[0 ].id =ACPI_SRAT_TYPE_CPU_AFFINITY ;
drivers/acpi/numa/srat.c int __init acpi_numa_init(void) · line 547
Quoted 8 lines
drivers/acpi/numa/srat.c +2
-0@@ -512,6 +540,8 @@ int __init acpi_numa_init(void) srat_proc[2 ].handler = acpi_parse_gicc_affinity; srat_proc[3 ].id =ACPI_SRAT_TYPE_GENERIC_AFFINITY ; srat_proc[3 ].handler = acpi_parse_gi_affinity; + srat_proc[4 ].id =ACPI_SRAT_TYPE_RINTC_AFFINITY ; + srat_proc[4 ].handler = acpi_parse_rintc_affinity; acpi_table_parse_entries_array(ACPI_SIG_SRAT, sizeof(struct acpi_table_srat),
LGTM. Thanks!
PATCH v2 4/6 ACPI: NUMA: Make some NUMA related parse functions common
In reply to Haibo XuThe acpi_numa_slit_init(), acpi_numa_memory_affinity_init() and acpi_parse_cfmws() functions are common enough to be used on platforms that support ACPI_NUMA(x86/arm64/loongarch). Remove the condition to avoid long defined(CONFIG_ARCH) check when new platform(riscv) support was enabled.
--- drivers/acpi/numa/srat.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/acpi/numa/srat.c +0 -8
@@ -219,7 +219,6 @@ int __init srat_disabled(void)return acpi_numa <0 ; } -#if defined(CONFIG_X86 ) || defined(CONFIG_ARM64 ) || defined(CONFIG_LOONGARCH )/* * Callback for SLIT parsing. pxm_to_node() returns NUMA_NO_NODE for * I/O localities since SRAT does not list them. I/O localities are
@@ -351,13 +350,6 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, (*fake_pxm)++;return 0 ; } -#else -static int __init acpi_parse_cfmws (union acpi_subtable_headers *header, -void *arg,const unsigned long table_end) -{ -return 0 ; -} -#endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */ static int __init acpi_parse_slit (struct acpi_table_header *table) {
Signature · 1 line
2.34.1
Re: [PATCH v2 4/6] ACPI: NUMA: Make some NUMA related parse functions common
Quoted 28 lines · Haibo Xu
The
acpi_numa_slit_init(),acpi_numa_memory_affinity_init()andacpi_parse_cfmws()functions are common enough to be used on platforms that supportACPI_NUMA(x86/arm64/loongarch). Remove the condition to avoid longdefined(CONFIG_ARCH)check when new platform(riscv) support was enabled.Suggested-by Sunil V L <[email protected]>Signed-off-by Haibo Xu <[email protected]>--- drivers/acpi/numa/srat.c | 8 -------- 1 file changed, 8 deletions(-)drivers/acpi/numa/srat.c +0
-1@@ -219,7 +219,6 @@ int __init srat_disabled(void)return acpi_numa <0 ; } -#if defined(CONFIG_X86 ) || defined(CONFIG_ARM64 ) || defined(CONFIG_LOONGARCH )/* * Callback for SLIT parsing. pxm_to_node() returns NUMA_NO_NODE for * I/O localities since SRAT does not list them. I/O localities are @@ -351,13 +350,6 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, (*fake_pxm)++;return 0 ; }
drivers/acpi/numa/srat.c static int __init acpi_parse_cfmws(union acpi_subtable_headers *header, · line 355
Quoted 10 lines
drivers/acpi/numa/srat.c +0
-7-#else -static int __init acpi_parse_cfmws (union acpi_subtable_headers *header, -void *arg,const unsigned long table_end) -{ -return 0 ; -} -#endif /* defined(CONFIG_X86) || defined (CONFIG_ARM64) */ static int __init acpi_parse_slit (struct acpi_table_header *table) {
LGTM.
PATCH v2 5/6 ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
In reply to Haibo Xux86/arm64/loongarch would select ACPI_NUMA by default and riscv would do the same thing, so the dependency is no longer needed since these are the four architectures that support ACPI.
--- drivers/acpi/numa/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/acpi/numa/Kconfig +0 -1
@@ -2,7 +2,6 @@ config ACPI_NUMA bool "NUMA support" depends on NUMA - depends on (X86 || ARM64 || LOONGARCH) default y if ARM64 config ACPI_HMAT
Signature · 1 line
2.34.1
Re: [PATCH v2 5/6] ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
Quoted 16 lines · Haibo Xu
x86/arm64/loongarch would select
ACPI_NUMAby default and riscv would do the same thing, so the dependency is no longer needed since these are the four architectures that support ACPI.Suggested-by Arnd Bergmann <[email protected]>Suggested-by Sunil V L <[email protected]>Signed-off-by Haibo Xu <[email protected]>--- drivers/acpi/numa/Kconfig | 1 - 1 file changed, 1 deletion(-)drivers/acpi/numa/Kconfig +0
-0
drivers/acpi/numa/Kconfig line 5
Quoted 5 lines
drivers/acpi/numa/Kconfig +0
-1@@ -2,7 +2,6 @@ config ACPI_NUMA bool "NUMA support" depends on NUMA - depends on (X86 || ARM64 || LOONGARCH) default y if ARM64
Can we remove the prompt as well and make this a hidden option? I think this is now always selected when it can be used anyway.
If we make it
def_bool NUMA && !X86
then the select statements except for the X86_64_ACPI_NUMA can also go away.
Arnd
Re: [PATCH v2 5/6] ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
Quoted 28 lines · Arnd Bergmann
Quoted 16 lines · Haibo Xu
x86/arm64/loongarch would select
ACPI_NUMAby default and riscv would do the same thing, so the dependency is no longer needed since these are the four architectures that support ACPI.Suggested-by Arnd Bergmann <[email protected]>Suggested-by Sunil V L <[email protected]>Signed-off-by Haibo Xu <[email protected]>--- drivers/acpi/numa/Kconfig | 1 - 1 file changed, 1 deletion(-)drivers/acpi/numa/Kconfig +0
-0drivers/acpi/numa/Kconfig line 5
Quoted 5 lines
drivers/acpi/numa/Kconfig +0
-1@@ -2,7 +2,6 @@ config ACPI_NUMA bool "NUMA support" depends on NUMA - depends on (X86 || ARM64 || LOONGARCH) default y if ARM64Can we remove the prompt as well and make this a hidden option? I think this is now always selected when it can be used anyway.
Quoted 7 lines
If we make it
def_bool NUMA && !X86then the select statements except for the
X86_64_ACPI_NUMAcan also go away.
Good idea!
Shall we include the ACPI in the def_bool definition?
Quoted 1 line
Arnd
Re: [PATCH v2 5/6] ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
Quoted 5 lines · Haibo Xu
Quoted 4 lines · Arnd Bergmann
On Thu, Mar 7, 2024, at 09:47, Haibo Xu wrote:
If we make it
Quoted 9 lines
Quoted 5 lines
def_bool NUMA && !X86then the select statements except for the
X86_64_ACPI_NUMAcan also go away.Good idea!
Shall we include the ACPI in thedef_booldefinition?
No need, because this is inside of an 'if ACPI' block.
Arnd
Re: [PATCH v2 5/6] ACPI: NUMA: Remove ARCH depends option in ACPI_NUMA Kconfig
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Haibo Xu
Quoted 9 lines · Arnd Bergmann
On Thu, Mar 7, 2024, at 09:47, Haibo Xu wrote:
If we make it
def_bool NUMA && !X86then the select statements except for the
X86_64_ACPI_NUMAcan also go away.
Quoted 6 lines
Quoted 3 lines
Good idea!
Shall we include the ACPI in thedef_booldefinition?No need, because this is inside of an 'if ACPI' block.
Cool! Let me have a try.
Thanks,
Haibo
Quoted 1 line
Arnd
PATCH v2 6/6 ACPI: RISCV: Enable ACPI based NUMA
In reply to Haibo XuEnable ACPI based NUMA for RISCV in Kconfig.
--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
@@ -447,6 +447,7 @@ config NUMA select HAVE_SETUP_PER_CPU_AREA select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select ACPI_NUMA if ACPI select OF_NUMA select USE_PERCPU_NUMA_NODE_ID help
Signature · 1 line
2.34.1
Re: [PATCH v2 6/6] ACPI: RISCV: Enable ACPI based NUMA
Hi Haibo,
Quoted 12 lines · Haibo Xu
Enable ACPI based NUMA for RISCV in
Kconfig.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)arch/riscv/Kconfig +0
-0
arch/riscv/Kconfig config NUMA · line 450
Quoted 4 lines
arch/riscv/Kconfig +1
-0@@ -447,6 +447,7 @@ config NUMA select HAVE_SETUP_PER_CPU_AREA select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select ACPI_NUMA if ACPI
If the firmware didn't provide the SRAT/SLIT on ACPI based systems, then there will be a message "Failed to initialise from firmware" from arch_acpi_numa_init(). This is not specific to RISC-V. But I am wondering why should it be pr_info instead of pr_debug.
Thanks,
Sunil
Quoted 6 lines
arch/riscv/Kconfig +0
-0select OF_NUMA select USE_PERCPU_NUMA_NODE_ID helpSignature · 1 line
2.34.1
Re: [PATCH v2 6/6] ACPI: RISCV: Enable ACPI based NUMA
Quoted 11 lines · Sunil V L
Hi Haibo,
Quoted 7 lines · Haibo Xu
Enable ACPI based NUMA for RISCV in
Kconfig.Signed-off-by Haibo Xu <[email protected]>--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
Quoted 15 lines
arch/riscv/Kconfig config NUMA · line 450
Quoted 9 lines
arch/riscv/Kconfig +1
-0@@ -447,6 +447,7 @@ config NUMA select HAVE_SETUP_PER_CPU_AREA select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK + select ACPI_NUMA if ACPIIf the firmware didn't provide the SRAT/SLIT on ACPI based systems, then there will be a message "Failed to initialise from firmware" from
arch_acpi_numa_init(). This is not specific to RISC-V. But I am wondering why should it bepr_infoinstead ofpr_debug.
My understanding is maybe it just wants to expose explicit logs to avoid any potential
bugs from FW or Kernel.
Quoted 8 lines
Thanks,
SunilQuoted 6 lines
arch/riscv/Kconfig +0
-1select OF_NUMA select USE_PERCPU_NUMA_NODE_ID help --2.34.1
RE: [PATCH v2 6/6] ACPI: RISCV: Enable ACPI based NUMA
Quoted 8 lines
Quoted 5 lines
If the firmware didn't provide the SRAT/SLIT on ACPI based systems, then there will be a message "Failed to initialise from firmware" from
arch_acpi_numa_init(). This is not specific to RISC-V. But I am wondering why should it bepr_infoinstead ofpr_debug.My understanding is maybe it just wants to expose explicit logs to avoid any potential bugs from FW or Kernel.
There are lots of ACPI enabled systems that aren't NUMA (single socket servers, desktops, laptops). Making this "pr_info()" would just add noise to the boot on all of those.
-Tony
Re: [PATCH v2 6/6] ACPI: RISCV: Enable ACPI based NUMA
Quoted 6 lines · Tony
Quoted 6 lines
Quoted 5 lines
If the firmware didn't provide the SRAT/SLIT on ACPI based systems, then there will be a message "Failed to initialise from firmware" from
arch_acpi_numa_init(). This is not specific to RISC-V. But I am wondering why should it bepr_infoinstead ofpr_debug.
Quoted 7 lines
Quoted 2 lines
My understanding is maybe it just wants to expose explicit logs to avoid any potential bugs from FW or Kernel.
There are lots of ACPI enabled systems that aren't NUMA (single socket servers, desktops, laptops). Making this "
pr_info()" would just add noise to the boot on all of those.
Exactly. But this is an existing pr_info message across architectures. My suggestion is to add one more patch in this series to convert this to pr_debug unless someone has strong reason to keep it pr_info.
Thanks,
Sunil
Re: [PATCH v2 6/6] ACPI: RISCV: Enable ACPI based NUMA
Quoted 11 lines · Sunil V L
Quoted 9 lines · Tony
Quoted 8 lines
Quoted 5 lines
If the firmware didn't provide the SRAT/SLIT on ACPI based systems, then there will be a message "Failed to initialise from firmware" from
arch_acpi_numa_init(). This is not specific to RISC-V. But I am wondering why should it bepr_infoinstead ofpr_debug.My understanding is maybe it just wants to expose explicit logs to avoid any potential bugs from FW or Kernel.
Quoted 8 lines
Quoted 4 lines
There are lots of ACPI enabled systems that aren't NUMA (single socket servers, desktops, laptops). Making this "
pr_info()" would just add noise to the boot on all of those.Exactly. But this is an existing
pr_infomessage across architectures. My suggestion is to add one more patch in this series to convert this topr_debugunless someone has strong reason to keep itpr_info.
Sure. I will add a patch to fix it in v3.
Thanks,
Haibo
Quoted 2 lines
Thanks,
Sunil
Hi @Sunil V L,
Could you please have a review on this patch set?
Thanks,
Haibo
Quoted 102 lines · Haibo Xu
This patch series enable RISC-V ACPI NUMA support which was based on the recently approved ACPI ECR[1].
Patch 1/6 is generated from the acpica PR[2] and should be merged through the acpica project. Due to this dependency, other 5 patches can only be merged after the corresponding ACPICA patch was pulled into linux.
Patch 2/6 add RISC-V specific
acpi_numa.cfile to parse NUMA information from SRAT and SLIT ACPI tables.
Patch 3/6 add the common SRAT RINTC affinity structure handler. Patch 4/6 remove the '#ifdefined(CONFIG_ARCH)' condition to make some NUMA related parse functions common for all current architectures that supportACPI_NUMA
Patch 5/6 remove ARCH depends option inACPI_NUMAKconfigwhich was no longer needed since all the current architectures that support ACPI would selectACPI_NUMAby default.
Patch 6/6 add correspondingACPI_NUMAconfig for RISC-VKconfig.Based-on: https://github.com/linux-riscv/linux-riscv/tree/for-next
[1] https://drive.google.com/file/d/1YTdDx2IPm5IeZjAW932EYU-tUtgS08tX/view?usp=sharing
[2] https://github.com/acpica/acpica/pull/926Testing:
Since the ACPI AIA/PLIC support patch set is still under upstream review, hence it is tested using the poll based HVC SBI console and RAM disk.
1) Build latest Qemu with the following patch backported
https://lore.kernel.org/all/[email protected]/
https://github.com/vlsunil/qemu/commit/42bd4eeefd5d4410a68f02d54fee406d8a1269b02) Build latest EDK-II
https://github.com/tianocore/edk2/blob/master/OvmfPkg/RiscVVirt/README.md3) Build Linux with the following configs enabled
CONFIG_RISCV_SBI_V01=y
CONFIG_SERIAL_EARLYCON_RISCV_SBI=y
CONFIG_HVC_RISCV_SBI=y
CONFIG_NUMA=y
CONFIG_ACPI_NUMA=y4) Build buildroot rootfs.cpio
5) Launch the Qemu machine
qemu-system-riscv64 -nographic \ -machine virt,pflash0=pflash0,pflash1=pflash1 -smp 4 -m 8G \ -blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \ -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \ -object memory-backend-ram,size=4G,id=m0 \ -object memory-backend-ram,size=4G,id=m1 \ -numa node,memdev=m0,cpus=0-1,nodeid=0 \ -numa node,memdev=m1,cpus=2-3,nodeid=1 \ -numa dist,src=0,dst=1,val=30 \ -kernel linux/arch/riscv/boot/Image \ -initrd buildroot/output/images/rootfs.cpio \ -append "root=/dev/ram ro console=hvc0 earlycon=sbi"[ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x80000000-0x17fffffff] [ 0.000000] ACPI: SRAT: Node 1 PXM 1 [mem 0x180000000-0x27fffffff] [ 0.000000] NUMA: NODE_DATA [mem 0x17fe3bc40-0x17fe3cfff] [ 0.000000] NUMA: NODE_DATA [mem 0x27fff4c40-0x27fff5fff] ... [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x0 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 0 -> HARTID 0x1 -> Node 0 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x2 -> Node 1 [ 0.000000] ACPI: NUMA: SRAT: PXM 1 -> HARTID 0x3 -> Node 1---
Changes since v1
- Switch the order of patch 2/4 and 3/4 - Per Sunil's suggestion
- Add a new patch 4/6 to make some NUMA related parse functions common for all the architectures that support ACPI NUMA - Per Sunil's suggestion
- Add a new patch 5/6 to remove ARCH depends option inACPI_NUMAKconfigsince all the current architectures that support ACPI would selectACPI_NUMAby default - Per Arnd and Sunil's suggestion
- Other minor fix for code format - Per Sunil's commentsHaibo Xu (6):
ACPICA: SRAT: Add RISC-V RINTC affinity structure
ACPI: RISCV: Add NUMA support based on SRAT and SLIT
ACPI: NUMA: Add handler for SRAT RINTC affinity structure
ACPI: NUMA: Make some NUMA related parse functions common
ACPI: NUMA: Remove ARCH depends option inACPI_NUMAKconfig
ACPI: RISCV: Enable ACPI based NUMAarch/riscv/Kconfig | 1 + arch/riscv/include/asm/acpi.h | 15 +++- arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/acpi.c | 5 -- arch/riscv/kernel/acpi_numa.c | 131 ++++++++++++++++++++++++++++++++++ arch/riscv/kernel/setup.c | 4 +- arch/riscv/kernel/smpboot.c | 2 - drivers/acpi/numa/Kconfig | 1 - drivers/acpi/numa/srat.c | 40 ++++++++--- include/acpi/actbl3.h | 18 ++++- include/linux/acpi.h | 6 ++ 11 files changed, 203 insertions(+), 21 deletions(-) create mode 100644 arch/riscv/kernel/acpi_numa.c--
2.34.1