[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 08/24] xen/sched: Link CPU topology to scheduler and display via xl info


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Date: Mon, 1 Jun 2026 07:47:38 +0900
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=valinux.co.jp; dmarc=pass action=none header.from=valinux.co.jp; dkim=pass header.d=valinux.co.jp; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eDDYgiA7UEf0V5xxwFfRaXTUj6xHA+tLO+dwu2CP7mc=; b=qSLtyfi5XDFGixU4sF9Nnh4QnNSIFGHRF/dGMWa9EIyOS5UQl9nR0PKZRk5CDUpJXp8OAPEjYhWrVIp17C0uS8o1d6qs1E0HpgzRlwYNPbTUIjo4eM/k89kZwmh+pCoJt4uAHxb788b7NbPS5sEnsVnBWypPLu2YX4j/EhxitbofaH9/DPCy2bhmDTorn7EUdkKe5pjvRA3kiYodTQ3lZZAaFfUn+hK1BcX4mpZOAt7qG54aXvbLA+gDPhMmw+893tSBytc2UOWbYr0eg4bz/p7wUu87uF0e/2f9g01wRIht9VGKO9hiy3zhi/jVpPSGhaNmvaX6NaIIfBY61hECBA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YJncUA6ScRXyGcuA5hcsbN1H4MDTGa0PYkmhjUx9CJKEV3z2z+BnGvIe/GLRjFsFUanXyDwwr5lK/ubhUKnM7R9IUNtksSylw8xgSqB5B+oSHyozscdbWQ82s7s3JZO+K6ZkZR6z75bk8+6+OkWMEth3mNn4A4KW+WFnBN3+9R8Wen1syuT5uK+PpmRX/aSep/Cd8kTxUhFWk24SkjMycoHt6BYeWitqD7VPUlirHrcO3X0mN4yzIl0ihmguUxrSbj2yP19aE5EazJMIoj0EEMAYgXriW8telql8cFHD3timouGCiGX5OMkJlwMWX9i9TYfTgsFQKBCCs/2h0YrSBQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=valinux.co.jp header.i="@valinux.co.jp" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>
  • Delivery-date: Sun, 31 May 2026 22:48:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Make CPU topology information available to the Xen scheduler.
Additionally, ensure that this topology information is displayed
when executing the 'xl info -n' command.
---
 xen/arch/arm/include/asm/processor.h  |  4 --
 xen/arch/arm/smpboot.c                | 10 +++--
 xen/common/device-tree/cpu-topology.c | 54 +++++++++++++++++++++++++++
 xen/common/sched/credit2.c            |  3 ++
 xen/common/sysctl.c                   |  1 +
 xen/include/xen/cpu-topology.h        | 11 ++++++
 6 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/xen/arch/arm/include/asm/processor.h 
b/xen/arch/arm/include/asm/processor.h
index 895d7cd502..b968a1605e 100644
--- a/xen/arch/arm/include/asm/processor.h
+++ b/xen/arch/arm/include/asm/processor.h
@@ -591,10 +591,6 @@ void show_stack(const struct cpu_user_regs *regs);
 
 #define cpu_relax() barrier() /* Could yield? */
 
-/* All a bit UP for the moment */
-#define cpu_to_core(_cpu)   (0)
-#define cpu_to_socket(_cpu) (0)
-
 struct vcpu;
 void vcpu_regs_hyp_to_user(const struct vcpu *vcpu,
                            struct vcpu_guest_core_regs *regs);
diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 6bcf7e7f53..a8e914523d 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -93,13 +93,17 @@ static int setup_cpu_sibling_map(int cpu)
          !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
         return -ENOMEM;
 
+#ifdef CONFIG_DT_CPU_TOPOLOGY
+    cpumask_copy(per_cpu(cpu_sibling_mask, cpu), 
&cpu_topology[cpu].thread_sibling);
+    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_topology[cpu].core_sibling);
+#else /* CONFIG_DT_CPU_TOPOLOGY */
     /*
-     * Currently we assume there is no multithread and NUMA, so
-     * a CPU is a sibling with itself, and the all possible CPUs
-     * are supposed to belong to the same socket (NUMA node).
+     * If CONFIG_DT_CPU_TOPOLOGY is disabled, it is assumed that
+     * all CPUs reside in the same socket and that SMT is not used.
      */
     cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
     cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_possible_map);
+#endif /* CONFIG_DT_CPU_TOPOLOGY */
 
     return 0;
 }
diff --git a/xen/common/device-tree/cpu-topology.c 
b/xen/common/device-tree/cpu-topology.c
index 82a366f3f6..8821ea94f1 100644
--- a/xen/common/device-tree/cpu-topology.c
+++ b/xen/common/device-tree/cpu-topology.c
@@ -294,6 +294,58 @@ int __init parse_dt_topology(void)
     return parse_socket(map);
 }
 
