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 05/17] xen/arm: build NUMA cpu_to_node map in dt_smp_init_cpus
Date: Mon, 20 Nov 2023 10:54:19 +0800	[thread overview]
Message-ID: <20231120025431.14845-6-Henry.Wang@arm.com> (raw)
In-Reply-To: <20231120025431.14845-1-Henry.Wang@arm.com>

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

NUMA implementation has a cpu_to_node array to store CPU to NODE
map. Xen is using CPU logical ID in runtime components, so we
use CPU logical ID as CPU index in cpu_to_node.

In device tree case, cpu_logical_map is created in dt_smp_init_cpus.
So, when NUMA is enabled, dt_smp_init_cpus will fetch CPU NUMA id
at the same time for cpu_to_node.

Signed-off-by: Wei Chen <wei.chen@arm.com>
Signed-off-by: Henry Wang <Henry.Wang@arm.com>
---
v2 -> v6:
- Rebase on top of staging without code changes.
v1 -> v2:
- Use static inline to replace macros to perform
  function paramerters type check.
- Add numa_disabled to gate the numa-node-id check for
  CONFIG_NUMA on but numa disabled user case.
- Use macro instead of static inline function to stub
  numa_set_node.
---
 xen/arch/arm/include/asm/numa.h |  4 ++++
 xen/arch/arm/smpboot.c          | 36 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/xen/arch/arm/include/asm/numa.h b/xen/arch/arm/include/asm/numa.h
index 96c856a9f7..97d4a67dea 100644
--- a/xen/arch/arm/include/asm/numa.h
+++ b/xen/arch/arm/include/asm/numa.h
@@ -68,6 +68,10 @@ static inline bool arch_numa_broken(void)
     return true;
 }
 
+static inline void numa_set_node(unsigned int cpu, nodeid_t node)
+{
+}
+
 #endif
 
 #define arch_want_default_dmazone() (false)
diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 5533aed455..81574ae0ad 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -119,7 +119,12 @@ static void __init dt_smp_init_cpus(void)
     {
         [0 ... NR_CPUS - 1] = MPIDR_INVALID
     };
+    static nodeid_t node_map[NR_CPUS] __initdata =
+    {
+        [0 ... NR_CPUS - 1] = NUMA_NO_NODE
+    };
     bool bootcpu_valid = false;
+    unsigned int nid = 0;
     int rc;
 
     mpidr = system_cpuinfo.mpidr.bits & MPIDR_HWID_MASK;
@@ -170,6 +175,28 @@ static void __init dt_smp_init_cpus(void)
             continue;
         }
 
+        if ( IS_ENABLED(CONFIG_NUMA) )
+        {
+            /*
+             * When CONFIG_NUMA is set, try to fetch numa infomation
+             * from CPU dts node, otherwise the nid is always 0.
+             */
+            if ( !dt_property_read_u32(cpu, "numa-node-id", &nid) )
+            {
+                printk(XENLOG_WARNING
+                       "cpu[%d] dts path: %s: doesn't have numa information!\n",
+                       cpuidx, dt_node_full_name(cpu));
+                /*
+                 * During the early stage of NUMA initialization, when Xen
+                 * found any CPU dts node doesn't have numa-node-id info, the
+                 * NUMA will be treated as off, all CPU will be set to a FAKE
+                 * node 0. So if we get numa-node-id failed here, we should
+                 * set nid to 0.
+                 */
+                nid = 0;
+            }
+        }
+
         /*
          * 8 MSBs must be set to 0 in the DT since the reg property
          * defines the MPIDR[23:0]
@@ -229,9 +256,13 @@ static void __init dt_smp_init_cpus(void)
         {
             printk("cpu%d init failed (hwid %"PRIregister"): %d\n", i, hwid, rc);
             tmp_map[i] = MPIDR_INVALID;
+            node_map[i] = NUMA_NO_NODE;
         }
         else
+        {
             tmp_map[i] = hwid;
+            node_map[i] = nid;
+        }
     }
 
     if ( !bootcpu_valid )
@@ -247,6 +278,11 @@ static void __init dt_smp_init_cpus(void)
             continue;
         cpumask_set_cpu(i, &cpu_possible_map);
         cpu_logical_map(i) = tmp_map[i];
+
+        nid = node_map[i];
+        if ( nid >= MAX_NUMNODES )
+            nid = 0;
+        numa_set_node(i, nid);
     }
 }
 
-- 
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 ` Henry Wang [this message]
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 ` [PATCH v6 07/17] xen/arm: introduce a helper to parse device tree processor node Henry Wang
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-6-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.