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

[PATCH v14 2/4] xen/sched: Link CPU topology to scheduler


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
  • Date: Wed, 2 Dec 2026 16:31:33 +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=o3NgC/2cObahSBHiLGgT1QWdeZNUVr/7ofu2L+HROFY=; b=Hyl/QkUNqFz3ZdkFrWIYEmfeVs50eDX/UbAgKkTomS/toA95PHdFbGMe0M+OsADdYLlgaeU/yPbwTTiAiZ2ry8wVuvRElhktxVUgoI54ZCwafQFuQSb85ZVxwO0z2PLqlG5K4hsyxSaFdKWFdhA/ShjibPf5fUE2DRkBiZLzJZ0P1QuA/jk7K3H2kRpSqKae8QRUazDUc4eNJ2pK3MvOMvMBF7sKtDR29vG7sy3Sqqv8BXdSAWadnxU62/s97e4Rmgzzqi1ckh8zgLDK2EAh1XXmzTUUT/VGx8/TH/hb1WTX7LOTaoOAvH5fQ7ZkoI4IaeC9DASSQhFPbfg2GjA9Jw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ce5V7jPx+oiCnHfs0Oxvv3BnmJN4wvaZlJz4zAlrkAXdl2CdDZEzFEGLNB9d2IJ+BvPuJfFtZ7Uqx7kX+98kj5Kg0DQtUtuZ4TfCIyMN1SHhIAg8Ss9rxxp4gXnyalWp7zhs1ixF8FsHzEDiUsYJuSGTCBhvjyUMhulO3FGxBSHJIm/d1R0sdgqqQza6fwJmCGktIVniwVA2yPS+8NkKzO302UcRC1/cuudSFq/MaYAog676ztSsbdefWtYRQSC/XDPTBZg/bA6vNmCeQ7Z4D8S+eY4BarxJskQc2bQSadthvueuj4L9IjXiR+IU+wordWu3xr7Fl7p0/8PK+WBwxg==
  • 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: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=valinux.co.jp;
  • Cc: michal.orzel@xxxxxxx, jbeulich@xxxxxxxx, Hirokazu Takahashi <taka@xxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Timothy Pearson <tpearson@xxxxxxxxxxxxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>
  • Delivery-date: Wed, 02 Dec 2026 07:32:19 +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.

Signed-off-by: Hirokazu Takahashi <taka@xxxxxxxxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
Acked-by: Michal Orzel <michal.orzel@xxxxxxx>
Reviewed-by: Juergen Gross <jgross@xxxxxxxx> # scheduler part
---
Changes in v14:
- Remove the stale comment stating that Xen on Arm does not support
  multithreading.

 xen/arch/arm/include/asm/processor.h   |  4 ---
 xen/arch/arm/smpboot.c                 | 39 +++++++++++++++++---------
 xen/arch/ppc/include/asm/processor.h   |  4 ---
 xen/arch/riscv/include/asm/processor.h |  4 ---
 xen/common/device-tree/cpu-topology.c  |  5 ++++
 xen/common/sched/credit2.c             |  6 ++++
 xen/common/sysctl.c                    |  1 +
 xen/drivers/acpi/cpu-topology.c        |  3 ++
 xen/include/xen/cpu-topology.h         | 24 ++++++++++++++--
 9 files changed, 62 insertions(+), 28 deletions(-)

diff --git a/xen/arch/arm/include/asm/processor.h 
b/xen/arch/arm/include/asm/processor.h
index 8ee8f88fb4..fe4125cd75 100644
--- a/xen/arch/arm/include/asm/processor.h
+++ b/xen/arch/arm/include/asm/processor.h
@@ -614,10 +614,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 97e227cd92..baf1136fee 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -70,11 +70,6 @@ static bool cpu_is_dead;
 
 /* ID of the PCPU we're running on */
 DEFINE_PER_CPU(unsigned int, cpu_id);
