All of lore.kernel.org
 help / color / mirror / Atom feed
From: Henry Wang <Henry.Wang@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Wei Chen <wei.chen@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Henry Wang <Henry.Wang@arm.com>
Subject: [PATCH v6 07/17] xen/arm: introduce a helper to parse device tree processor node
Date: Mon, 20 Nov 2023 10:54:21 +0800	[thread overview]
Message-ID: <20231120025431.14845-8-Henry.Wang@arm.com> (raw)
In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com>

From: Wei Chen <wei.chen@arm.com>

Processor NUMA ID information is stored in device tree's processor
node as "numa-node-id". We need a new helper to parse this ID from
processor node. If we get this ID from processor node, this ID's
validity still need to be checked. Once we got a invalid NUMA ID
from any processor node, the device tree will be marked as NUMA
information invalid.

Since new helpers need to know the NUMA status, move the
enum dt_numa_status to the Arm NUMA header.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Signed-off-by: Henry Wang <Henry.Wang@arm.com>
---
v5 -> v6:
- Rebase on top of staging without code changes.
v3 -> v5:
- Rename "numa_device_tree.c" to "numa-dt.c".
v2 -> v3:
- Move the enum dt_numa_status to the Arm NUMA header.
- Update the year in copyright to 2023.
v1 -> v2:
- Move numa_disabled from fdt_numa_processor_affinity_init
  to fdt_parse_numa_cpu_node.
- Move invalid NUMA id check to fdt_parse_numa_cpu_node.
- Return ENODATA for normal dtb without NUMA info.
- Use NUMA status helpers instead of SRAT functions.
---
 xen/arch/arm/Makefile           |  1 +
 xen/arch/arm/include/asm/numa.h |  8 +++++
 xen/arch/arm/numa-dt.c          | 64 +++++++++++++++++++++++++++++++++
 xen/arch/arm/numa.c             |  8 +----
 4 files changed, 74 insertions(+), 7 deletions(-)
 create mode 100644 xen/arch/arm/numa-dt.c

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 86e0e47e22..6a4e7814b8 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -39,6 +39,7 @@ obj-y += mem_access.o
 obj-y += mm.o
 obj-y += monitor.o
 obj-$(CONFIG_NUMA) += numa.o
+obj-$(CONFIG_DEVICE_TREE_NUMA) += numa-dt.o
 obj-y += p2m.o
 obj-y += percpu.o
 obj-y += platform.o
diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h
index b04ace26db..2987158d16 100644
--- a/xen/arch/arm/include/asm/numa.h
+++ b/xen/arch/arm/include/asm/numa.h
@@ -22,6 +22,14 @@ typedef u8 nodeid_t;
  */
 #define NR_NODE_MEMBLKS NR_MEM_BANKS
 
+enum dt_numa_status {
+    DT_NUMA_DEFAULT,
+    DT_NUMA_ON,
+    DT_NUMA_OFF,
+};
+
+extern enum dt_numa_status device_tree_numa;
+
 /*
  * In ACPI spec, 0-9 are the reserved values for node distance,
  * 10 indicates local node distance, 20 indicates remote node
diff --git a/xen/arch/arm/numa-dt.c b/xen/arch/arm/numa-dt.c
new file mode 100644
index 0000000000..83601c83e7
--- /dev/null
+++ b/xen/arch/arm/numa-dt.c
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Arm Architecture support layer for device tree NUMA.
+ *
+ * Copyright (C) 2023 Arm Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include <xen/init.h>
+#include <xen/nodemask.h>
+#include <xen/numa.h>
+#include <xen/libfdt/libfdt.h>
+#include <xen/device_tree.h>
+
+/* Callback for device tree processor affinity */
+static int __init fdt_numa_processor_affinity_init(nodeid_t node)
+{
+    numa_set_processor_nodes_parsed(node);
+    device_tree_numa = DT_NUMA_ON;
+
+    printk(KERN_INFO "DT: NUMA node %"PRIu8" processor parsed\n", node);
+
+    return 0;
+}
+
+/* Parse CPU NUMA node info */
+static int __init fdt_parse_numa_cpu_node(const void *fdt, int node)
+{
+    unsigned int nid;
+
+    if ( numa_disabled() )
+        return -EINVAL;
+
+    /*
+     * device_tree_get_u32 will return NUMA_NO_NODE when this CPU
+     * DT node doesn't have numa-node-id. This can help us to
+     * distinguish a bad DTB and a normal DTB without NUMA info.
+     */
+    nid = device_tree_get_u32(fdt, node, "numa-node-id", NUMA_NO_NODE);
+    if ( nid == NUMA_NO_NODE )
+    {
+        numa_fw_bad();
+        return -ENODATA;
+    }
+    else if ( nid >= MAX_NUMNODES )
+    {
+        printk(XENLOG_ERR "DT: CPU NUMA node id %u is invalid\n", nid);
+        numa_fw_bad();
+        return -EINVAL;
+    }
+
+    return fdt_numa_processor_affinity_init(nid);
+}
diff --git a/xen/arch/arm/numa.c b/xen/arch/arm/numa.c
index b5a87531f7..08e15ebbb0 100644
--- a/xen/arch/arm/numa.c
+++ b/xen/arch/arm/numa.c
@@ -20,13 +20,7 @@
 #include <xen/init.h>
 #include <xen/numa.h>
 
