Skip to contentSkip to conversation

xen/arm: Device Tree based CPU topology support

PATCH Superseded Hirokazu Takahashi 2 participants 11 messages Jun 17 – Jun 24

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v2 cover xen/arm: Device Tree based CPU topology support

Hello,

This patch series introduces basic CPU topology support for ARM Xen.

Changes in v2:
- Generate topology information even when ACPI is enabled. Note that this is a temporary implementation and doesn't yet parse the PPTT (Processor Properties Topology Table).
- Added support for cpu-map node in Device Tree that doesn't contain explicit cluster node definitions.

Changes in v1 from the previous series "Introduce Device Tree based NUMA support for ARM Xen":

1. Optimized Memory Allocation:
The series now allocates only the minimum required memory area to manage the essential data for the CPUs.

2. Flexible Device Tree Parsing:
The parsing logic no longer depends on the definition order of the 'cpu' nodes and 'cpu-map' nodes in the Device Tree. They can now be read correctly even if their orders do not match.

3. CPU Hotplug Readiness:
To support future CPU hotplug, the system assumes that inactive CPUs are also described in the Device Tree. Xen will pre-load and generate the topology information for these inactive CPUs during the boot phase so it stays available in memory.

Thank you,
Hirokazu Takahashi

Hirokazu Takahashi (3):
xen/device-tree: Parse 'cpu-map' node for CPU topology exploration xen/sched: Link CPU topology to scheduler
xen/sched: Make cpu_nr_siblings() architecture-specific

 xen/arch/arm/Kconfig                  |  11 +
 xen/arch/arm/include/asm/processor.h  |   4 -
 xen/arch/arm/smpboot.c                |  15 +-
 xen/arch/x86/include/asm/processor.h  |   1 +
 xen/common/Kconfig                    |   8 +
 xen/common/Makefile                   |   1 +
 xen/common/cpu-topology.c             |  30 ++
 xen/common/device-tree/Makefile       |   1 +
 xen/common/device-tree/cpu-topology.c | 394 ++++++++++++++++++++++++++
 xen/common/sched/credit2.c            |  21 +-
 xen/common/sysctl.c                   |   1 +
 xen/drivers/acpi/Kconfig              |   3 +
 xen/drivers/acpi/Makefile             |   2 +
 xen/drivers/acpi/topology.c           |  41 +++
 xen/include/xen/acpi.h                |   4 +
 xen/include/xen/cpu-topology.h        |  48 ++++
 xen/include/xen/dt-cpu-topology.h     |  30 ++
 17 files changed, 591 insertions(+), 24 deletions(-)
 create mode 100644 xen/common/cpu-topology.c
 create mode 100644 xen/common/device-tree/cpu-topology.c
 create mode 100644 xen/drivers/acpi/topology.c
 create mode 100644 xen/include/xen/cpu-topology.h
 create mode 100644 xen/include/xen/dt-cpu-topology.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 xen/device-tree: Parse 'cpu-map' node for CPU topology exploration

Parse the 'cpu-map' node in the Device Tree to extract CPU topology information. If the 'cpu-map' node is absent, fall back to generating the topology data from the NUMA information. This generation assumes exactly one socket per NUMA node and that SMT is unsupported.

---
 xen/arch/arm/Kconfig                  |  11 +
 xen/arch/arm/smpboot.c                |   5 +
 xen/common/Kconfig                    |   8 +
 xen/common/Makefile                   |   1 +
 xen/common/cpu-topology.c             |  30 +++
 xen/common/device-tree/Makefile       |   1 +
 xen/common/device-tree/cpu-topology.c | 343 ++++++++++++++++++++++++++
 xen/drivers/acpi/Kconfig              |   3 +
 xen/drivers/acpi/Makefile             |   2 +
 xen/drivers/acpi/topology.c           |  38 +++
 xen/include/xen/acpi.h                |   4 +
 xen/include/xen/cpu-topology.h        |  36 +++
 xen/include/xen/dt-cpu-topology.h     |  30 +++
 13 files changed, 512 insertions(+)
 create mode 100644 xen/common/cpu-topology.c
 create mode 100644 xen/common/device-tree/cpu-topology.c
 create mode 100644 xen/drivers/acpi/topology.c
 create mode 100644 xen/include/xen/cpu-topology.h
 create mode 100644 xen/include/xen/dt-cpu-topology.h
xen/arch/arm/Kconfig +11 -0
index 5fa89fcb24..36574e0ce8 100644
@@ -101,6 +101,17 @@ endchoice
 
 source "arch/Kconfig"
 
+config ARM_CPU_TOPOLOGY
+	bool "CPU topology support (UNSUPPORTED)" if UNSUPPORTED
+	select CPU_TOPOLOGY
+	help
+	  Retrieve CPU topology information from the device tree or
+	  ACPI PPTT (Processor Properties Topology Table) to optimize
+	  virtual CPU scheduling.
+
+	  Note: Implementation for parsing CPU topology from the ACPI PPTT
+	  is currently missing and will be added in the future.
+
 config ACPI
 	bool "ACPI (Advanced Configuration and Power Interface) Support (UNSUPPORTED)" if UNSUPPORTED
 	depends on ARM_64 && ARM_EFI
xen/arch/arm/smpboot.c +5 -0
index 7f3cfa812e..fb2cf26424 100644
@@ -24,6 +24,7 @@
 #include <xen/warning.h>
 #include <xen/irq.h>
 #include <xen/console.h>
+#include <xen/cpu-topology.h>
 #include <asm/cpuerrata.h>
 #include <asm/gic.h>
 #include <asm/procinfo.h>