-/*
- * Although multithread is part of the Arm spec, there are not many
- * processors supporting multithread and current Xen on Arm assumes there
- * is no multithread.
- */
 /* representing HT siblings of each logical CPU */
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_mask);
 /* representing HT and core siblings of each logical CPU */
@@ -103,17 +98,30 @@ static void set_cpu_sibling_map(unsigned int cpu)
     BUG_ON(!per_cpu(cpu_sibling_mask, cpu));
     BUG_ON(!per_cpu(cpu_core_mask, cpu));
 
-    /*
-     * Currently we assume there is no multithread and NUMA, so
-     * a CPU is a sibling with itself, and the all online CPUs
-     * are supposed to belong to the same socket (NUMA node).
-     */
+    if ( IS_ENABLED(CONFIG_GENERIC_CPU_TOPOLOGY) && cpu_topology )
+    {
+        cpumask_and(per_cpu(cpu_sibling_mask, cpu), &cpu_online_map,
+                    cpu_topology[cpu].thread_sibling);
+
+        for_each_cpu(sibling, per_cpu(cpu_sibling_mask, cpu))
+            cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, sibling));
+
+        cpumask_and(per_cpu(cpu_core_mask, cpu), &cpu_online_map,
+                    cpu_topology[cpu].core_sibling);
+
+        for_each_cpu(sibling, per_cpu(cpu_core_mask, cpu))
+            cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, sibling));
+    }
+    else
+    {
+        cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_online_map);
+
+        for_each_online_cpu(sibling)
+            cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, sibling));
+    }
+
     cpumask_set_cpu(cpu, per_cpu(cpu_sibling_mask, cpu));
-    cpumask_copy(per_cpu(cpu_core_mask, cpu), &cpu_online_map);
     cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, cpu));
-
-    for_each_online_cpu(sibling)
-        cpumask_set_cpu(cpu, per_cpu(cpu_core_mask, sibling));
 }
 
 static void remove_siblinginfo(unsigned int cpu)
@@ -123,6 +131,9 @@ static void remove_siblinginfo(unsigned int cpu)
     for_each_cpu(sibling, per_cpu(cpu_core_mask, cpu))
         cpumask_clear_cpu(cpu, per_cpu(cpu_core_mask, sibling));
 
+    for_each_cpu(sibling, per_cpu(cpu_sibling_mask, cpu))
+        cpumask_clear_cpu(cpu, per_cpu(cpu_sibling_mask, sibling));
+
     cpumask_clear(per_cpu(cpu_sibling_mask, cpu));
     cpumask_clear(per_cpu(cpu_core_mask, cpu));
 }
diff --git a/xen/arch/ppc/include/asm/processor.h 
b/xen/arch/ppc/include/asm/processor.h
index 242346cab9..1bf6f6c66c 100644
--- a/xen/arch/ppc/include/asm/processor.h
+++ b/xen/arch/ppc/include/asm/processor.h
@@ -141,10 +141,6 @@
 /* Macro to adjust thread priority for hardware multithreading */
 #define HMT_very_low()  asm volatile ( "or %r31, %r31, %r31" )
 
-/* TODO: This isn't correct */
-#define cpu_to_core(cpu)   (0)
-#define cpu_to_socket(cpu) (0)
-
 /*
  * User-accessible registers: most of these need to be saved/restored
  * for every nested Xen invocation.
diff --git a/xen/arch/riscv/include/asm/processor.h 
b/xen/arch/riscv/include/asm/processor.h
index 007c22d2e6..5a0d351974 100644
--- a/xen/arch/riscv/include/asm/processor.h
+++ b/xen/arch/riscv/include/asm/processor.h
@@ -52,10 +52,6 @@ struct cpu_user_regs
     unsigned long hstatus;
 };
 
-/* TODO: need to implement */
-#define cpu_to_core(cpu)   0
-#define cpu_to_socket(cpu) 0
-
 static inline void cpu_relax(void)
 {
 #ifdef __riscv_zihintpause
diff --git a/xen/common/device-tree/cpu-topology.c 
b/xen/common/device-tree/cpu-topology.c
index 556c1b9816..a04d9f15c4 100644
--- a/xen/common/device-tree/cpu-topology.c
+++ b/xen/common/device-tree/cpu-topology.c
@@ -349,7 +349,10 @@ static int __init parse_dt_topology(void)
 }
 
 <<<<<<< HEAD
