From nobody Thu Nov 6 01:26:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1700448962298491.9199553583204; Sun, 19 Nov 2023 18:56:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.636377.991839 (Exim 4.92) (envelope-from ) id 1r4uRu-0004B5-RL; Mon, 20 Nov 2023 02:55:46 +0000 Received: by outflank-mailman (output) from mailman id 636377.991839; Mon, 20 Nov 2023 02:55:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRu-0004AM-Lf; Mon, 20 Nov 2023 02:55:46 +0000 Received: by outflank-mailman (input) for mailman id 636377; Mon, 20 Nov 2023 02:55:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r4uRi-0007WE-Tl for xen-devel@lists.xenproject.org; Mon, 20 Nov 2023 02:55:34 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 457dd832-8750-11ee-9b0e-b553b5be7939; Mon, 20 Nov 2023 03:55:33 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8A6551042; Sun, 19 Nov 2023 18:56:18 -0800 (PST) Received: from a015966.shanghai.arm.com (a015966.shanghai.arm.com [10.169.190.5]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E45863F6C4; Sun, 19 Nov 2023 18:55:29 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 457dd832-8750-11ee-9b0e-b553b5be7939 From: Henry Wang To: xen-devel@lists.xenproject.org Cc: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v6 12/17] xen/arm: enable device tree based NUMA in system init Date: Mon, 20 Nov 2023 10:54:26 +0800 Message-Id: <20231120025431.14845-13-Henry.Wang@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com> References: <20231120025431.14845-1-Henry.Wang@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1700448964270100001 Content-Type: text/plain; charset="utf-8" From: Wei Chen In this patch, we can start to create NUMA system that is based on device tree. Signed-off-by: Wei Chen Signed-off-by: Henry Wang --- v5 -> v6: - Rebase on top of staging without code changes. v1 -> v5: - Fix coding style: label indented by 1 space. - replace ~0 by INVALID_PADDR. - only print error messages for invalid dtb data. - remove unnecessary return. - remove the parameter of numa_init. --- xen/arch/arm/include/asm/numa.h | 5 +++ xen/arch/arm/numa.c | 57 +++++++++++++++++++++++++++++++++ xen/arch/arm/setup.c | 7 ++++ 3 files changed, 69 insertions(+) diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/num= a.h index 15308f5a36..55ac4665db 100644 --- a/xen/arch/arm/include/asm/numa.h +++ b/xen/arch/arm/include/asm/numa.h @@ -45,6 +45,7 @@ extern void numa_set_distance(nodeid_t from, nodeid_t to, unsigned int distance); extern void numa_detect_cpu_node(unsigned int cpu); extern int numa_device_tree_init(const void *fdt); +extern void numa_init(void); =20 #else =20 @@ -90,6 +91,10 @@ static inline void numa_detect_cpu_node(unsigned int cpu) { } =20 +static inline void numa_init(void) +{ +} + #endif =20 #define arch_want_default_dmazone() (false) diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c index 08e15ebbb0..13a167fc4f 100644 --- a/xen/arch/arm/numa.c +++ b/xen/arch/arm/numa.c @@ -18,7 +18,11 @@ * */ #include +#include +#include #include +#include +#include =20 enum dt_numa_status __ro_after_init device_tree_numa =3D DT_NUMA_DEFAULT; =20 @@ -104,6 +108,59 @@ unsigned char __node_distance(nodeid_t from, nodeid_t = to) return node_distance_map[from][to]; } =20 +void __init numa_init(void) +{ + unsigned int idx; + paddr_t ram_start =3D INVALID_PADDR; + paddr_t ram_size =3D 0; + paddr_t ram_end =3D 0; + + /* NUMA has been turned off through Xen parameters */ + if ( numa_off ) + goto mem_init; + + /* Initialize NUMA from device tree when system is not ACPI booted */ + if ( acpi_disabled ) + { + int ret =3D numa_device_tree_init(device_tree_flattened); + if ( ret ) + { + numa_off =3D true; + if ( ret =3D=3D -EINVAL ) + printk(XENLOG_WARNING + "Init NUMA from device tree failed, ret=3D%d\n", re= t); + } + } + else + { + /* We don't support NUMA for ACPI boot currently */ + printk(XENLOG_WARNING + "ACPI NUMA has not been supported yet, NUMA off!\n"); + numa_off =3D true; + } + + mem_init: + /* + * Find the minimal and maximum address of RAM, NUMA will + * build a memory to node mapping table for the whole range. + */ + ram_start =3D bootinfo.mem.bank[0].start; + ram_size =3D bootinfo.mem.bank[0].size; + ram_end =3D ram_start + ram_size; + for ( idx =3D 1 ; idx < bootinfo.mem.nr_banks; idx++ ) + { + paddr_t bank_start =3D bootinfo.mem.bank[idx].start; + paddr_t bank_size =3D bootinfo.mem.bank[idx].size; + paddr_t bank_end =3D bank_start + bank_size; + + ram_size =3D ram_size + bank_size; + ram_start =3D min(ram_start, bank_start); + ram_end =3D max(ram_end, bank_end); + } + + numa_initmem_init(PFN_UP(ram_start), PFN_DOWN(ram_end)); +} + int __init arch_get_ram_range(unsigned int idx, paddr_t *start, paddr_t *e= nd) { if ( idx >=3D bootinfo.mem.nr_banks ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 02bc887725..01affc12d9 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -1124,6 +1124,13 @@ void __init start_xen(unsigned long boot_phys_offset, /* Parse the ACPI tables for possible boot-time configuration */ acpi_boot_table_init(); =20 + /* + * Try to initialize NUMA system, if failed, the system will + * fallback to uniform system which means system has only 1 + * NUMA node. + */ + numa_init(); + end_boot_allocator(); =20 /* --=20 2.25.1