@@ -242,6 +243,8 @@ static void __init dt_smp_init_cpus(void)
         }
         else
             tmp_map[i] = hwid;
+
+        map_cpuid_to_node(i, cpu); /* pass the info to dt_init_cpu_topology() */
     }
 
     if ( !bootcpu_valid )
@@ -279,6 +282,8 @@ void __init smp_init_cpus(void)
     else
         acpi_smp_init_cpus();
 
+    init_cpu_topology();
+
     if ( opt_hmp_unsafe )
         warning_add("WARNING: HMP COMPUTING HAS BEEN ENABLED.\n"
                     "It has implications on the security and stability of the system,\n"
xen/common/Kconfig +8 -0
index 5ff71480ee..6875dd07b3 100644
@@ -188,6 +188,14 @@ config VM_EVENT
 config NEEDS_LIBELF
 	bool
 
+config DT_CPU_TOPOLOGY
+	bool
+
+config CPU_TOPOLOGY
+	bool
+	select DT_CPU_TOPOLOGY if DEVICE_TREE_PARSE
+	select ACPI_CPU_TOPOLOGY if ACPI
+
 config NUMA
 	bool
 
xen/common/Makefile +1 -0
index 6018e25614..adb406ab5e 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_GENERIC_BUG_FRAME) += bug.o
 obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
+obj-$(CONFIG_CPU_TOPOLOGY) += cpu-topology.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
 obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += device.o
 obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