+<<<<<<< HEAD
+=======
 =======
+>>>>>>> 8d3d2f8bf2 (xen/sched: Link CPU topology to scheduler)
 static void __init setup_cpu_topology_ids(void)
 {
     unsigned int cpu;
@@ -432,6 +435,8 @@ int __init dt_init_cpu_topology(void)
     for_each_possible_cpu(cpu)
         setup_siblings_masks(cpu);
 
+    setup_cpu_topology_ids();
+
     return 0;
 }
 
diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c
index 042168e531..be20ca316b 100644
--- a/xen/common/sched/credit2.c
+++ b/xen/common/sched/credit2.c
@@ -9,6 +9,7 @@
  * Based on an earlier verson by Emmanuel Ackaouy.
  */
 
+#include <xen/cpu-topology.h>
 #include <xen/errno.h>
 #include <xen/init.h>
 #include <xen/lib.h>
@@ -35,6 +36,11 @@
  */
 static unsigned int cpu_nr_siblings(unsigned int cpu)
 {
+#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
+    if ( cpu_topology )
+        return cpu_topology[cpu].num_siblings;
+#endif
+
 #ifdef CONFIG_X86
     return cpu_data[cpu].x86_num_siblings;
 #else
diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c
index 8fb5ff0af3..6f1839b359 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/drivers/acpi/cpu-topology.c b/xen/drivers/acpi/cpu-topology.c
index f9836447b2..32f5b97c3e 100644
--- a/xen/drivers/acpi/cpu-topology.c
+++ b/xen/drivers/acpi/cpu-topology.c
@@ -24,6 +24,9 @@ int __init acpi_init_cpu_topology(void)
     {
         struct cpu_topology *topo = &cpu_topology[cpu];
 
+        topo->phys_core_id = cpu;
+        topo->num_siblings = 1;
+
         cpumask_set_cpu(cpu, topo->thread_sibling);
         cpumask_copy(topo->core_sibling, &cpu_possible_map);
         cpumask_copy(topo->cluster_sibling, &cpu_possible_map);
diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h
index 27b9bd443e..e70d14b581 100644
--- a/xen/include/xen/cpu-topology.h
+++ b/xen/include/xen/cpu-topology.h
@@ -3,23 +3,43 @@
 #ifndef XEN_CPU_TOPOLOGY_H
 #define XEN_CPU_TOPOLOGY_H
 
-#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
-
 #include <xen/cpumask.h>
+#include <xen/percpu.h>
+
+#include <asm/processor.h>
+#include <asm/smp.h>
 
 struct cpu_topology {
     cpumask_var_t thread_sibling;
     cpumask_var_t core_sibling;
     cpumask_var_t cluster_sibling;
+    unsigned int phys_core_id;
+    unsigned int phys_cluster_id;
+    unsigned int phys_socket_id;
+    unsigned int num_siblings;
 };
 
 extern struct cpu_topology *cpu_topology;
+
+#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
+
 void init_cpu_topology(void);
 
+#define cpu_to_core(cpu) (cpu_topology ? cpu_topology[cpu].phys_core_id : 0)
+#define cpu_to_socket(cpu) (cpu_topology ? cpu_topology[cpu].phys_socket_id : 
0)
+
 #else /* CONFIG_GENERIC_CPU_TOPOLOGY */
 
 static inline void init_cpu_topology(void) {}
 
+#ifndef cpu_to_core
+#define cpu_to_core(cpu)   (0)
+#endif
+
+#ifndef cpu_to_socket
+#define cpu_to_socket(cpu) (0)
+#endif
+
 #endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
 
 #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®.