+static void __init setup_topology_for_sched(void)
+{
+    int prev_socketid = 0;
+    int prev_clusterid = 0;
+    int prev_coreid = 0;
+    int prev_threadid = 0;
+    unsigned int coreid = 0U;
+    unsigned int socketid = 0U;
+    unsigned int clusterid = 0U;
+    unsigned int threadid = 0U;
+    int cpu;
+
+    for_each_possible_cpu(cpu)
+    {
+        struct cpu_topology *cpu_topo = &cpu_topology[cpu];
+
+        if (cpu_topo->package_id != prev_socketid)
+        {
+            prev_socketid = cpu_topo->package_id;
+            prev_clusterid = cpu_topo->cluster_id;
+            prev_coreid = cpu_topo->core_id;
+            socketid++;
+            clusterid++;
+            coreid++;
+            threadid++;
+        }
+        else if (cpu_topo->cluster_id != prev_clusterid)
+        {
+            prev_clusterid = cpu_topo->cluster_id;
+            prev_coreid = cpu_topo->core_id;
+            clusterid++;
+            coreid++;
+            threadid++;
+        }
+        else if (cpu_topo->core_id != prev_coreid)
+        {
+            prev_coreid = cpu_topo->core_id;
+            coreid++;
+            threadid++;
+        }
+        else if (cpu_topo->thread_id != prev_threadid)
+        {
+            threadid++;
+        }
+
+        cpu_topo->phys_socket_id = socketid;
+        cpu_topo->phys_core_id = coreid;
+        cpu_topo->num_siblings = cpumask_weight(&cpu_topo->thread_sibling);
+    }
+
+}
+
 void __init dt_init_cpu_topology(void)
 {
     int cpu;
@@ -303,4 +355,6 @@ void __init dt_init_cpu_topology(void)
 
     for_each_possible_cpu(cpu)
         setup_siblings_masks(cpu);
+
+    setup_topology_for_sched();
 }
diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c
index 77475ee363..dcce1e361f 100644
--- a/xen/common/sched/credit2.c
+++ b/xen/common/sched/credit2.c
@@ -19,6 +19,7 @@
 #include <xen/softirq.h>
 #include <xen/time.h>
 #include <xen/trace.h>
+#include <xen/cpu-topology.h>
 
 #include <asm/div64.h>
 
@@ -37,6 +38,8 @@ static unsigned int cpu_nr_siblings(unsigned int cpu)
 {
 #ifdef CONFIG_X86
     return cpu_data[cpu].x86_num_siblings;
+#elif CONFIG_DT_CPU_TOPOLOGY
+    return cpu_topology[cpu].num_siblings;
 #else
     return 1;
 #endif
diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c
index 5207664252..81a68fe24c 100644
--- a/xen/common/sysctl.c
+++ b/xen/common/sysctl.c
@@ -28,6 +28,7 @@
 #include <xen/pmstat.h>
 #include <xen/livepatch.h>
 #include <xen/coverage.h>
+#include <xen/cpu-topology.h>
 
 long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h
index 8445f5786d..828c31f7ee 100644
--- a/xen/include/xen/cpu-topology.h
+++ b/xen/include/xen/cpu-topology.h
@@ -14,6 +14,9 @@ struct cpu_topology {
     cpumask_t thread_sibling;
     cpumask_t core_sibling;
     cpumask_t cluster_sibling;
+    unsigned int phys_core_id;
+    unsigned int phys_socket_id;
+    unsigned int num_siblings;
 };
 
 
@@ -23,11 +26,19 @@ extern struct cpu_topology cpu_topology[NR_CPUS];
 void map_cpuid_to_node(u32 cpuid, struct dt_device_node *cpu_node);
 void dt_init_cpu_topology(void);
 
+#define cpu_to_core(_cpu)   (cpu_topology[_cpu].phys_core_id)
+#define cpu_to_socket(_cpu)   (cpu_topology[_cpu].phys_socket_id)
+#define cpu_nr_siblings(_cpu) (cpu_topology[_cpu].num_siblings)
+
 #elif CONFIG_DEVICE_TREE_PARSE
 
 static inline void map_cpuid_to_node(u32 cpuid, struct dt_device_node 
*cpu_node) {}
 static inline void dt_init_cpu_topology(void) {}
 
+#define cpu_to_core(_cpu)   (0)
+#define cpu_to_socket(_cpu) (0)
+#define cpu_nr_siblings(_cpu) (1)
+
 #endif /* CONFIG_DEVICE_TREE_PARSE */
 
 #endif /* XEN_CPU_TOPOLOGY_H */
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.