xen/common/cpu-topology.c new file +30 -0
new file mode 100644
index 0000000000..edf47445ac
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+void __init init_cpu_topology(void)
+{
+    const unsigned int nr_cpus = cpumask_last(&cpu_possible_map) + 1U;
+
+    cpu_topology = xzalloc_array(struct cpu_topology, nr_cpus);
+    if ( !cpu_topology )
+        panic("Failed to allocate memory for cpu_topology array\n");
+
+    if ( acpi_disabled )
+        dt_init_cpu_topology();
+    else
+        acpi_init_cpu_topology();
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/common/device-tree/Makefile +1 -0
index 9036e455d6..38bc5d5306 100644
@@ -1,6 +1,7 @@
 obj-y += bootfdt.init.o
 obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo-fdt.init.o
 obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += bootinfo.init.o
+obj-$(CONFIG_DT_CPU_TOPOLOGY) += cpu-topology.o
 obj-y += device-tree.o
 obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += domain-build.init.o
 obj-$(filter $(CONFIG_DOM0LESS_BOOT),$(CONFIG_HAS_DEVICE_TREE_DISCOVERY)) += dom0less-build.init.o
xen/common/device-tree/cpu-topology.c new file +343 -0

343 lines not on this page · raw message

xen/drivers/acpi/Kconfig +3 -0
index e3f3d8f4b1..5277b7bf83 100644
@@ -8,3 +8,6 @@ config ACPI_LEGACY_TABLES_LOOKUP
 config ACPI_NUMA
 	bool
 	select NUMA
+
+config ACPI_CPU_TOPOLOGY
+	bool
xen/drivers/acpi/Makefile +2 -0
index 477408afbe..2c8d64c314 100644
@@ -10,3 +10,5 @@ obj-$(CONFIG_PM_OP) += pm-op.o
 
 obj-$(CONFIG_X86) += hwregs.o
 obj-$(CONFIG_X86) += reboot.o
+
+obj-$(CONFIG_ACPI_CPU_TOPOLOGY) += topology.o
xen/drivers/acpi/topology.c new file +38 -0
new file mode 100644
index 0000000000..7a7042c84e
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+/*
+ * ToDo: Populate the topology information by scanning the ACPI
+ *       PPTT (Processor Properties Topology Table).
+ */
+void __init acpi_init_cpu_topology(void)
+{
+    unsigned int cpu;
+
+    /*
+     * Generate temporary cpu topology information for now.
+     * It assumes that the cpu doesn't have SMT and all CPUs
+     * belong to the same socket.
+     */
+    for_each_possible_cpu(cpu)
+    {
+        struct cpu_topology *topo = &cpu_topology[cpu];
+
+        cpumask_set_cpu(cpu, &topo->thread_sibling);
+        cpumask_copy(&topo->core_sibling, &cpu_possible_map);
+    }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/xen/acpi.h +4 -0
index 2fdf38cf74..3aa4edd20f 100644
@@ -101,6 +101,8 @@ void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr
 void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
 void acpi_table_print_srat_entry (struct acpi_subtable_header *srat);
 
+void acpi_init_cpu_topology(void);
+
 /* the following four functions are architecture-dependent */
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
 void acpi_numa_processor_affinity_init(const struct acpi_srat_cpu_affinity *);
@@ -133,6 +135,8 @@ static inline int acpi_boot_table_init(void)
 	return 0;
 }
 
+static inline void acpi_init_cpu_topology(void) {}
+
 #endif 	/*!CONFIG_ACPI*/
 
 int get_cpu_id(u32 acpi_id);
xen/include/xen/cpu-topology.h new file +36 -0
new file mode 100644
index 0000000000..896eefb04f
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_CPU_TOPOLOGY_H
+#define XEN_CPU_TOPOLOGY_H
+
+#include <xen/types.h>
+#include <xen/dt-cpu-topology.h>
+
+struct cpu_topology {
+    cpumask_t thread_sibling;
+    cpumask_t core_sibling;
+    cpumask_t cluster_sibling;
+};
+
+
+#ifdef CONFIG_CPU_TOPOLOGY
+
+extern struct cpu_topology *cpu_topology;
+void init_cpu_topology(void);
+
+#else /* CONFIG_CPU_TOPOLOGY */
+
+static inline void init_cpu_topology(void) {}
+
+#endif /* CONFIG_CPU_TOPOLOGY */
+
+#endif /* XEN_CPU_TOPOLOGY_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/xen/dt-cpu-topology.h new file +30 -0
new file mode 100644
index 0000000000..334a3181f9
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_DT_CPU_TOPOLOGY_H
+#define XEN_DT_CPU_TOPOLOGY_H
+
+#include <xen/types.h>
+#include <xen/device_tree.h>
+
+#ifdef CONFIG_DT_CPU_TOPOLOGY
+
+void map_cpuid_to_node(unsigned int cpuid, struct dt_device_node *cpu_node);
+void dt_init_cpu_topology(void);
+
+#else /* CONFIG_DT_CPU_TOPOLOGY */
+
+static inline void map_cpuid_to_node(unsigned int cpuid, struct dt_device_node *cpu_node) {}
+static inline void dt_init_cpu_topology(void) {}
+
+#endif /* CONFIG_DT_CPU_TOPOLOGY */
+
+#endif /* XEN_DT_CPU_TOPOLOGY_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/3] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration

Quoted 5 lines · Hirokazu Takahashi
xen/common/cpu-topology.c new file +2 -0
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+

xen/common/cpu-topology.c line 12

Quoted 10 lines
xen/common/cpu-topology.c new file +10 -0
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+void __init init_cpu_topology(void)
+{
+    const unsigned int nr_cpus = cpumask_last(&cpu_possible_map) + 1U;
+
+    cpu_topology = xzalloc_array(struct cpu_topology, nr_cpus);

cpu_topology exists as a global variable only when DT is in use. I think the definition needs to move here (from common/device-tree/cpu-topology.c).

As to the size of the array, it's not quite clear to me whether by doing it this way (instead of using nr_cpu_ids) we're not setting ourselves up for trouble.

xen/common/cpu-topology.c line 14

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+    if ( !cpu_topology )
+        panic("Failed to allocate memory for cpu_topology array\n");

I question such uses of panic(): Surely we can do without any NUMA info, it's only performance which is going to suffer.

Quoted 56 lines
xen/common/device-tree/cpu-topology.c new file +53 -0
@@ -0,0 +1,343 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Derived from Linux kernel 7.0's $drivers/base/arch_topology.c
+ * Parse cpu topology information.
+ */
+
+#include <xen/cpumask.h>
+#include <xen/device_tree.h>
+#include <xen/cpu-topology.h>
+#include <xen/numa.h>
+#include <xen/errno.h>
+#include <xen/init.h>
+
+struct cpu_map {
+    unsigned int thread_id;
+    unsigned int core_id;
+    unsigned int cluster_id;
+    unsigned int package_id;
+};
+
+struct cpu_topology *cpu_topology;
+static const unsigned int __initdata invalid_topo_id = (~0U);
+static struct cpu_map __initdata cpu_map[NR_CPUS] = {
+    [0 ... NR_CPUS-1] = {invalid_topo_id, invalid_topo_id, invalid_topo_id, 0U}
+};
+static struct dt_device_node * __initdata dt_cpu_table[NR_CPUS];
+
+static void __init setup_siblings_masks(unsigned int cpuid)
+{
+    struct cpu_topology *cpuid_topo = &cpu_topology[cpuid];
+    struct cpu_map *cpuid_map = &cpu_map[cpuid];
+    unsigned int cpu;
+
+    /* Update core and thread sibling masks */
+    for_each_possible_cpu(cpu)
+    {
+        struct cpu_topology *cpu_topo = &cpu_topology[cpu];
+        struct cpu_map *map = &cpu_map[cpu];
+
+        if ( cpuid_map->package_id != map->package_id )
+            continue;
+
+        cpumask_set_cpu(cpuid, &cpu_topo->core_sibling);
+        cpumask_set_cpu(cpu, &cpuid_topo->core_sibling);
+
+        if ( cpuid_map->cluster_id != map->cluster_id )
+            continue;
+
+        if ( cpuid_map->cluster_id != invalid_topo_id )
+        {
+            cpumask_set_cpu(cpu, &cpuid_topo->cluster_sibling);
+            cpumask_set_cpu(cpuid, &cpu_topo->cluster_sibling);
+        }

xen/common/device-tree/cpu-topology.c line 63

Quoted 10 lines
xen/common/device-tree/cpu-topology.c new file +10 -0
+
+        if ( cpuid_map->core_id != map->core_id )
+            continue;
+
+        cpumask_set_cpu(cpuid, &cpu_topo->thread_sibling);
+        cpumask_set_cpu(cpu, &cpuid_topo->thread_sibling);
+    }
+}
+
+static struct dt_device_node * __init dt_find_child_node_by_name(struct dt_device_node *from, const char *name)

Nit: Overlong line here, and ...

xen/common/device-tree/cpu-topology.c line 111

Quoted 3 lines
xen/common/device-tree/cpu-topology.c new file +3 -0
+static int __init parse_core(struct dt_device_node *core,
+                unsigned int package_id, unsigned int cluster_id,
+                unsigned int core_id)

... bogus indentation e.g. here. Please go though yourself to check style.

xen/drivers/acpi/topology.c line 10

Quoted 13 lines
xen/drivers/acpi/topology.c new file +10 -0
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+/*
+ * ToDo: Populate the topology information by scanning the ACPI
+ *       PPTT (Processor Properties Topology Table).

Please can this be spelled "TODO:", to stand out more and to be a hit also with case sensitive grep for "TODO"?

Quoted 12 lines
xen/include/xen/acpi.h +2 -0
@@ -101,6 +101,8 @@ void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr
 void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
 void acpi_table_print_srat_entry (struct acpi_subtable_header *srat);
 
+void acpi_init_cpu_topology(void);
+
 /* the following four functions are architecture-dependent */
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
 void acpi_numa_processor_affinity_init(const struct acpi_srat_cpu_affinity *);

xen/include/xen/acpi.h static inline int acpi_boot_table_init(void) · line 138

Quoted 4 lines
xen/include/xen/acpi.h +1 -0
@@ -133,6 +135,8 @@ static inline int acpi_boot_table_init(void)
 	return 0;
 }
 
+static inline void acpi_init_cpu_topology(void) {}

This shouldn't be needed. When ACPI=y, acpi_disabled is compile-time true, and hence the compiler can and will DCE the call. All it needs to see is a declaration, which therefore wants to move outside of the CONFIG_ACPI conditional.

Quoted 6 lines
xen/include/xen/cpu-topology.h new file +3 -0
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_CPU_TOPOLOGY_H

xen/include/xen/cpu-topology.h line 13

Quoted 10 lines
xen/include/xen/cpu-topology.h new file +10 -0
+#define XEN_CPU_TOPOLOGY_H
+
+#include <xen/types.h>
+#include <xen/dt-cpu-topology.h>
+
+struct cpu_topology {
+    cpumask_t thread_sibling;
+    cpumask_t core_sibling;
+    cpumask_t cluster_sibling;
+};

With huge NR_CPUS this can be pretty large a struct (of which in init_cpu_topology() you allocate an array). Imo you want to use cpumask_var_t here, with allocation added as needed.

xen/include/xen/cpu-topology.h line 15

Quoted 2 lines
xen/include/xen/cpu-topology.h new file +2 -0
+
+

Nit: No double blank lines please.

Jan

#3 lore raw

RE: [PATCH v2 1/3] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration

Hello,

Quoted 14 lines

xen/common/cpu-topology.c line 10

Quoted 13 lines
xen/common/cpu-topology.c new file +10 -0
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+void __init init_cpu_topology(void)
+{
+    const unsigned int nr_cpus = cpumask_last(&cpu_possible_map) +

1U;

Quoted 5 lines

xen/common/cpu-topology.c line 12

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+
+    cpu_topology = xzalloc_array(struct cpu_topology, nr_cpus);

cpu_topology exists as a global variable only when DT is in use. I think the definition needs to move here (from common/device-tree/cpu-topology.c).

Okay

Quoted 3 lines

As to the size of the array, it's not quite clear to me whether by doing it this way (instead of using nr_cpu_ids) we're not setting ourselves up for trouble.

On ARM64 Xen, nr_cpu_ids represents the total number of populated/available CPUs, but unfortunately it cannot be relied upon as the maximum CPU ID.

For instance, if a CPU node in the Device Tree has an invalid 'enable-method' property, that CPU ID slot is still consumed during the initial parsing, but the CPU is not counted towards nr_cpu_ids. This can result in a sparse CPU ID allocation where the maximum CPU ID actually exceeds.

If we were to use nr_cpu_ids as the array size here, we would risk an out-of-bounds access under such faulty Device Tree configurations. This is why I used "cpumask_last(&cpu_possible_map) + 1U" to ensure the array is large enough to cover the highest allocated CPU ID.

Consequently, there might actually be potential bugs in other parts of Xen where nr_cpu_ids is incorrectly assumed to be the upper bound for CPU ID indexing on ARM.

Quoted 5 lines

xen/common/cpu-topology.c line 14

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+    if ( !cpu_topology )
+        panic("Failed to allocate memory for cpu_topology array\n");

I question such uses of panic(): Surely we can do without any NUMA info, it's only performance which is going to suffer.

Okay, I will replace the panic() with a XENLOG_WARNING printk.

Quoted 4 lines

xen/common/cpu-topology.c line 16

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+
+static struct dt_device_node * __init dt_find_child_node_by_name(struct dt_device_node *from, const char *name)

Nit: Overlong line here, and ...

Okay, I will fix it.

Quoted 5 lines

xen/common/cpu-topology.c line 19

Quoted 3 lines
xen/common/cpu-topology.c new file +3 -0
+static int __init parse_core(struct dt_device_node *core,
+                unsigned int package_id, unsigned int cluster_id,
+                unsigned int core_id)

... bogus indentation e.g. here. Please go though yourself to check style.

Okay.

Quoted 8 lines
Quoted 8 lines
xen/drivers/acpi/topology.c new file +5 -0
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
Quoted 8 lines

xen/drivers/acpi/topology.c line 10

Quoted 5 lines
xen/drivers/acpi/topology.c new file +5 -0
+#include <xen/acpi.h>
+
+/*
+ * ToDo: Populate the topology information by scanning the ACPI
+ *       PPTT (Processor Properties Topology Table).

Please can this be spelled "TODO:", to stand out more and to be a hit also with case sensitive grep for "TODO"?

Okay.

Quoted 17 lines

xen/include/xen/acpi.h void acpi_table_print (struct acpi_table_header

Quoted 3 lines
xen/include/xen/acpi.h +0 -0
@@ -101,6 +101,8 @@ void acpi_table_print (struct acpi_table_header

*header, unsigned long phys_addr

xen/include/xen/acpi.h void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr

Quoted 8 lines
xen/include/xen/acpi.h +2 -0
 void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
 void acpi_table_print_srat_entry (struct acpi_subtable_header *srat);
 
+void acpi_init_cpu_topology(void);
+
 /* the following four functions are architecture-dependent */
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
 void acpi_numa_processor_affinity_init(const struct

acpi_srat_cpu_affinity *);

Quoted 4 lines
xen/include/xen/acpi.h +0 -0
@@ -133,6 +135,8 @@ static inline int acpi_boot_table_init(void)
 	return 0;
 }
 
Quoted 6 lines

xen/include/xen/acpi.h static inline int acpi_boot_table_init(void) · line 138

Quoted 1 line
xen/include/xen/acpi.h +1 -0
+static inline void acpi_init_cpu_topology(void) {}

This shouldn't be needed. When ACPI=y, acpi_disabled is compile-time true, and hence the compiler can and will DCE the call. All it needs to see is a declaration, which therefore wants to move outside of the CONFIG_ACPI conditional.

okay

Quoted 12 lines
Quoted 12 lines
xen/include/xen/cpu-topology.h new file +9 -0
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_CPU_TOPOLOGY_H
+#define XEN_CPU_TOPOLOGY_H
+
+#include <xen/types.h>
+#include <xen/dt-cpu-topology.h>
+
+struct cpu_topology {
Quoted 8 lines

xen/include/xen/cpu-topology.h line 13

Quoted 4 lines
xen/include/xen/cpu-topology.h new file +4 -0
+    cpumask_t thread_sibling;
+    cpumask_t core_sibling;
+    cpumask_t cluster_sibling;
+};

With huge NR_CPUS this can be pretty large a struct (of which in init_cpu_topology() you allocate an array). Imo you want to use cpumask_var_t here, with allocation added as needed.

Okay.

Quoted 4 lines

xen/include/xen/cpu-topology.h line 15

Quoted 2 lines
xen/include/xen/cpu-topology.h new file +2 -0
+
+

Nit: No double blank lines please.

Okay.

Thank you,
Hirokazu Takahashi.

#4 lore raw

Re: [PATCH v2 1/3] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration

Quoted 34 lines · Hirokazu Takahashi
Quoted 14 lines

xen/common/cpu-topology.c line 10

Quoted 13 lines
xen/common/cpu-topology.c new file +10 -0
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/cpumask.h>
+#include <xen/cpu-topology.h>
+#include <xen/init.h>
+#include <xen/acpi.h>
+
+void __init init_cpu_topology(void)
+{
+    const unsigned int nr_cpus = cpumask_last(&cpu_possible_map) +

1U;

Quoted 5 lines

xen/common/cpu-topology.c line 12

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+
+    cpu_topology = xzalloc_array(struct cpu_topology, nr_cpus);

cpu_topology exists as a global variable only when DT is in use. I think the definition needs to move here (from common/device-tree/cpu-topology.c).

Okay

Quoted 3 lines

As to the size of the array, it's not quite clear to me whether by doing it this way (instead of using nr_cpu_ids) we're not setting ourselves up for trouble.

On ARM64 Xen, nr_cpu_ids represents the total number of populated/available CPUs, but unfortunately it cannot be relied upon as the maximum CPU ID.

For instance, if a CPU node in the Device Tree has an invalid 'enable-method' property, that CPU ID slot is still consumed during the initial parsing, but the CPU is not counted towards nr_cpu_ids. This can result in a sparse CPU ID allocation where the maximum CPU ID actually exceeds.

Quoted 8 lines

If we were to use nr_cpu_ids as the array size here, we would risk an out-of-bounds access under such faulty Device Tree configurations. This is why I used "cpumask_last(&cpu_possible_map) + 1U" to ensure the array is large enough to cover the highest allocated CPU ID.

Consequently, there might actually be potential bugs in other parts of Xen where nr_cpu_ids is incorrectly assumed to be the upper bound for CPU ID indexing on ARM.

Specifically cpumask_var_t allocations are dimensioned by nr_cpu_ids, and all cpumask{,_var}_t accesses (including the cpumask_last() you use above) also have bounds checks against nr_cpu_ids (sometimes only in debug builds). IOW if there is an issue as you describe it, and if that can happen in practice, then this urgently needs fixing on the Arm side. This cannot be an excuse to not do the sane thing here.

Quoted 7 lines
Quoted 5 lines

xen/common/cpu-topology.c line 14

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+    if ( !cpu_topology )
+        panic("Failed to allocate memory for cpu_topology array\n");

I question such uses of panic(): Surely we can do without any NUMA info, it's only performance which is going to suffer.

Okay, I will replace the panic() with a XENLOG_WARNING printk.

Which of course you understand isn't all that needs changing then.

Jan

#5 lore raw

RE: [PATCH v2 1/3] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration

Hello,

Quoted 21 lines
Quoted 12 lines
Quoted 3 lines

As to the size of the array, it's not quite clear to me whether by doing it this way (instead of using nr_cpu_ids) we're not setting ourselves up for trouble.

On ARM64 Xen, nr_cpu_ids represents the total number of populated/available CPUs, but unfortunately it cannot be relied upon as the maximum CPU ID.

For instance, if a CPU node in the Device Tree has an invalid 'enable-method' property, that CPU ID slot is still consumed during the initial parsing, but the CPU is not counted towards nr_cpu_ids. This can result in a sparse CPU ID allocation where the maximum CPU ID actually exceeds.

Quoted 8 lines

If we were to use nr_cpu_ids as the array size here, we would risk an out-of-bounds access under such faulty Device Tree configurations. This is why I used "cpumask_last(&cpu_possible_map) + 1U" to ensure the array is large enough to cover the highest allocated CPU ID.

Consequently, there might actually be potential bugs in other parts of Xen where nr_cpu_ids is incorrectly assumed to be the upper bound for CPU ID indexing on ARM.

Quoted 6 lines

Specifically cpumask_var_t allocations are dimensioned by nr_cpu_ids, and all cpumask{,_var}_t accesses (including the cpumask_last() you use above) also have bounds checks against nr_cpu_ids (sometimes only in debug builds). IOW if there is an issue as you describe it, and if that can happen in practice, then this urgently needs fixing on the Arm side. This cannot be an excuse to not do the sane thing here.

Okay, I will use 'nr_cpu_ids' as the array size.

And I have to fix the following code.
ARM Xen may possibly create sparse 'cpu_possible_map' and calculates nr_cpu_ids from the number of bits in it.

xen/common/cpu.c:
unsigned int __read_mostly nr_cpu_ids = NR_CPUS;

xen/arch/arm/setup.c:
void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)

{
        :
    smp_init_cpus();
    nr_cpu_ids = smp_get_max_cpus();
    printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", nr_cpu_ids);
        :
}

xen/arch/arm/smpboot.c:
/* maxcpus: maximum number of CPUs to activate. */ static unsigned int __initdata max_cpus; integer_param("maxcpus", max_cpus);

unsigned int __init smp_get_max_cpus(void)

{
    unsigned int i, cpus = 0;

    if ( ( !max_cpus ) || ( max_cpus > nr_cpu_ids ) )
        max_cpus = nr_cpu_ids;

    for ( i = 0; i < max_cpus; i++ )
        if ( cpu_possible(i) )
            cpus++;

    return cpus;
}

static void __init dt_smp_init_cpus(void)

{
        :
        :
    for ( i = 0; i < cpuidx; i++ )
    {
        if ( tmp_map[i] == MPIDR_INVALID )
            continue;
        cpumask_set_cpu(i, &cpu_possible_map);
        cpu_logical_map(i) = tmp_map[i];
    }
}
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

xen/common/cpu-topology.c line 14

Quoted 2 lines
xen/common/cpu-topology.c new file +2 -0
+    if ( !cpu_topology )
+        panic("Failed to allocate memory for cpu_topology array\n");

I question such uses of panic(): Surely we can do without any NUMA info, it's only performance which is going to suffer.

Okay, I will replace the panic() with a XENLOG_WARNING printk.

Which of course you understand isn't all that needs changing then.

Yes, I will ensure that the rest of the code handles a NULL 'cpu_topology' Pointer.

Hirokazu Takahashi.

#6 lore raw

PATCH v2 2/3 xen/sched: Link CPU topology to scheduler

In reply to Hirokazu Takahashi

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 | 51 +++++++++++++++++++++++++++
 xen/common/sched/credit2.c            |  3 ++
 xen/common/sysctl.c                   |  1 +
 xen/drivers/acpi/topology.c           |  3 ++
 xen/include/xen/cpu-topology.h        | 10 ++++++
 7 files changed, 75 insertions(+), 7 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -4
index a3753c317f..41fa73cfc4 100644
@@ -613,10 +613,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);
xen/arch/arm/smpboot.c +7 -3
index fb2cf26424..4a3f1149f6 100644
@@ -91,13 +91,17 @@ static int setup_cpu_sibling_map(int cpu)
          !zalloc_cpumask_var(&per_cpu(cpu_core_mask, cpu)) )
         return -ENOMEM;
 
