[PATCH v4 1/4] ACPI: RISCV: Add NUMA support based on SRAT and SLIT

Haibo Xu xiaobo55x at gmail.com
Tue Jul 23 07:53:59 PDT 2024


On Tue, Jul 23, 2024 at 10:50 PM Anup Patel <apatel at ventanamicro.com> wrote:
>
> On Tue, Jul 23, 2024 at 7:51 PM Haibo Xu <xiaobo55x at gmail.com> wrote:
> >
> > On Tue, Jul 23, 2024 at 9:30 PM Andrew Jones <ajones at ventanamicro.com> wrote:
> > >
> > > On Thu, Jun 13, 2024 at 04:54:33PM GMT, Haibo Xu wrote:
> > > > Add 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.
> > > >
> > > > Signed-off-by: Haibo Xu <haibo1.xu at intel.com>
> > > > Reviewed-by: Sunil V L <sunilvl at ventanamicro.com>
> > > > ---
> > > >  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
> > > >
> > > > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
> > > > index 7dad0cf9d701..e0a1f84404f3 100644
> > > > --- a/arch/riscv/include/asm/acpi.h
> > > > +++ b/arch/riscv/include/asm/acpi.h
> > > > @@ -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*/
> > > > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> > > > index 5b243d46f4b1..1e2afec141b5 100644
> > > > --- a/arch/riscv/kernel/Makefile
> > > > +++ b/arch/riscv/kernel/Makefile
> > > > @@ -110,3 +110,4 @@ obj-$(CONFIG_COMPAT)              += compat_vdso/
> > > >
> > > >  obj-$(CONFIG_64BIT)          += pi/
> > > >  obj-$(CONFIG_ACPI)           += acpi.o
> > > > +obj-$(CONFIG_ACPI_NUMA)      += acpi_numa.o
> > > > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
> > > > index e619edc8b0cc..040bdbfea2b4 100644
> > > > --- a/arch/riscv/kernel/acpi.c
> > > > +++ b/arch/riscv/kernel/acpi.c
> > > > @@ -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.
> > > > diff --git a/arch/riscv/kernel/acpi_numa.c b/arch/riscv/kernel/acpi_numa.c
> > > > new file mode 100644
> > > > index 000000000000..0231482d6946
> > > > --- /dev/null
> > > > +++ b/arch/riscv/kernel/acpi_numa.c
> > > > @@ -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 <hanjun.guo at linaro.org>
> > > > + * 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 };
> > >
> > > This only sets acpi_early_node_map[0] to NUMA_NO_NODE. Assuming we want
> > > to ensure all of them are initialized to NUMA_NO_NODE, then we need
> > >
> > > static int acpi_early_node_map[NR_CPUS] __initdata = { [0 ... NR_CPUS - 1] = NUMA_NO_NODE };
> > >
> >
> > Good catch! Thanks!
> >
> > @Palmer Dabbelt
> > I noticed this series had been merged to riscv/linux.git (for-next),
> > could you help include the above change from Drew?
> > Or shall I send out a new series?
>
> Since it's already in for-next, I suggest having a Fixes
> patch and add that to for-next because for-next is supposed
> to have a stable commit history.
>

Ok, I will send out the fix soon! Thanks!

> Regards,
> Anup



More information about the linux-arm-kernel mailing list