-enum dt_numa_status {
-    DT_NUMA_DEFAULT,
-    DT_NUMA_ON,
-    DT_NUMA_OFF,
-};
-
-static enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
+enum dt_numa_status __ro_after_init device_tree_numa = DT_NUMA_DEFAULT;
 
 static unsigned char __ro_after_init
 node_distance_map[MAX_NUMNODES][MAX_NUMNODES] = {
-- 
2.25.1



  parent reply	other threads:[~2023-11-20  2:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20  2:54 [PATCH v6 00/17] Device tree based NUMA support for Arm Henry Wang
2023-11-20  2:54 ` [PATCH v6 01/17] xen/arm: use NR_MEM_BANKS to override default NR_NODE_MEMBLKS Henry Wang
2023-11-20  2:54 ` [PATCH v6 02/17] xen/arm: implement helpers to get and update NUMA status Henry Wang
2024-01-03 15:10   ` Julien Grall
2023-11-20  2:54 ` [PATCH v6 03/17] xen/arm: implement node distance helpers for Arm Henry Wang
2023-11-20  2:54 ` [PATCH v6 04/17] xen/arm: use arch_get_ram_range to get memory ranges from bootinfo Henry Wang
2023-11-20  2:54 ` [PATCH v6 05/17] xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus Henry Wang
2023-11-20  2:54 ` [PATCH v6 06/17] xen/arm: Add boot and secondary CPU to NUMA system Henry Wang
2023-11-20  2:54 ` Henry Wang [this message]
2023-11-20  2:54 ` [PATCH v6 08/17] xen/arm: introduce a helper to parse device tree memory node Henry Wang
2023-11-20  2:54 ` [PATCH v6 09/17] xen/arm: introduce a helper to parse device tree NUMA distance map Henry Wang
2023-11-20  2:54 ` [PATCH v6 10/17] xen/arm: unified entry to parse all NUMA data from device tree Henry Wang
2023-11-20  2:54 ` [PATCH v6 11/17] xen/arm: keep guest still be NUMA unware Henry Wang
2023-11-20  2:54 ` [PATCH v6 12/17] xen/arm: enable device tree based NUMA in system init Henry Wang
2023-11-20  2:54 ` [PATCH v6 13/17] xen/arm: implement numa_node_to_arch_nid for device tree NUMA Henry Wang
2023-11-20  2:54 ` [PATCH v6 14/17] xen/arm: use CONFIG_NUMA to gate node_online_map in smpboot Henry Wang
2023-11-20  2:54 ` [PATCH v6 15/17] xen/arm: Set correct per-cpu cpu_core_mask Henry Wang
2023-11-20  2:54 ` [PATCH v6 16/17] xen/arm: Provide Kconfig options for Arm to enable NUMA Henry Wang
2023-11-20  2:54 ` [PATCH v6 17/17] docs: update numa command line to support Arm Henry Wang
2023-11-20  8:55   ` Jan Beulich
2023-11-20  8:57     ` Henry Wang
2023-11-30  1:06 ` [PATCH v6 00/17] Device tree based NUMA support for Arm Stefano Stabellini
2023-11-30  2:11   ` Henry Wang
2024-01-03 15:14 ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231120025431.14845-8-Henry.Wang@arm.com \
    --to=henry.wang@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=wei.chen@arm.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.