+#ifdef CONFIG_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_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_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_CPU_TOPOLOGY */
 
     return 0;
 }
xen/common/device-tree/cpu-topology.c +51 -0

63 lines not on this page · raw message

xen/common/sched/credit2.c +3 -0
index 77475ee363..cd8b7212bc 100644
@@ -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 defined(CONFIG_CPU_TOPOLOGY)
+    return cpu_topology[cpu].num_siblings;
 #else
     return 1;
 #endif
xen/common/sysctl.c +1 -0
index 5207664252..81a68fe24c 100644
@@ -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)
 {
xen/drivers/acpi/topology.c +3 -0
index 7a7042c84e..301ee0dafa 100644
@@ -22,6 +22,9 @@ void __init acpi_init_cpu_topology(void)
     {
         struct cpu_topology *topo = &cpu_topology[cpu];
 
+        topo->phys_core_id = cpu;
+        topo->num_siblings = 1U;
+
         cpumask_set_cpu(cpu, &topo->thread_sibling);
         cpumask_copy(&topo->core_sibling, &cpu_possible_map);
     }
xen/include/xen/cpu-topology.h +10 -0
index 896eefb04f..3fdbc25e8e 100644
@@ -10,6 +10,10 @@ struct cpu_topology {
     cpumask_t thread_sibling;
     cpumask_t core_sibling;
     cpumask_t cluster_sibling;
+    unsigned int phys_core_id;
+    unsigned int phys_cluster_id;
+    unsigned int phys_socket_id;
+    unsigned int num_siblings;
 };
 
 
@@ -18,10 +22,16 @@ struct cpu_topology {
 extern struct cpu_topology *cpu_topology;
 void 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)
+
 #else /* CONFIG_CPU_TOPOLOGY */
 
 static inline void init_cpu_topology(void) {}
 
+#define cpu_to_core(cpu)   (0U)
+#define cpu_to_socket(cpu) (0U)
+
 #endif /* CONFIG_CPU_TOPOLOGY */
 
 #endif /* XEN_CPU_TOPOLOGY_H */
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v2 2/3] xen/sched: Link CPU topology to scheduler

Quoted 11 lines · Hirokazu Takahashi
xen/common/sched/credit2.c +1 -0
@@ -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>
 

xen/common/sched/credit2.c static unsigned int cpu_nr_siblings(unsigned int cpu) · line 42

Quoted 5 lines
xen/common/sched/credit2.c +2 -0
@@ -37,6 +38,8 @@ static unsigned int cpu_nr_siblings(unsigned int cpu)
 {
 #ifdef CONFIG_X86
     return cpu_data[cpu].x86_num_siblings;
+#elif defined(CONFIG_CPU_TOPOLOGY)
+    return cpu_topology[cpu].num_siblings;

Would this better be the other way around (first the generic thing, then the x86 one)?

xen/drivers/acpi/topology.c void __init acpi_init_cpu_topology(void) · line 26

Quoted 8 lines
xen/drivers/acpi/topology.c +2 -0
@@ -22,6 +22,9 @@ void __init acpi_init_cpu_topology(void)
     {
         struct cpu_topology *topo = &cpu_topology[cpu];
 
+        topo->phys_core_id = cpu;
+        topo->num_siblings = 1U;

In the interest of readability suffixes may better be omitted from literal numbers when they aren't really needed. Which, btw, doesn't extend to ..

Quoted 16 lines
xen/include/xen/cpu-topology.h +4 -0
@@ -10,6 +10,10 @@ struct cpu_topology {
     cpumask_t thread_sibling;
     cpumask_t core_sibling;
     cpumask_t cluster_sibling;
+    unsigned int phys_core_id;
+    unsigned int phys_cluster_id;
+    unsigned int phys_socket_id;
+    unsigned int num_siblings;
 };
 
 
@@ -18,10 +22,16 @@ struct cpu_topology {
 extern struct cpu_topology *cpu_topology;
 void init_cpu_topology(void);

xen/include/xen/cpu-topology.h struct cpu_topology { · line 33

Quoted 10 lines
xen/include/xen/cpu-topology.h +5 -0
 
+#define cpu_to_core(cpu)   (cpu_topology[cpu].phys_core_id)
+#define cpu_to_socket(cpu)   (cpu_topology[cpu].phys_socket_id)
+
 #else /* CONFIG_CPU_TOPOLOGY */
 
 static inline void init_cpu_topology(void) {}
 
+#define cpu_to_core(cpu)   (0U)
+#define cpu_to_socket(cpu) (0U)

... such uses (in particular stub/fallback ones) in header files.

Jan

#8 lore raw

PATCH v2 3/3 xen/sched: Make cpu_nr_siblings() architecture-specific

In reply to Hirokazu Takahashi

Make cpu_nr_siblings() an architecture-specific function. This patch provides the implementation for x86 and a common version for Device Tree-based architectures.

---
 xen/arch/x86/include/asm/processor.h |  1 +
 xen/common/sched/credit2.c           | 22 +++-------------------
 xen/include/xen/cpu-topology.h       |  2 ++
 3 files changed, 6 insertions(+), 19 deletions(-)
xen/arch/x86/include/asm/processor.h +1 -0
index 8ca6799a81..9758060129 100644
@@ -106,6 +106,7 @@ extern void intel_init_arat(void);
 
 #define cpu_to_core(_cpu)   (cpu_data[_cpu].cpu_core_id)
 #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id)
+#define cpu_nr_siblings(_cpu) (cpu_data[_cpu].x86_num_siblings)
 
 unsigned int apicid_to_socket(unsigned int apicid);
 
xen/common/sched/credit2.c +3 -19
index cd8b7212bc..7623e57549 100644
@@ -29,22 +29,6 @@
 /* #define d2printk printk */
 #define d2printk(x...)
 
-/*
- * TODO: Abstract this properly, and figure out what Credit2 wants to do with
- *       the fact that x86_num_siblings doesn't even have the same meaning
- *       between x86 vendors.
- */
-static unsigned int cpu_nr_siblings(unsigned int cpu)
-{
-#ifdef CONFIG_X86
-    return cpu_data[cpu].x86_num_siblings;
-#elif defined(CONFIG_CPU_TOPOLOGY)
-    return cpu_topology[cpu].num_siblings;
-#else
-    return 1;
-#endif
-}
-
 /*
  * Credit2 tracing events ("only" 512 available!). Check
  * include/public/trace.h for more details.
@@ -882,9 +866,9 @@ cpu_runqueue_match(const struct csched2_runqueue_data *rqd, unsigned int cpu)
 
 /*
  * Additional checks, to avoid separating siblings in different runqueues.
- * This deals with both Intel's HTs and AMD's CUs. An arch that does not have
- * any similar concept will just have cpu_nr_siblings() always return 1, and
- * setup the cpu_sibling_mask-s acordingly (as currently does ARM), and things
+ * This deals with Intel's HTs, AMD's CUs and ARM's SMT. An arch that
+ * does not have similar concept will just have cpu_nr_siblings() always
+ * return 1, and setup the cpu_sibling_mask-s accordingly, and things
  * will just work as well.
  */
 static bool
xen/include/xen/cpu-topology.h +2 -0
index 3fdbc25e8e..3f748f0384 100644
@@ -24,6 +24,7 @@ void 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)
 
 #else /* CONFIG_CPU_TOPOLOGY */
 
@@ -31,6 +32,7 @@ static inline void init_cpu_topology(void) {}
 
 #define cpu_to_core(cpu)   (0U)
 #define cpu_to_socket(cpu) (0U)
+#define cpu_nr_siblings(cpu) (1U)
 
 #endif /* CONFIG_CPU_TOPOLOGY */
 
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH v2 3/3] xen/sched: Make cpu_nr_siblings() architecture-specific

xen/arch/x86/include/asm/processor.h extern void intel_init_arat(void); · line 109

Quoted 7 lines · Hirokazu Takahashi
xen/arch/x86/include/asm/processor.h +1 -0
@@ -106,6 +106,7 @@ extern void intel_init_arat(void);
 
 #define cpu_to_core(_cpu)   (cpu_data[_cpu].cpu_core_id)
 #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id)
+#define cpu_nr_siblings(_cpu) (cpu_data[_cpu].x86_num_siblings)

This is uniformly available when building x86. An earlier patch adds an #include of the new cpu-topology.h ...

Quoted 11 lines
xen/common/sched/credit2.c +0 -5
@@ -29,22 +29,6 @@
 /* #define d2printk printk */
 #define d2printk(x...)
 
-/*
- * TODO: Abstract this properly, and figure out what Credit2 wants to do with
- *       the fact that x86_num_siblings doesn't even have the same meaning
- *       between x86 vendors.
- */

xen/common/sched/credit2.c line 46

Quoted 10 lines
xen/common/sched/credit2.c +0 -10
-static unsigned int cpu_nr_siblings(unsigned int cpu)
-{
-#ifdef CONFIG_X86
-    return cpu_data[cpu].x86_num_siblings;
-#elif defined(CONFIG_CPU_TOPOLOGY)
-    return cpu_topology[cpu].num_siblings;
-#else
-    return 1;
-#endif
-}

... to this file, thus allowing for the static function to be dropped. However,
...

Quoted 11 lines
xen/include/xen/cpu-topology.h +1 -0
@@ -24,6 +24,7 @@ void 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)
 
 #else /* CONFIG_CPU_TOPOLOGY */
 

xen/include/xen/cpu-topology.h static inline void init_cpu_topology(void) {} · line 37

Quoted 6 lines
xen/include/xen/cpu-topology.h +1 -0
@@ -31,6 +32,7 @@ static inline void init_cpu_topology(void) {}
 
 #define cpu_to_core(cpu)   (0U)
 #define cpu_to_socket(cpu) (0U)
+#define cpu_nr_siblings(cpu) (1U)
 
 #endif /* CONFIG_CPU_TOPOLOGY */

... one of the two #define-s will take effect here. Whichever one it is, it'll conflict with x86'es (when building for x86). Am I overlooking something here, or did you simply not build-test x86? Looks like a problem of the same kind may actually be introduced already by patch 2.

Jan

#10 lore raw

RE: [PATCH v2 3/3] xen/sched: Make cpu_nr_siblings() architecture-specific

Hello,

Quoted 11 lines · Hirokazu Takahashi

xen/arch/x86/include/asm/processor.h extern void intel_init_arat(void); · line 109

Quoted 7 lines
xen/arch/x86/include/asm/processor.h +1 -0
@@ -106,6 +106,7 @@ extern void intel_init_arat(void);
 
 #define cpu_to_core(_cpu)   (cpu_data[_cpu].cpu_core_id)
 #define cpu_to_socket(_cpu) (cpu_data[_cpu].phys_proc_id)
+#define cpu_nr_siblings(_cpu) (cpu_data[_cpu].x86_num_siblings)

This is uniformly available when building x86. An earlier patch adds an #include of the new cpu-topology.h ...

"The cpu-topology.h header is intended for non-x86 architectures where topology information is retrieved from Device Tree or ACPI.
For x86, I will ensure that it is properly disabled to avoid any conflicts."

Quoted 41 lines
Quoted 11 lines
xen/common/sched/credit2.c +0 -5
@@ -29,22 +29,6 @@
 /* #define d2printk printk */
 #define d2printk(x...)
 
-/*
- * TODO: Abstract this properly, and figure out what Credit2 wants to do with
- *       the fact that x86_num_siblings doesn't even have the same meaning
- *       between x86 vendors.
- */

xen/common/sched/credit2.c line 46

Quoted 10 lines
xen/common/sched/credit2.c +0 -10
-static unsigned int cpu_nr_siblings(unsigned int cpu)
-{
-#ifdef CONFIG_X86
-    return cpu_data[cpu].x86_num_siblings;
-#elif defined(CONFIG_CPU_TOPOLOGY)
-    return cpu_topology[cpu].num_siblings;
-#else
-    return 1;
-#endif
-}

... to this file, thus allowing for the static function to be dropped. However,
...

Quoted 16 lines
xen/include/xen/cpu-topology.h +2 -0
@@ -24,6 +24,7 @@ void 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)
 
 #else /* CONFIG_CPU_TOPOLOGY */
 
@@ -31,6 +32,7 @@ static inline void init_cpu_topology(void) {}
 
 #define cpu_to_core(cpu)   (0U)
 #define cpu_to_socket(cpu) (0U)
+#define cpu_nr_siblings(cpu) (1U)
 
Quoted 6 lines

xen/include/xen/cpu-topology.h static inline void init_cpu_topology(void) {} · line 37

Quoted 1 line
xen/include/xen/cpu-topology.h +0 -0
 #endif /* CONFIG_CPU_TOPOLOGY */

... one of the two #define-s will take effect here. Whichever one it is, it'll conflict with x86'es (when building for x86). Am I overlooking something here, or did you simply not build-test x86? Looks like a problem of the same kind may actually be introduced already by patch 2.

Oops, you are completely right, and I sincerely apologize. I did not properly build-test on x86.

Thank you,
Hirokazu Takahashi.