* [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT
@ 2026-11-30 6:57 Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Hirokazu Takahashi
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel; +Cc: michal.orzel, jbeulich, Hirokazu Takahashi
Hello,
This is v13 of the ARM64 CPU topology discovery patch series.
Changes in v13:
- Do not pass ACPI PPTT to Dom0, as PPTT does not represent the
topology of Dom0 vCPUs.
- Make the fix for offline CPUs remaining in CPU sibling maps
a separete commit f1b08cc03ace ("xen/arm: Fix sibling mask
setup to only include online CPUs").
- Rename drivers/acpi/topology.c to drivers/acpi/cpu-topology.c.
- Exit the loop immediately when memory allocation fails.
- Avoid printing redundant error messages on -ENOMEM.
- Do not log error messages on -ENOENT or -ENOTSUPP.
- Add appropriate XENLOG levels to printk() calls that lacked them.
- Replace dt_node_name() with dt_node_full_name() in error logs to
provide more detailed information.
- Adjust code to follow the Xen coding style.
- Minor fixes to comments.
Changes in v12:
- Error reporting for memory allocation failures in init_cpu_topology()
into a single error path.
- Emit an error message from init_cpu_topology() when
dt_init_cpu_topology() or acpi_init_cpu_topology() returns an error,
explicitly indicating that CPU topology initialization has failed.
- Drop the Reviewed-by tag from patch 0001 due to changes in
common/cpu-topology.c.
- In dt_smp_init_cpus(), add a comment explaining that the boot core
remains valid even if arch_cpu_init() fails.
- dt_init_cpu_topology() returns -EINVAL if a leaf node lacks the cpu
phandle property or if the target node is not a valid CPU node.
- dt_init_cpu_topology() continues parsing subsequent threads instead
of returning early when a referenced CPU is not tracked by Xen.
- Update the log message when skipping an unmapped CPU to reflect
that secondary CPUs have not yet been brought up at this stage.
- Remove trailing periods from log messages.
- Drop the Reviewed-by tag from patch 0001 due to changes in
common/cpu-topology.c.
Changes in v11:
- When parsing the Device Tree, ignore CPU nodes if the corresponding
physical CPU failed to boot, rather than treating it as an error.
- Drop the dependency on UNSUPPORTED for CPU topology support.
- Print an error message if memory allocation fails in init_cpu_topology().
- Fix a compilation error involving cpumask_set_cpu().
- Call map_cpu_to_dt_node() to record the CPU ID to DT node mapping only
when arch_cpu_init() succeeds, or if the CPU is the boot CPU (treated
as successful since the boot CPU is already up and running).
- Use XENLOG_ERR as the log level for error messages emitted when DT CPU
topology parsing fails.
- Add ASSERT(cpu_topology) to acpi_init_cpu_topology() for consistency.
- Code cleanups:
* Use dt_node_name_is_equal() instead of dt_node_cmp().
* Drop redundant "ERROR:" and "WARNING:" prefixes from log messages.
* Move header file includes into #ifdef / #else blocks where they are
actually needed.
* Adjust spacing to comply with the Xen coding style.
Changes in v10:
- Postpone the invocation of init_cpu_topology() until after nr_cpu_ids
is finalized.
- Improve the Device Tree cpu-map node parsing logic:
* Rename functions and variables to accurately reflect the DT nodes
being processed.
* Simplify the parsing algorithm by eliminating recursive calls and
avoiding passing INVALID_TOPO_ID as an argument.
- Unify all license headers to GPL-2.0-only.
- Return an error instead of triggering an ASSERT() when duplicate CPU
definitions are detected.
- Replace BUG_ON() with ASSERT() for condition checks in
dt_init_cpu_topology().
- Update commit messages to remove details that no longer match the
current implementation.
Changes in v9:
- Add bounds checking for the number of private resources in the PPTT
processor table.
- Verify the validity of entries when indexing into the map_cpu_acpiid table.
- Coding style adjustments (following Xen standards):
* Place logical operators ('||', '&&') at the end of lines when splitting
multi-line conditions.
* Place arithmetic operators ('+', '-') at the end of lines when wrapping
long assignment statements.
* Enclose bitwise operations in parentheses within conditional expressions
that combine logical operators.
* Combine variable declaration and initialization where applicable.
Changes in v8:
- PPTT Table Validation & Hardening:
* Relaxed processor node length check to allow
proc->header.length >= table_size.
* Treated root nodes (nodes with parent == 0) as equivalent to
ACPI_PPTT_PHYSICAL_PACKAGE nodes.
- Build & Kconfig Adjustments:
* Removed leftovers of ACPI_CPU_TOPOLOGY definition from
xen/drivers/acpi/Kconfig.
- Code Cleanups & Style Conformance:
* Moved INVALID_ACPIID definition to xen/acpi.h to make it available
cross-architecture.
* Removed ARM-specific references from comments in
architecture-agnostic code.
* Added explicit parentheses around bitwise operations in logical
expressions.
* Placed binary logical operators (||, &&) at the end of lines when
splitting conditional statements.
* Combined variable declarations and initializations where appropriate.
* Removed trailing full stops ('.') from printk log messages.
* Fixed printk format specifier mix-up.
* Explicitly included <xen/cpu-topology.h> in xen/common/cpu.c.
Changes in v7:
- PPTT Table Validation & Hardening:
* find_pptt_node(): Added leaf node verification (ACPI 6.3+).
* acpi_init_cpu_topology(): Added bounds checks to ensure proc->parent
validly references memory strictly inside the PPTT table bounds.
* Factored out shared table checking helper functions used by both
find_pptt_node() and acpi_init_cpu_topology().
* Added subtable alignment checks and strengthened processor structure
size validation.
- Graceful Fallback & Allocation:
* Treated missing topology definitions as benign conditions.
* Used xvzalloc_array() for temporary memory allocations during
initialization.
- Build & Kconfig Adjustments:
* Updated Kconfig to use "depends on UNSUPPORTED" instead of "if UNSUPPORTED".
- Code Cleanups & Style Conformance:
* Used designated initializers for structure data initializations.
* Consolidated topology helpers with IS_ENABLED().
* Removed redundant error checks and reduced unnecessary pointer casts.
* Switched type-based sizeof(type) to variable-based sizeof(*var).
* Added leading spaces before labels ( out:)
Changes in v6:
- Renamed the series subject from "xen/arm: Device Tree based CPU topology
support" to reflect the inclusion of generic ACPI PPTT topology parsing.
- Infrastructure & Kconfig:
* Updated Kconfig to make both DT_CPU_TOPOLOGY and ACPI_CPU_TOPOLOGY
select GENERIC_CPU_TOPOLOGY.
* Ensured that if topology parsing from either DT or ACPI PPTT fails, the
CPU topology table is freed to fall back to the non-topology behavior.
* Moved the `cpu_topology` definition to `cpu.c` so that variables and
functions in `cpu-topology.c` can be completely freed after Xen init.
- Topology Logic (DT / ACPI):
* Set the cluster ID to 0 when the cluster definition is missing from the
Device Tree `cpu-map` node.
* Handled cases where cluster info is missing upon reaching a physical
package in the PPTT parser by assuming one cluster per socket.
* Split out the import of ACPI PPTT definitions from the Linux kernel
(including unused definitions) into a separate standalone patch.
- Robustness & Safety:
* Avoided assuming `np` becomes NULL after exiting `dt_for_each_child_node()`;
explicitly return NULL instead.
* Added bounds-checking `ASSERT`s for values returned by `cpumask_first()`.
* Added explicit braces `{}` to nested `if` statements to clarify `else`
scoping and maintain style symmetry.
* Enforced an upper limit on the PPTT parsing loop iterations to prevent
infinite loops on corrupted tables.
* Treat the absence of a physical package node definition in PPTT as a
parsing error.
- Optimization & Efficiency:
* Optimized `setup_siblings_masks()` to eliminate redundant loop iterations.
* Dynamically allocate the temporary data storage used during ACPI PPTT
parsing.
- Code Cleanup & Refactoring:
* Replaced the `invalid_topo_id` constant with the `INVALID_TOPO_ID` macro.
* Initialized all members of the `cpu_map` array with `INVALID_TOPO_ID`.
* Added a blank line between `<xen/...>` and `<asm/...>` header groups.
* Reordered `#ifdef` blocks to prioritize generic logic over architecture-
specific ones.
* Corrected code indentation.
* Applied the `static` specifier to file-local data structures and functions.
* Minimized the use of fixed-width `uint32_t` types, restricting its use only
where strictly required by the 32-bit ACPI ID specification.
* Declared `map_cpu_acpiid[]` as static and introduced the helper function
`acpi_map_cpu_acpiid()` for managed access.
* Renamed local variables to more intuitive names.
* Simplified the implementation of `get_logical_id()`.
* Refactored PPTT parsing to reduce type casting by using `container_of()`
and switching from `char *` to `void *` pointers.
* Removed redundant error checks.
* Cleaned up unused variables and eliminated debug print statements.
Changes in v5:
- Extracted CPU topology information from the ACPI PPTT.
- Corrected the erroneous use of CONFIG_CPU_TOPOLOGY to
CONFIG_GENERIC_CPU_TOPOLOGY.
Changes in v4:
- Only display the CPU topology configuration prompt in common/Kconfig
if the architecture defines HAS_GENERIC_CPU_TOPOLOGY.
- Move the definition of the global 'cpu_topology' pointer to
common/cpu-topology.c.
- Update the Makefile to explicitly build objects as .init.o when all
functions and data within a file are annotated with __init/__initdata,
ensuring their memory is reclaimed after system initialization.
- Add an error log in the CPU-to-node mapping function for out-of-bounds
cases.
- Use ARRAY_SIZE() instead of raw macros when guarding array accesses.
- Rename variables and functions to avoid ambiguous or misleading terms:
- Avoid 'cpuid' to prevent confusion with x86 CPUID features/instructions.
- Avoid 'node' where it could be confused with a NUMA node, explicitly
renaming them to clarify they refer to a Device Tree node.
- Move local variable declarations into the narrowest possible scope.
- Replace the unsupported "%pOF" printk format specifier with "%s" and
explicit node name retrieval.
- Remove #include <dt-cpu-topology.h> from cpu-topology.h, and ensure
the header directly includes only what its definitions require.
- Remove #include <xen/device_tree.h> from dt-cpu-topology.h, replacing
it with a forward declaration of 'struct dt_device_node'.
- Use 'const' qualifiers for pointer declarations where the pointed-to
structure is not modified.
- Explicitly #include <asm/processor.h> in cpu-topology.h to guarantee
that arch-specific definitions of cpu_to_core() and cpu_to_socket()
take precedence over the generic fallbacks.
- Introduce inline initialization functions for cpu_sibling_mask and
cpu_core_mask in cpu-topology.h, providing separate variants for both
when CONFIG_GENERIC_CPU_TOPOLOGY is enabled and disabled.
Changes in v3:
- Use (nr_cpu_ids - 1) as the maximum CPU ID here. The fix for the sparse
map mismatch issue on ARM Xen has been split out into a separate patch.
- Switch topology sibling masks to cpumask_var_t for dynamic allocation.
- Allow the system to keep running with a degraded fallback even if
the topology table allocation fails.
- Remove the temporary definitions of cpu_to_core() and cpu_to_socket()
from RISC-V and PPC processor.h.
- Minimize the use of #ifdef blocks, leveraging compiler Dead Code
Elimination (DCE) where possible.
- Clean up the code to follow the Xen coding style. Please let me know
if I missed any style nits!
- Verify successful builds across x86, RISC-V, and PPC environments.
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 (5):
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/acpi: Parse PPTT to initialize CPU topology
xen/acpi: Do not pass ACPI PPTT to Dom0
xen/arch/arm/Kconfig | 1 +
xen/arch/arm/acpi/boot.c | 2 +
xen/arch/arm/acpi/domain_build.c | 31 ++
xen/arch/arm/include/asm/processor.h | 4 -
xen/arch/arm/setup.c | 3 +
xen/arch/arm/smpboot.c | 44 ++-
xen/arch/ppc/include/asm/processor.h | 4 -
xen/arch/riscv/include/asm/processor.h | 4 -
xen/arch/x86/include/asm/acpi.h | 2 -
xen/arch/x86/include/asm/processor.h | 1 +
xen/common/Kconfig | 22 ++
xen/common/Makefile | 1 +
xen/common/cpu-topology.c | 81 +++++
xen/common/cpu.c | 5 +
xen/common/device-tree/Makefile | 1 +
xen/common/device-tree/cpu-topology.c | 427 +++++++++++++++++++++++++
xen/common/sched/credit2.c | 21 +-
xen/common/sysctl.c | 1 +
xen/drivers/acpi/Makefile | 1 +
xen/drivers/acpi/cpu-topology.c | 343 ++++++++++++++++++++
xen/include/xen/acpi.h | 17 +
xen/include/xen/cpu-topology.h | 59 ++++
xen/include/xen/dt-cpu-topology.h | 35 ++
23 files changed, 1070 insertions(+), 40 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/cpu-topology.c
create mode 100644 xen/include/xen/cpu-topology.h
create mode 100644 xen/include/xen/dt-cpu-topology.h
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
@ 2026-11-30 6:57 ` Hirokazu Takahashi
2026-12-01 11:22 ` Orzel, Michal
2026-11-30 6:57 ` [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler Hirokazu Takahashi
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel
Cc: michal.orzel, jbeulich, Hirokazu Takahashi, Stefano Stabellini,
Julien Grall, Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné
Parse the 'cpu-map' node in the Device Tree to extract CPU topology
information. If the 'cpu-map' node is absent, simply ignore it.
Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
---
Changes in v13:
- Rename drivers/acpi/topology.c to drivers/acpi/cpu-topology.c.
- Exit the loop immediately when memory allocation fails.
- Avoid printing redundant error messages on -ENOMEM.
- Do not log error messages on -ENOENT or -ENOTSUPP.
- Add appropriate XENLOG levels to printk() calls that lacked them.
- Replace dt_node_name() with dt_node_full_name() in error logs to
provide more detailed information.
xen/arch/arm/Kconfig | 1 +
xen/arch/arm/setup.c | 3 +
xen/arch/arm/smpboot.c | 10 +
xen/common/Kconfig | 22 ++
xen/common/Makefile | 1 +
xen/common/cpu-topology.c | 81 ++++++
xen/common/cpu.c | 5 +
xen/common/device-tree/Makefile | 1 +
xen/common/device-tree/cpu-topology.c | 374 ++++++++++++++++++++++++++
xen/drivers/acpi/Makefile | 1 +
xen/drivers/acpi/cpu-topology.c | 43 +++
xen/include/xen/acpi.h | 13 +
xen/include/xen/cpu-topology.h | 34 +++
xen/include/xen/dt-cpu-topology.h | 35 +++
14 files changed, 624 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/cpu-topology.c
create mode 100644 xen/include/xen/cpu-topology.h
create mode 100644 xen/include/xen/dt-cpu-topology.h
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index b9c5c40678..3d0f689220 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -19,6 +19,7 @@ config ARM
select HAS_ALTERNATIVE if HAS_VMAP
select HAS_DEVICE_TREE_DISCOVERY
select HAS_DOM0LESS
+ select HAS_GENERIC_CPU_TOPOLOGY
select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE
select HAS_SHARED_INFO
select HAS_STACK_PROTECTOR
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 2cd1c021b5..c1aa06bd31 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -10,6 +10,7 @@
#include <xen/bootinfo.h>
#include <xen/compile.h>
+#include <xen/cpu-topology.h>
#include <xen/device_tree.h>
#include <xen/dom0less-build.h>
#include <xen/domain_page.h>
@@ -375,6 +376,8 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)
nr_cpu_ids = smp_get_max_cpus();
printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", nr_cpu_ids);
+ init_cpu_topology();
+
/*
* Some errata relies on SMCCC version which is detected by psci_init()
* (called from smp_init_cpus()).
diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
index 2fc6c36ca1..97e227cd92 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -9,10 +9,12 @@
#include <xen/acpi.h>
#include <xen/cpu.h>
+#include <xen/cpu-topology.h>
#include <xen/cpumask.h>
#include <xen/delay.h>
#include <xen/device_tree.h>
#include <xen/domain_page.h>
+#include <xen/dt-cpu-topology.h>
#include <xen/errno.h>
#include <xen/init.h>
#include <xen/mm.h>
@@ -268,6 +270,14 @@ static void __init dt_smp_init_cpus(void)
}
else
tmp_map[i] = hwid;
+
+ /*
+ * Because the boot CPU (i == 0) is already running, treat it as valid
+ * even if arch_cpu_init() fails (e.g. due to a missing enable-method).
+ */
+ if ( (rc >= 0) || (i == 0) )
+ /* Pass the info to dt_init_cpu_topology() */
+ map_cpu_to_dt_node(i, cpu);
}
if ( !bootcpu_valid )
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index a619f2cef1..637ea0d486 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -143,6 +143,9 @@ config HAS_EX_TABLE
config HAS_FAST_MULTIPLY
bool
+config HAS_GENERIC_CPU_TOPOLOGY
+ bool
+
config HAS_IOPORTS
bool
@@ -197,6 +200,25 @@ config VM_EVENT
config NEEDS_LIBELF
bool
+config GENERIC_CPU_TOPOLOGY
+ bool
+
+config DT_CPU_TOPOLOGY
+ bool "Device tree based CPU topology support"
+ depends on HAS_GENERIC_CPU_TOPOLOGY && DEVICE_TREE_PARSE
+ select GENERIC_CPU_TOPOLOGY
+ help
+ Retrieve CPU topology information from the device tree to optimize
+ vCPU scheduling.
+
+config ACPI_CPU_TOPOLOGY
+ bool "ACPI based CPU topology support"
+ depends on HAS_GENERIC_CPU_TOPOLOGY && ACPI
+ select GENERIC_CPU_TOPOLOGY
+ help
+ Retrieve CPU topology information from the ACPI PPTT to optimize
+ vCPU scheduling.
+
config NUMA
bool
diff --git a/xen/common/Makefile b/xen/common/Makefile
index cbabaf1e2b..25a9feef10 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -6,6 +6,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_GENERIC_CPU_TOPOLOGY) += cpu-topology.init.o
obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += device.o
obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
diff --git a/xen/common/cpu-topology.c b/xen/common/cpu-topology.c
new file mode 100644
index 0000000000..e9275924ca
--- /dev/null
+++ b/xen/common/cpu-topology.c
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/acpi.h>
+#include <xen/cpu-topology.h>
+#include <xen/cpumask.h>
+#include <xen/dt-cpu-topology.h>
+#include <xen/init.h>
+#include <xen/xvmalloc.h>
+
+static void __init free_topology_table(void)
+{
+ unsigned int cpu;
+
+ if ( !cpu_topology )
+ return;
+
+ for ( cpu = 0; cpu < nr_cpu_ids; cpu++ )
+ {
+ free_cpumask_var(cpu_topology[cpu].thread_sibling);
+ free_cpumask_var(cpu_topology[cpu].core_sibling);
+ free_cpumask_var(cpu_topology[cpu].cluster_sibling);
+ }
+
+ XVFREE(cpu_topology);
+}
+
+void __init init_cpu_topology(void)
+{
+ unsigned int cpu;
+ int ret;
+
+ if ( num_possible_cpus() == 1 )
+ return;
+
+ cpu_topology = xvzalloc_array(struct cpu_topology, nr_cpu_ids);
+
+ if ( cpu_topology )
+ {
+ for ( cpu = 0; cpu < nr_cpu_ids; cpu++ )
+ {
+ if ( !zalloc_cpumask_var(&cpu_topology[cpu].thread_sibling) ||
+ !zalloc_cpumask_var(&cpu_topology[cpu].core_sibling) ||
+ !zalloc_cpumask_var(&cpu_topology[cpu].cluster_sibling) )
+ {
+ free_topology_table();
+ break;
+ }
+ }
+ }
+
+ if ( !cpu_topology )
+ {
+ printk(XENLOG_WARNING "CPU topology table allocation failed\n");
+ return;
+ }
+
+ if ( acpi_disabled )
+ ret = dt_init_cpu_topology();
+ else
+ ret = acpi_init_cpu_topology();
+
+ /* Free the CPU topology table if initialization fails. */
+ if ( ret != 0 )
+ {
+ free_topology_table();
+
+ if ( (ret != -ENOENT) && (ret != -EOPNOTSUPP) )
+ printk(XENLOG_WARNING
+ "Failed to initialize cpu topology (error %d)\n", ret);
+ }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index f09af0444b..9591ada60a 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -1,5 +1,6 @@
#include <xen/cpumask.h>
#include <xen/cpu.h>
+#include <xen/cpu-topology.h>
#include <xen/event.h>
#include <xen/init.h>
#include <xen/sched.h>
@@ -46,6 +47,10 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
#undef MASK_DECLARE_2
#undef MASK_DECLARE_1
+#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
+struct cpu_topology *__ro_after_init cpu_topology;
+#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
+
static DEFINE_RWLOCK(cpu_add_remove_lock);
bool get_cpu_maps(void)
diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makefile
index 730d202349..b15b3382d2 100644
--- a/xen/common/device-tree/Makefile
+++ b/xen/common/device-tree/Makefile
@@ -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.init.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
diff --git a/xen/common/device-tree/cpu-topology.c b/xen/common/device-tree/cpu-topology.c
new file mode 100644
index 0000000000..0561b4856d
--- /dev/null
+++ b/xen/common/device-tree/cpu-topology.c
@@ -0,0 +1,374 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Derived from Linux kernel 7.0's $drivers/base/arch_topology.c
+ * Parse cpu topology information.
+ */
+
+#include <xen/acpi.h>
+#include <xen/cpu-topology.h>
+#include <xen/cpumask.h>
+#include <xen/device_tree.h>
+#include <xen/errno.h>
+#include <xen/init.h>
+
+#define INVALID_TOPO_ID (~0U)
+
+struct cpu_map {
+ unsigned int thread_id;
+ unsigned int core_id;
+ unsigned int cluster_id;
+ unsigned int socket_id;
+};
+
+static struct cpu_map __initdata cpu_map[NR_CPUS] = {
+ [0 ... NR_CPUS - 1] = {
+ .thread_id = INVALID_TOPO_ID,
+ .core_id = INVALID_TOPO_ID,
+ .cluster_id = INVALID_TOPO_ID,
+ .socket_id = INVALID_TOPO_ID,
+ },
+};
+static struct dt_device_node *__initdata dt_cpu_table[NR_CPUS];
+
+static void __init setup_siblings_masks(unsigned int target_cpu)
+{
+ struct cpu_topology *target_topo = &cpu_topology[target_cpu];
+ const struct cpu_map *target_map = &cpu_map[target_cpu];
+ unsigned int cpu;
+
+ /* Update cluster, core and thread sibling masks */
+ for_each_possible_cpu(cpu)
+ {
+ struct cpu_topology *cpu_topo = &cpu_topology[cpu];
+ const struct cpu_map *map = &cpu_map[cpu];
+
+ if ( target_cpu > cpu )
+ continue;
+
+ if ( target_map->socket_id != map->socket_id )
+ continue;
+
+ cpumask_set_cpu(target_cpu, cpu_topo->core_sibling);
+ cpumask_set_cpu(cpu, target_topo->core_sibling);
+
+ if ( target_map->cluster_id != map->cluster_id )
+ continue;
+
+ cpumask_set_cpu(target_cpu, cpu_topo->cluster_sibling);
+ cpumask_set_cpu(cpu, target_topo->cluster_sibling);
+
+ if ( target_map->core_id != map->core_id )
+ continue;
+
+ cpumask_set_cpu(target_cpu, cpu_topo->thread_sibling);
+ cpumask_set_cpu(cpu, target_topo->thread_sibling);
+ }
+}
+
+static const struct dt_device_node *__init dt_find_child_node_by_name(
+ const struct dt_device_node *dt,
+ const char *name)
+{
+ const struct dt_device_node *np;
+
+ dt_for_each_child_node(dt, np)
+ if ( np->name && dt_node_name_is_equal(np, name) )
+ return np;
+
+ return NULL;
+}
+
+void __init map_cpu_to_dt_node(unsigned int cpu,
+ struct dt_device_node *cpu_node)
+{
+ if ( cpu < ARRAY_SIZE(dt_cpu_table) )
+ dt_cpu_table[cpu] = cpu_node;
+ else
+ printk(XENLOG_WARNING
+ "cpu %u exceeds the max cpus %zu\n",
+ cpu, ARRAY_SIZE(dt_cpu_table));
+}
+
+static unsigned int __init cpu_node_to_id(
+ const struct dt_device_node *cpu_node)
+{
+ unsigned int cpu;
+
+ for_each_possible_cpu(cpu)
+ if ( cpu_node == dt_cpu_table[cpu] )
+ return cpu;
+
+ return INVALID_TOPO_ID;
+}
+
+/*
+ * This function returns the Xen cpu number of the DT node.
+ */
+static int __init get_cpu_for_node(
+ const struct dt_device_node *dt_node, unsigned int *cpu)
+{
+ const struct dt_device_node *cpu_node =
+ dt_parse_phandle(dt_node, "cpu", 0);
+
+ if ( !cpu_node || !dt_device_type_is_equal(cpu_node, "cpu") )
+ {
+ *cpu = INVALID_TOPO_ID;
+ return -EINVAL;
+ }
+
+ *cpu = cpu_node_to_id(cpu_node);
+
+ return 0;
+}
+
+static bool __init is_cpu_map_empty(unsigned int cpu)
+{
+ return (cpu_map[cpu].socket_id == INVALID_TOPO_ID) &&
+ (cpu_map[cpu].cluster_id == INVALID_TOPO_ID) &&
+ (cpu_map[cpu].core_id == INVALID_TOPO_ID) &&
+ (cpu_map[cpu].thread_id == INVALID_TOPO_ID);
+}
+
+static int __init parse_core(const struct dt_device_node *core,
+ unsigned int socket_id,
+ unsigned int cluster_id,
+ unsigned int core_id)
+{
+ bool leaf = true;
+ unsigned int thread_id;
+ unsigned int cpu;
+ int ret;
+
+ for ( thread_id = 0; ; thread_id++ )
+ {
+ const struct dt_device_node *thread;
+ char name[20];
+
+ snprintf(name, sizeof(name), "thread%u", thread_id);
+ thread = dt_find_child_node_by_name(core, name);
+
+ if ( !thread )
+ break;
+
+ leaf = false;
+ ret = get_cpu_for_node(thread, &cpu);
+ if ( ret )
+ {
+ printk(XENLOG_ERR
+ "%s: No CPU found for thread\n", dt_node_full_name(thread));
+ return ret;
+ }
+
+ if ( cpu == INVALID_TOPO_ID )
+ {
+ /*
+ * Ignore this CPU node definition as the corresponding physical
+ * CPU is unavailable.
+ */
+ printk(XENLOG_INFO
+ "%s: CPU for thread is unavailable\n",
+ dt_node_full_name(thread));
+ continue;
+ }
+
+ if ( !is_cpu_map_empty(cpu) )
+ {
+ printk(XENLOG_ERR
+ "Duplicate CPU definition for CPU%u\n", cpu);
+ return -EINVAL;
+ }
+
+ cpu_map[cpu].socket_id = socket_id;
+ cpu_map[cpu].cluster_id = cluster_id;
+ cpu_map[cpu].core_id = core_id;
+ cpu_map[cpu].thread_id = thread_id;
+ }
+
+ ret = get_cpu_for_node(core, &cpu);
+
+ if ( cpu != INVALID_TOPO_ID )
+ {
+ if ( !leaf )
+ {
+ printk(XENLOG_ERR "%s: Core has both threads and CPU\n",
+ dt_node_full_name(core));
+ return -EINVAL;
+ }
+
+ if ( !is_cpu_map_empty(cpu) )
+ {
+ printk(XENLOG_ERR "Duplicate CPU definition for CPU%u\n", cpu);
+ return -EINVAL;
+ }
+
+ cpu_map[cpu].socket_id = socket_id;
+ cpu_map[cpu].cluster_id = cluster_id;
+ cpu_map[cpu].core_id = core_id;
+ cpu_map[cpu].thread_id = 0;
+ }
+ else if ( leaf )
+ {
+ if ( ret )
+ {
+ printk(XENLOG_ERR
+ "%s: No CPU found for leaf core\n",
+ dt_node_full_name(core));
+ return ret;
+ }
+
+ /*
+ * Ignore this CPU node definition as the corresponding physical
+ * CPU is unavailable.
+ */
+ printk(XENLOG_INFO
+ "%s: CPU for leaf core is unavailable\n",
+ dt_node_full_name(core));
+ }
+
+ return 0;
+}
+
+static int __init parse_cluster(const struct dt_device_node *cluster,
+ unsigned int socket_id,
+ unsigned int cluster_id)
+{
+ bool has_cores = false;
+ int ret = 0;
+
+ if ( dt_find_child_node_by_name(cluster, "cluster0") )
+ {
+ printk(XENLOG_ERR
+ "Topology for clusters of clusters not yet supported\n");
+ return -EINVAL;
+ }
+
+ for ( unsigned int core_id = 0; ; core_id++ )
+ {
+ const struct dt_device_node *core;
+ char name[20];
+
+ snprintf(name, sizeof(name), "core%u", core_id);
+ core = dt_find_child_node_by_name(cluster, name);
+
+ if ( !core )
+ break;
+
+ has_cores = true;
+
+ ret = parse_core(core, socket_id, cluster_id, core_id);
+ if ( ret != 0 )
+ return ret;
+ }
+
+ if ( !has_cores )
+ printk(XENLOG_WARNING "%s: empty cluster\n",
+ dt_node_full_name(cluster));
+
+ return ret;
+}
+
+static int __init parse_socket(const struct dt_device_node *socket,
+ unsigned int socket_id)
+{
+ bool has_cluster = false;
+ int ret = 0;
+
+ for ( unsigned int cluster_id = 0; ; cluster_id++ )
+ {
+ const struct dt_device_node *cluster;
+ char name[20];
+
+ snprintf(name, sizeof(name), "cluster%u", cluster_id);
+ cluster = dt_find_child_node_by_name(socket, name);
+
+ if ( !cluster )
+ break;
+
+ has_cluster = true;
+ ret = parse_cluster(cluster, socket_id, cluster_id);
+ if ( ret != 0 )
+ return ret;
+ }
+
+ /*
+ * If no cluster node is defined, assume the socket has
+ * a single cluster.
+ */
+ if ( !has_cluster )
+ ret = parse_cluster(socket, socket_id, 0);
+
+ return ret;
+}
+
+static int __init parse_package(const struct dt_device_node *package)
+{
+ bool has_socket = false;
+ int ret = 0;
+
+ for ( unsigned int socket_id = 0; ; socket_id++ )
+ {
+ const struct dt_device_node *socket;
+ char name[20];
+
+ snprintf(name, sizeof(name), "socket%u", socket_id);
+ socket = dt_find_child_node_by_name(package, name);
+
+ if ( !socket )
+ break;
+
+ has_socket = true;
+ ret = parse_socket(socket, socket_id);
+ if ( ret != 0 )
+ return ret;
+ }
+
+ /*
+ * If no socket node is defined, assume all clusters reside under
+ * a single socket.
+ */
+ if ( !has_socket )
+ ret = parse_socket(package, 0);
+
+ return ret;
+}
+
+static int __init parse_dt_topology(void)
+{
+ const struct dt_device_node *cpus;
+ const struct dt_device_node *map;
+
+ cpus = dt_find_node_by_path("/cpus");
+ if ( !cpus )
+ return -ENOENT;
+
+ map = dt_find_child_node_by_name(cpus, "cpu-map");
+ if ( !map )
+ return -ENOENT;
+
+ return parse_package(map);
+}
+
+int __init dt_init_cpu_topology(void)
+{
+ unsigned int cpu;
+ int ret;
+
+ ASSERT(cpu_topology);
+
+ ret = parse_dt_topology();
+ if ( ret == 0 )
+ for_each_possible_cpu(cpu)
+ setup_siblings_masks(cpu);
+
+ return ret;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile
index 477408afbe..8337f4cc8b 100644
--- a/xen/drivers/acpi/Makefile
+++ b/xen/drivers/acpi/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_NUMA) += numa.o
obj-y += osl.o
obj-$(CONFIG_PM_STATS) += pmstat.o
obj-$(CONFIG_PM_OP) += pm-op.o
+obj-$(CONFIG_ACPI_CPU_TOPOLOGY) += cpu-topology.init.o
obj-$(CONFIG_X86) += hwregs.o
obj-$(CONFIG_X86) += reboot.o
diff --git a/xen/drivers/acpi/cpu-topology.c b/xen/drivers/acpi/cpu-topology.c
new file mode 100644
index 0000000000..f9836447b2
--- /dev/null
+++ b/xen/drivers/acpi/cpu-topology.c
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/acpi.h>
+#include <xen/cpu-topology.h>
+#include <xen/cpumask.h>
+#include <xen/init.h>
+
+/*
+ * TODO: Populate the topology information by scanning the ACPI
+ * PPTT (Processor Properties Topology Table).
+ */
+int __init acpi_init_cpu_topology(void)
+{
+ unsigned int cpu;
+
+ ASSERT(cpu_topology);
+
+ /*
+ * 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);
+ cpumask_copy(topo->cluster_sibling, &cpu_possible_map);
+ }
+
+ return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h
index 2fdf38cf74..cbb02e0f35 100644
--- a/xen/include/xen/acpi.h
+++ b/xen/include/xen/acpi.h
@@ -135,6 +135,19 @@ static inline int acpi_boot_table_init(void)
#endif /*!CONFIG_ACPI*/
+#ifdef CONFIG_ACPI_CPU_TOPOLOGY
+
+int acpi_init_cpu_topology(void);
+
+#else /* CONFIG_ACPI_CPU_TOPOLOGY */
+
+static inline int acpi_init_cpu_topology(void)
+{
+ return -EOPNOTSUPP;
+}
+
+#endif /* CONFIG_ACPI_CPU_TOPOLOGY */
+
int get_cpu_id(u32 acpi_id);
unsigned int acpi_register_gsi (u32 gsi, int edge_level, int active_high_low);
diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h
new file mode 100644
index 0000000000..27b9bd443e
--- /dev/null
+++ b/xen/include/xen/cpu-topology.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_CPU_TOPOLOGY_H
+#define XEN_CPU_TOPOLOGY_H
+
+#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
+
+#include <xen/cpumask.h>
+
+struct cpu_topology {
+ cpumask_var_t thread_sibling;
+ cpumask_var_t core_sibling;
+ cpumask_var_t cluster_sibling;
+};
+
+extern struct cpu_topology *cpu_topology;
+void init_cpu_topology(void);
+
+#else /* CONFIG_GENERIC_CPU_TOPOLOGY */
+
+static inline void init_cpu_topology(void) {}
+
+#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
+
+#endif /* XEN_CPU_TOPOLOGY_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/dt-cpu-topology.h b/xen/include/xen/dt-cpu-topology.h
new file mode 100644
index 0000000000..43f7b31bf6
--- /dev/null
+++ b/xen/include/xen/dt-cpu-topology.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_DT_CPU_TOPOLOGY_H
+#define XEN_DT_CPU_TOPOLOGY_H
+
+struct dt_device_node;
+
+#ifdef CONFIG_DT_CPU_TOPOLOGY
+
+void map_cpu_to_dt_node(unsigned int cpu, struct dt_device_node *cpu_node);
+int dt_init_cpu_topology(void);
+
+#else /* CONFIG_DT_CPU_TOPOLOGY */
+
+#include <xen/errno.h>
+
+static inline void map_cpu_to_dt_node(unsigned int cpu,
+ struct dt_device_node *cpu_node) {}
+static inline int dt_init_cpu_topology(void)
+{
+ return -EOPNOTSUPP;
+}
+
+#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:
+ */
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Hirokazu Takahashi
@ 2026-11-30 6:57 ` Hirokazu Takahashi
2026-12-01 13:20 ` Orzel, Michal
2026-11-30 6:57 ` [PATCH v13 3/5] xen/sched: Make cpu_nr_siblings() architecture-specific Hirokazu Takahashi
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel
Cc: michal.orzel, jbeulich, Hirokazu Takahashi, Juergen Gross,
Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk, Andrew Cooper, Anthony PERARD,
Roger Pau Monné, Timothy Pearson, Alistair Francis,
Baptiste Le Duc, Connor Davis, Oleksii Kurochko, Dario Faggioli,
George Dunlap
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@valinux.co.jp>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com> # scheduler part
---
xen/arch/arm/include/asm/processor.h | 4 --
xen/arch/arm/smpboot.c | 34 ++++++++++++-----
xen/arch/ppc/include/asm/processor.h | 4 --
xen/arch/riscv/include/asm/processor.h | 4 --
xen/common/device-tree/cpu-topology.c | 53 ++++++++++++++++++++++++++
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, 110 insertions(+), 23 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..41162f8ea1 100644
--- a/xen/arch/arm/smpboot.c
+++ b/xen/arch/arm/smpboot.c
@@ -103,17 +103,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 +136,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 0561b4856d..cef80f7240 100644
--- a/xen/common/device-tree/cpu-topology.c
+++ b/xen/common/device-tree/cpu-topology.c
@@ -348,6 +348,55 @@ static int __init parse_dt_topology(void)
return parse_package(map);
}
+static void __init setup_cpu_topology_ids(void)
+{
+ unsigned int cpu;
+ unsigned int next_core_id = 0;
+ unsigned int next_cluster_id = 0;
+ unsigned int next_socket_id = 0;
+
+ for_each_possible_cpu(cpu)
+ {
+ unsigned int first_cpu;
+ struct cpu_topology *topo = &cpu_topology[cpu];
+
+ first_cpu = cpumask_first(topo->thread_sibling);
+ ASSERT(first_cpu < nr_cpu_ids);
+
+ if ( first_cpu == cpu )
+ {
+ topo->phys_core_id = next_core_id;
+ next_core_id++;
+ }
+ else
+ topo->phys_core_id = cpu_topology[first_cpu].phys_core_id;
+
+ first_cpu = cpumask_first(topo->cluster_sibling);
+ ASSERT(first_cpu < nr_cpu_ids);
+
+ if ( first_cpu == cpu )
+ {
+ topo->phys_cluster_id = next_cluster_id;
+ next_cluster_id++;
+ }
+ else
+ topo->phys_cluster_id = cpu_topology[first_cpu].phys_cluster_id;
+
+ first_cpu = cpumask_first(topo->core_sibling);
+ ASSERT(first_cpu < nr_cpu_ids);
+
+ if ( first_cpu == cpu )
+ {
+ topo->phys_socket_id = next_socket_id;
+ next_socket_id++;
+ }
+ else
+ topo->phys_socket_id = cpu_topology[first_cpu].phys_socket_id;
+
+ topo->num_siblings = cpumask_weight(topo->thread_sibling);
+ }
+}
+
int __init dt_init_cpu_topology(void)
{
unsigned int cpu;
@@ -357,9 +406,13 @@ int __init dt_init_cpu_topology(void)
ret = parse_dt_topology();
if ( ret == 0 )
+ {
for_each_possible_cpu(cpu)
setup_siblings_masks(cpu);
+ setup_cpu_topology_ids();
+ }
+
return ret;
}
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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v13 3/5] xen/sched: Make cpu_nr_siblings() architecture-specific
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler Hirokazu Takahashi
@ 2026-11-30 6:57 ` Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 4/5] xen/acpi: Parse PPTT to initialize CPU topology Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0 Hirokazu Takahashi
4 siblings, 0 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel
Cc: michal.orzel, jbeulich, Hirokazu Takahashi, Juergen Gross,
Andrew Cooper, Roger Pau Monné, Teddy Astie, Anthony PERARD,
Julien Grall, Stefano Stabellini, Dario Faggioli, George Dunlap
Make cpu_nr_siblings() an architecture-specific function.
This patch provides the implementation for x86 and a common
version for Device Tree-based architectures.
Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
Acked-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Juergen Gross <jgross@suse.com> # scheduler part
---
xen/arch/x86/include/asm/processor.h | 1 +
xen/common/sched/credit2.c | 25 +++----------------------
xen/include/xen/cpu-topology.h | 5 +++++
3 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/xen/arch/x86/include/asm/processor.h b/xen/arch/x86/include/asm/processor.h
index 4b17e13a97..049b917c49 100644
--- a/xen/arch/x86/include/asm/processor.h
+++ b/xen/arch/x86/include/asm/processor.h
@@ -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);
diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c
index be20ca316b..0ccd469e0c 100644
--- a/xen/common/sched/credit2.c
+++ b/xen/common/sched/credit2.c
@@ -29,25 +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_GENERIC_CPU_TOPOLOGY
- if ( cpu_topology )
- return cpu_topology[cpu].num_siblings;
-#endif
-
-#ifdef CONFIG_X86
- return cpu_data[cpu].x86_num_siblings;
-#else
- return 1;
-#endif
-}
-
/*
* Credit2 tracing events ("only" 512 available!). Check
* include/public/trace.h for more details.
@@ -885,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
diff --git a/xen/include/xen/cpu-topology.h b/xen/include/xen/cpu-topology.h
index e70d14b581..5beb52c6c2 100644
--- a/xen/include/xen/cpu-topology.h
+++ b/xen/include/xen/cpu-topology.h
@@ -27,6 +27,7 @@ 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)
+#define cpu_nr_siblings(cpu) (cpu_topology ? cpu_topology[cpu].num_siblings : 1)
#else /* CONFIG_GENERIC_CPU_TOPOLOGY */
@@ -40,6 +41,10 @@ static inline void init_cpu_topology(void) {}
#define cpu_to_socket(cpu) (0)
#endif
+#ifndef cpu_nr_siblings
+#define cpu_nr_siblings(cpu) (1)
+#endif
+
#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
#endif /* XEN_CPU_TOPOLOGY_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v13 4/5] xen/acpi: Parse PPTT to initialize CPU topology
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
` (2 preceding siblings ...)
2026-11-30 6:57 ` [PATCH v13 3/5] xen/sched: Make cpu_nr_siblings() architecture-specific Hirokazu Takahashi
@ 2026-11-30 6:57 ` Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0 Hirokazu Takahashi
4 siblings, 0 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel
Cc: michal.orzel, jbeulich, Hirokazu Takahashi, Stefano Stabellini,
Julien Grall, Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné, Teddy Astie
Parse the ACPI PPTT (Processor Properties Topology Table) to
initialize the CPU topology.
For ACPI 6.3 and later, the ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD flag
is checked to determine the presence of threading. For ACPI 6.2 and
earlier, CPUs are assumed not to support threading.
Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
xen/arch/arm/acpi/boot.c | 2 +
xen/arch/x86/include/asm/acpi.h | 2 -
xen/drivers/acpi/cpu-topology.c | 323 ++++++++++++++++++++++++++++++--
xen/include/xen/acpi.h | 4 +
4 files changed, 316 insertions(+), 15 deletions(-)
diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c
index 4ac0fd8f51..fc7ecb5749 100644
--- a/xen/arch/arm/acpi/boot.c
+++ b/xen/arch/arm/acpi/boot.c
@@ -85,6 +85,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
return;
}
bootcpu_valid = true;
+ acpi_map_cpu_acpiid(0, processor->uid);
return;
}
@@ -119,6 +120,7 @@ acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
/* map the logical cpu id to cpu MPIDR */
cpu_logical_map(enabled_cpus) = mpidr;
+ acpi_map_cpu_acpiid(enabled_cpus, processor->uid);
enabled_cpus++;
}
diff --git a/xen/arch/x86/include/asm/acpi.h b/xen/arch/x86/include/asm/acpi.h
index 217819dd61..7a89baa143 100644
--- a/xen/arch/x86/include/asm/acpi.h
+++ b/xen/arch/x86/include/asm/acpi.h
@@ -132,8 +132,6 @@ struct acpi_sleep_info {
extern u32 x86_acpiid_to_apicid[];
#define MAX_LOCAL_APIC MAX(256, 4 * NR_CPUS)
-#define INVALID_ACPIID (-1U)
-
extern u32 pmtmr_ioport;
extern unsigned int pmtmr_width;
diff --git a/xen/drivers/acpi/cpu-topology.c b/xen/drivers/acpi/cpu-topology.c
index 32f5b97c3e..d727e6f15e 100644
--- a/xen/drivers/acpi/cpu-topology.c
+++ b/xen/drivers/acpi/cpu-topology.c
@@ -4,35 +4,332 @@
#include <xen/cpu-topology.h>
#include <xen/cpumask.h>
#include <xen/init.h>
+#include <xen/xvmalloc.h>
+
+#define ACPI_PPTT_MAX_LEVELS 16
+
+static uint32_t __initdata map_cpu_acpiid[NR_CPUS] = {
+ [0 ... NR_CPUS - 1] = INVALID_ACPIID
+};
/*
- * TODO: Populate the topology information by scanning the ACPI
- * PPTT (Processor Properties Topology Table).
+ * The first argument 'cpu' is the logical CPU ID assigned by Xen,
+ * and the second argument 'acpi_id' the 32-bit ACPI processor ID.
+ */
+void __init acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id)
+{
+ map_cpu_acpiid[cpu] = acpi_id;
+}
+
+static unsigned int __init get_logical_id(unsigned int key,
+ unsigned int *map,
+ unsigned int *count)
+{
+ unsigned int id;
+
+ for ( id = 0; id < *count; id++ )
+ if ( map[id] == key )
+ return id;
+
+ map[*count] = key;
+
+ return (*count)++;
+}
+
+static bool __init verify_subtable(const struct acpi_subtable_header *entry,
+ const struct acpi_table_pptt *pptt)
+{
+ unsigned long table_end = (unsigned long)pptt + pptt->header.length;
+
+ if ( entry->length < sizeof(*entry) || (entry->length & 3) )
+ {
+ printk(XENLOG_ERR "ACPI: PPTT subtable length is invalid\n");
+ return false;
+ }
+
+ if ( (unsigned long)entry + entry->length > table_end )
+ {
+ printk(XENLOG_ERR "ACPI: PPTT subtable extends beyond table end\n");
+ return false;
+ }
+
+ return true;
+}
+
+static bool __init verify_proc(const struct acpi_pptt_processor *proc)
+{
+ unsigned long table_size;
+
+ if ( proc->header.length < sizeof(*proc) )
+ {
+ printk(XENLOG_ERR "ACPI: PPTT processor node length is too small\n");
+ return false;
+ }
+
+ /*
+ * Each private resource is represented by a 32-bit resource ID.
+ * Reject if the number of private resources exceeds what can fit in
+ * the 8-bit limit of proc->header.length.
+ */
+ if ( proc->number_of_priv_resources >
+ (UINT8_MAX - sizeof(*proc)) / sizeof(uint32_t) )
+ {
+ printk(XENLOG_ERR "ACPI: PPTT too many private resources\n");
+ return false;
+ }
+
+ /*
+ * Ensure the structure length accurately accounts for the trailing array.
+ */
+ table_size = sizeof(*proc) +
+ proc->number_of_priv_resources * sizeof(uint32_t);
+
+ if ( proc->header.length < table_size )
+ {
+ printk(XENLOG_ERR "ACPI: PPTT processor node length invalid\n");
+ return false;
+ }
+
+ return true;
+}
+
+static const struct acpi_pptt_processor *__init find_pptt_node(
+ const struct acpi_table_pptt *pptt, uint32_t acpi_id)
+{
+ const struct acpi_subtable_header *entry;
+ unsigned long table_end = (unsigned long)pptt + pptt->header.length;
+ const void *ptr = pptt + 1;
+
+ while ( (unsigned long)ptr + sizeof(*entry) <= table_end )
+ {
+ entry = ptr;
+
+ if ( !verify_subtable(entry, pptt) )
+ break;
+
+ if ( entry->type == ACPI_PPTT_TYPE_PROCESSOR )
+ {
+ const struct acpi_pptt_processor *proc =
+ container_of(entry, const struct acpi_pptt_processor, header);
+
+ if ( !verify_proc(proc) )
+ break;
+
+ /*
+ * Leaf node verification is only required for ACPI 6.3
+ * (PPTT revision 2) or later.
+ */
+ if ( (proc->flags & ACPI_PPTT_ACPI_PROCESSOR_ID_VALID) &&
+ proc->acpi_processor_id == acpi_id &&
+ (pptt->header.revision < 2 ||
+ (proc->flags & ACPI_PPTT_ACPI_LEAF_NODE)) )
+ return proc;
+ }
+
+ ptr += entry->length;
+ }
+
+ return NULL;
+}
+
+/*
+ * Populate the topology information by scanning the ACPI PPTT
+ * (Processor Properties Topology Table).
*/
int __init acpi_init_cpu_topology(void)
{
+ struct acpi_table_header *table_header;
+ const struct acpi_table_pptt *pptt;
+ unsigned int num_sockets = 0;
+ unsigned int num_clusters = 0;
+ unsigned int num_cores = 0;
+ unsigned int *socket_map = xvzalloc_array(unsigned int, nr_cpu_ids);
+ unsigned int *cluster_map = xvzalloc_array(unsigned int, nr_cpu_ids);
+ unsigned int *core_map = xvzalloc_array(unsigned int, nr_cpu_ids);
unsigned int cpu;
+ int ret = 0;
+ acpi_status status = acpi_get_table(ACPI_SIG_PPTT, 0, &table_header);
ASSERT(cpu_topology);
- /*
- * Generate temporary cpu topology information for now.
- * It assumes that the cpu doesn't have SMT and all CPUs
- * belong to the same socket.
- */
+ if ( ACPI_FAILURE(status) )
+ {
+ /* A missing PPTT is benign; fall back to the default topology. */
+ ret = -ENOENT;
+ goto out;
+ }
+
+ if ( !socket_map || !cluster_map || !core_map )
+ {
+ printk(XENLOG_ERR
+ "ACPI: Failed to allocate memory for topology parsing\n");
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ pptt = container_of(table_header, const struct acpi_table_pptt, header);
+
+ for_each_possible_cpu(cpu)
+ {
+ uint32_t acpi_id = map_cpu_acpiid[cpu];
+ struct cpu_topology *topo = &cpu_topology[cpu];
+ const struct acpi_pptt_processor *proc;
+ unsigned int level;
+ unsigned int core_group_key = 0;
+ unsigned int cluster_group_key = 0;
+ unsigned int socket_group_key = 0;
+ bool threading = false;
+
+ if ( acpi_id == INVALID_ACPIID )
+ {
+ printk(XENLOG_WARNING "ACPI: Invalid ACPI ID for CPU %u\n", cpu);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ proc = find_pptt_node(pptt, acpi_id);
+ if ( !proc )
+ {
+ printk(XENLOG_WARNING
+ "ACPI: No PPTT leaf node for CPU %u (ACPI ID %#x)\n",
+ cpu, acpi_id);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ /*
+ * Limit the maximum loop depth to prevent an infinite loop in case
+ * the PPTT is corrupted or contains cyclic references.
+ */
+ for ( level = 0; level < ACPI_PPTT_MAX_LEVELS; level++ )
+ {
+ const unsigned int offset = (const void *)proc - (const void *)pptt;
+
+ /*
+ * If this proc has no parent node, it is the root node. Treat it
+ * as equivalent to an ACPI_PPTT_PHYSICAL_PACKAGE node.
+ */
+ if ( (proc->flags & ACPI_PPTT_PHYSICAL_PACKAGE) || !proc->parent )
+ {
+ socket_group_key = offset;
+
+ /*
+ * If cluster/core info is absent upon reaching the physical
+ * package, assume one cluster per socket and one core per
+ * cluster.
+ */
+ if ( cluster_group_key == 0 )
+ cluster_group_key = socket_group_key;
+
+ if ( core_group_key == 0 )
+ core_group_key = cluster_group_key;
+
+ break;
+ }
+ else if ( level == 0 )
+ {
+ /*
+ * ACPI_PPTT_PROCESSOR_IS_THREAD is supported in PPTT
+ * revision 2 and later. Assume no threading support when
+ * PPTT revision is 1.
+ */
+ if ( proc->flags & ACPI_PPTT_ACPI_PROCESSOR_IS_THREAD )
+ threading = true;
+ else
+ core_group_key = offset;
+ }
+ else if ( level == 1 )
+ {
+ if ( threading )
+ core_group_key = offset;
+ else
+ cluster_group_key = offset;
+ }
+ else if ( level == 2 && threading )
+ cluster_group_key = offset;
+
+ if ( (proc->parent & 3) ||
+ proc->parent < sizeof(*pptt) ||
+ proc->parent > pptt->header.length - sizeof(*proc) ||
+ (proc->parent + sizeof(*proc) > offset &&
+ proc->parent < offset + proc->header.length) )
+ {
+ printk(XENLOG_WARNING
+ "ACPI: PPTT parent offset is invalid\n");
+ break;
+ }
+
+ proc = (const void *)pptt + proc->parent;
+
+ if ( proc->header.type != ACPI_PPTT_TYPE_PROCESSOR )
+ {
+ printk(XENLOG_WARNING
+ "ACPI: PPTT parent node is not a processor structure\n");
+ break;
+ }
+
+ if ( !verify_subtable(&proc->header, pptt) ||
+ !verify_proc(proc) )
+ break;
+ }
+
+ if ( socket_group_key == 0 )
+ {
+ printk(XENLOG_WARNING
+ "ACPI: Could not reach the physical package node for CPU %u (ACPI ID %#x)\n",
+ cpu, acpi_id);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ topo->phys_socket_id =
+ get_logical_id(socket_group_key, socket_map, &num_sockets);
+ topo->phys_cluster_id =
+ get_logical_id(cluster_group_key, cluster_map, &num_clusters);
+ topo->phys_core_id =
+ get_logical_id(core_group_key, core_map, &num_cores);
+ }
+
for_each_possible_cpu(cpu)
{
struct cpu_topology *topo = &cpu_topology[cpu];
+ unsigned int tcpu;
- topo->phys_core_id = cpu;
- topo->num_siblings = 1;
+ for_each_possible_cpu(tcpu)
+ {
+ struct cpu_topology *ttopo = &cpu_topology[tcpu];
- cpumask_set_cpu(cpu, topo->thread_sibling);
- cpumask_copy(topo->core_sibling, &cpu_possible_map);
- cpumask_copy(topo->cluster_sibling, &cpu_possible_map);
+ if ( cpu > tcpu )
+ continue;
+
+ if ( topo->phys_core_id == ttopo->phys_core_id )
+ {
+ cpumask_set_cpu(tcpu, topo->thread_sibling);
+ cpumask_set_cpu(cpu, ttopo->thread_sibling);
+ }
+
+ if ( topo->phys_cluster_id == ttopo->phys_cluster_id )
+ {
+ cpumask_set_cpu(tcpu, topo->cluster_sibling);
+ cpumask_set_cpu(cpu, ttopo->cluster_sibling);
+ }
+
+ if ( topo->phys_socket_id == ttopo->phys_socket_id )
+ {
+ cpumask_set_cpu(tcpu, topo->core_sibling);
+ cpumask_set_cpu(cpu, ttopo->core_sibling);
+ }
+ }
+
+ topo->num_siblings = cpumask_weight(topo->thread_sibling);
}
- return 0;
+ out:
+ xvfree(socket_map);
+ xvfree(cluster_map);
+ xvfree(core_map);
+
+ return ret;
}
/*
diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h
index cbb02e0f35..9788586be4 100644
--- a/xen/include/xen/acpi.h
+++ b/xen/include/xen/acpi.h
@@ -52,6 +52,8 @@
(!(entry)) || (unsigned long)(entry) + sizeof(*(entry)) > (end) || \
(entry)->header.length < sizeof(*(entry)))
+#define INVALID_ACPIID (-1U)
+
#ifdef CONFIG_ACPI
#include <acpi/acpi.h>
@@ -137,10 +139,12 @@ static inline int acpi_boot_table_init(void)
#ifdef CONFIG_ACPI_CPU_TOPOLOGY
+void acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id);
int acpi_init_cpu_topology(void);
#else /* CONFIG_ACPI_CPU_TOPOLOGY */
+static inline void acpi_map_cpu_acpiid(unsigned int cpu, uint32_t acpi_id) {}
static inline int acpi_init_cpu_topology(void)
{
return -EOPNOTSUPP;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
` (3 preceding siblings ...)
2026-11-30 6:57 ` [PATCH v13 4/5] xen/acpi: Parse PPTT to initialize CPU topology Hirokazu Takahashi
@ 2026-11-30 6:57 ` Hirokazu Takahashi
2026-12-01 13:31 ` Orzel, Michal
4 siblings, 1 reply; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-11-30 6:57 UTC (permalink / raw)
To: xen-devel
Cc: michal.orzel, jbeulich, Hirokazu Takahashi, Stefano Stabellini,
Julien Grall, Bertrand Marquis, Volodymyr Babchuk
The PPTT received by Xen shows the topology of the physical CPUs,
rather than the vCPUs used by Dom0. Leave topology-aware
scheduling to Xen.
Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
---
Changes in v13:
- Do not pass ACPI PPTT to Dom0, as PPTT does not represent the
topology of Dom0 vCPUs.
xen/arch/arm/acpi/domain_build.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/xen/arch/arm/acpi/domain_build.c b/xen/arch/arm/acpi/domain_build.c
index db16f7fa94..89c69e647d 100644
--- a/xen/arch/arm/acpi/domain_build.c
+++ b/xen/arch/arm/acpi/domain_build.c
@@ -263,6 +263,34 @@ static void __init acpi_xsdt_modify_entry(u64 entry[],
}
}
+static bool __init acpi_xsdt_remove_entry(u64 entry[],
+ unsigned long *entry_count,
+ const char *signature)
+{
+ unsigned long i;
+ struct acpi_table_header *table;
+ u64 size = sizeof(*table);
+
+ for ( i = 0; i < *entry_count; i++ )
+ {
+ table = acpi_os_map_memory(entry[i], size);
+ if ( !table )
+ continue;
+
+ if ( ACPI_COMPARE_NAME(table->signature, signature) )
+ {
+ acpi_os_unmap_memory(table, size);
+ memmove(&entry[i], &entry[i + 1],
+ (*entry_count - i - 1) * sizeof(u64));
+ (*entry_count)--;
+ return true;
+ }
+ acpi_os_unmap_memory(table, size);
+ }
+
+ return false;
+}
+
static int __init acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
{
struct acpi_table_header *table = NULL;
@@ -298,6 +326,9 @@ static int __init acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
ACPI_SIG_FADT, tbl_add[TBL_FADT].start);
acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count,
ACPI_SIG_MADT, tbl_add[TBL_MADT].start);
+ if ( acpi_xsdt_remove_entry(xsdt->table_offset_entry, &entry_count,
+ "PPTT") )
+ table_size -= sizeof(u64);
xsdt->table_offset_entry[entry_count] = tbl_add[TBL_STAO].start;
xsdt->header.length = table_size;
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
2026-11-30 6:57 ` [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Hirokazu Takahashi
@ 2026-12-01 11:22 ` Orzel, Michal
2026-12-02 3:55 ` Hirokazu Takahashi
0 siblings, 1 reply; 12+ messages in thread
From: Orzel, Michal @ 2026-12-01 11:22 UTC (permalink / raw)
To: Hirokazu Takahashi, xen-devel
Cc: jbeulich, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk, Andrew Cooper, Anthony PERARD,
Roger Pau Monné
On 30-Nov-26 07:57, Hirokazu Takahashi wrote:
> Parse the 'cpu-map' node in the Device Tree to extract CPU topology
> information. If the 'cpu-map' node is absent, simply ignore it.
For the v14, that hopefully will be the last revision of this patch, can you
please extend the commit msg. For such a big change it deserves a proper commit
msg explaining what, why and how.
>
> Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
> ---
> Changes in v13:
> - Rename drivers/acpi/topology.c to drivers/acpi/cpu-topology.c.
> - Exit the loop immediately when memory allocation fails.
> - Avoid printing redundant error messages on -ENOMEM.
> - Do not log error messages on -ENOENT or -ENOTSUPP.
> - Add appropriate XENLOG levels to printk() calls that lacked them.
> - Replace dt_node_name() with dt_node_full_name() in error logs to
> provide more detailed information.
>
> xen/arch/arm/Kconfig | 1 +
> xen/arch/arm/setup.c | 3 +
> xen/arch/arm/smpboot.c | 10 +
> xen/common/Kconfig | 22 ++
> xen/common/Makefile | 1 +
> xen/common/cpu-topology.c | 81 ++++++
> xen/common/cpu.c | 5 +
> xen/common/device-tree/Makefile | 1 +
> xen/common/device-tree/cpu-topology.c | 374 ++++++++++++++++++++++++++
> xen/drivers/acpi/Makefile | 1 +
> xen/drivers/acpi/cpu-topology.c | 43 +++
> xen/include/xen/acpi.h | 13 +
> xen/include/xen/cpu-topology.h | 34 +++
> xen/include/xen/dt-cpu-topology.h | 35 +++
> 14 files changed, 624 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/cpu-topology.c
> create mode 100644 xen/include/xen/cpu-topology.h
> create mode 100644 xen/include/xen/dt-cpu-topology.h
>
> diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
> index b9c5c40678..3d0f689220 100644
> --- a/xen/arch/arm/Kconfig
> +++ b/xen/arch/arm/Kconfig
> @@ -19,6 +19,7 @@ config ARM
> select HAS_ALTERNATIVE if HAS_VMAP
> select HAS_DEVICE_TREE_DISCOVERY
> select HAS_DOM0LESS
> + select HAS_GENERIC_CPU_TOPOLOGY
> select HAS_GRANT_CACHE_FLUSH if GRANT_TABLE
> select HAS_SHARED_INFO
> select HAS_STACK_PROTECTOR
> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index 2cd1c021b5..c1aa06bd31 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -10,6 +10,7 @@
>
> #include <xen/bootinfo.h>
> #include <xen/compile.h>
> +#include <xen/cpu-topology.h>
> #include <xen/device_tree.h>
> #include <xen/dom0less-build.h>
> #include <xen/domain_page.h>
> @@ -375,6 +376,8 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)
> nr_cpu_ids = smp_get_max_cpus();
> printk(XENLOG_INFO "SMP: Allowing %u CPUs\n", nr_cpu_ids);
>
> + init_cpu_topology();
> +
> /*
> * Some errata relies on SMCCC version which is detected by psci_init()
> * (called from smp_init_cpus()).
> diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
> index 2fc6c36ca1..97e227cd92 100644
> --- a/xen/arch/arm/smpboot.c
> +++ b/xen/arch/arm/smpboot.c
> @@ -9,10 +9,12 @@
>
> #include <xen/acpi.h>
> #include <xen/cpu.h>
> +#include <xen/cpu-topology.h>
> #include <xen/cpumask.h>
> #include <xen/delay.h>
> #include <xen/device_tree.h>
> #include <xen/domain_page.h>
> +#include <xen/dt-cpu-topology.h>
> #include <xen/errno.h>
> #include <xen/init.h>
> #include <xen/mm.h>
> @@ -268,6 +270,14 @@ static void __init dt_smp_init_cpus(void)
> }
> else
> tmp_map[i] = hwid;
> +
> + /*
> + * Because the boot CPU (i == 0) is already running, treat it as valid
> + * even if arch_cpu_init() fails (e.g. due to a missing enable-method).
> + */
> + if ( (rc >= 0) || (i == 0) )
> + /* Pass the info to dt_init_cpu_topology() */
> + map_cpu_to_dt_node(i, cpu);
> }
>
> if ( !bootcpu_valid )
> diff --git a/xen/common/Kconfig b/xen/common/Kconfig
> index a619f2cef1..637ea0d486 100644
> --- a/xen/common/Kconfig
> +++ b/xen/common/Kconfig
> @@ -143,6 +143,9 @@ config HAS_EX_TABLE
> config HAS_FAST_MULTIPLY
> bool
>
> +config HAS_GENERIC_CPU_TOPOLOGY
> + bool
> +
> config HAS_IOPORTS
> bool
>
> @@ -197,6 +200,25 @@ config VM_EVENT
> config NEEDS_LIBELF
> bool
>
> +config GENERIC_CPU_TOPOLOGY
> + bool
> +
> +config DT_CPU_TOPOLOGY
> + bool "Device tree based CPU topology support"
> + depends on HAS_GENERIC_CPU_TOPOLOGY && DEVICE_TREE_PARSE
> + select GENERIC_CPU_TOPOLOGY
> + help
> + Retrieve CPU topology information from the device tree to optimize
> + vCPU scheduling.
> +
> +config ACPI_CPU_TOPOLOGY
> + bool "ACPI based CPU topology support"
> + depends on HAS_GENERIC_CPU_TOPOLOGY && ACPI
> + select GENERIC_CPU_TOPOLOGY
> + help
> + Retrieve CPU topology information from the ACPI PPTT to optimize
> + vCPU scheduling.
> +
> config NUMA
> bool
>
> diff --git a/xen/common/Makefile b/xen/common/Makefile
> index cbabaf1e2b..25a9feef10 100644
> --- a/xen/common/Makefile
> +++ b/xen/common/Makefile
> @@ -6,6 +6,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_GENERIC_CPU_TOPOLOGY) += cpu-topology.init.o
> obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
> obj-$(CONFIG_HAS_DEVICE_TREE_DISCOVERY) += device.o
> obj-$(filter-out $(CONFIG_X86),$(CONFIG_ACPI)) += device.o
> diff --git a/xen/common/cpu-topology.c b/xen/common/cpu-topology.c
> new file mode 100644
> index 0000000000..e9275924ca
> --- /dev/null
> +++ b/xen/common/cpu-topology.c
> @@ -0,0 +1,81 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#include <xen/acpi.h>
> +#include <xen/cpu-topology.h>
> +#include <xen/cpumask.h>
> +#include <xen/dt-cpu-topology.h>
> +#include <xen/init.h>
> +#include <xen/xvmalloc.h>
> +
> +static void __init free_topology_table(void)
> +{
> + unsigned int cpu;
> +
> + if ( !cpu_topology )
> + return;
You did not use goto as I suggested and instead used ifs. It's ok but with that
this check is now dead.
> +
> + for ( cpu = 0; cpu < nr_cpu_ids; cpu++ )
> + {
> + free_cpumask_var(cpu_topology[cpu].thread_sibling);
> + free_cpumask_var(cpu_topology[cpu].core_sibling);
> + free_cpumask_var(cpu_topology[cpu].cluster_sibling);
> + }
> +
> + XVFREE(cpu_topology);
> +}
> +
> +void __init init_cpu_topology(void)
> +{
> + unsigned int cpu;
> + int ret;
> +
> + if ( num_possible_cpus() == 1 )
> + return;
> +
> + cpu_topology = xvzalloc_array(struct cpu_topology, nr_cpu_ids);
> +
> + if ( cpu_topology )
> + {
> + for ( cpu = 0; cpu < nr_cpu_ids; cpu++ )
> + {
> + if ( !zalloc_cpumask_var(&cpu_topology[cpu].thread_sibling) ||
> + !zalloc_cpumask_var(&cpu_topology[cpu].core_sibling) ||
> + !zalloc_cpumask_var(&cpu_topology[cpu].cluster_sibling) )
> + {
> + free_topology_table();
> + break;
> + }
> + }
> + }
> +
> + if ( !cpu_topology )
> + {
> + printk(XENLOG_WARNING "CPU topology table allocation failed\n");
> + return;
> + }
> +
> + if ( acpi_disabled )
> + ret = dt_init_cpu_topology();
> + else
> + ret = acpi_init_cpu_topology();
> +
> + /* Free the CPU topology table if initialization fails. */
> + if ( ret != 0 )
> + {
> + free_topology_table();
> +
> + if ( (ret != -ENOENT) && (ret != -EOPNOTSUPP) )
> + printk(XENLOG_WARNING
> + "Failed to initialize cpu topology (error %d)\n", ret);
> + }
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * tab-width: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/common/cpu.c b/xen/common/cpu.c
> index f09af0444b..9591ada60a 100644
> --- a/xen/common/cpu.c
> +++ b/xen/common/cpu.c
> @@ -1,5 +1,6 @@
> #include <xen/cpumask.h>
> #include <xen/cpu.h>
> +#include <xen/cpu-topology.h>
> #include <xen/event.h>
> #include <xen/init.h>
> #include <xen/sched.h>
> @@ -46,6 +47,10 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
> #undef MASK_DECLARE_2
> #undef MASK_DECLARE_1
>
> +#ifdef CONFIG_GENERIC_CPU_TOPOLOGY
> +struct cpu_topology *__ro_after_init cpu_topology;
> +#endif /* CONFIG_GENERIC_CPU_TOPOLOGY */
> +
> static DEFINE_RWLOCK(cpu_add_remove_lock);
>
> bool get_cpu_maps(void)
> diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makefile
> index 730d202349..b15b3382d2 100644
> --- a/xen/common/device-tree/Makefile
> +++ b/xen/common/device-tree/Makefile
> @@ -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.init.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
> diff --git a/xen/common/device-tree/cpu-topology.c b/xen/common/device-tree/cpu-topology.c
> new file mode 100644
> index 0000000000..0561b4856d
> --- /dev/null
> +++ b/xen/common/device-tree/cpu-topology.c
> @@ -0,0 +1,374 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Derived from Linux kernel 7.0's $drivers/base/arch_topology.c
> + * Parse cpu topology information.
> + */
> +
> +#include <xen/acpi.h>
xen/acpi.h is not used here and please include xen/dt-cpu-topology.h
> +#include <xen/cpu-topology.h>
> +#include <xen/cpumask.h>
> +#include <xen/device_tree.h>
> +#include <xen/errno.h>
> +#include <xen/init.h>
> +
> +#define INVALID_TOPO_ID (~0U)
> +
> +struct cpu_map {
> + unsigned int thread_id;
> + unsigned int core_id;
> + unsigned int cluster_id;
> + unsigned int socket_id;
> +};
> +
> +static struct cpu_map __initdata cpu_map[NR_CPUS] = {
> + [0 ... NR_CPUS - 1] = {
> + .thread_id = INVALID_TOPO_ID,
> + .core_id = INVALID_TOPO_ID,
> + .cluster_id = INVALID_TOPO_ID,
> + .socket_id = INVALID_TOPO_ID,
> + },
> +};
> +static struct dt_device_node *__initdata dt_cpu_table[NR_CPUS];
> +
> +static void __init setup_siblings_masks(unsigned int target_cpu)
> +{
> + struct cpu_topology *target_topo = &cpu_topology[target_cpu];
> + const struct cpu_map *target_map = &cpu_map[target_cpu];
> + unsigned int cpu;
> +
> + /* Update cluster, core and thread sibling masks */
> + for_each_possible_cpu(cpu)
> + {
> + struct cpu_topology *cpu_topo = &cpu_topology[cpu];
> + const struct cpu_map *map = &cpu_map[cpu];
> +
> + if ( target_cpu > cpu )
> + continue;
> +
> + if ( target_map->socket_id != map->socket_id )
> + continue;
> +
> + cpumask_set_cpu(target_cpu, cpu_topo->core_sibling);
> + cpumask_set_cpu(cpu, target_topo->core_sibling);
> +
> + if ( target_map->cluster_id != map->cluster_id )
> + continue;
> +
> + cpumask_set_cpu(target_cpu, cpu_topo->cluster_sibling);
> + cpumask_set_cpu(cpu, target_topo->cluster_sibling);
> +
> + if ( target_map->core_id != map->core_id )
> + continue;
> +
> + cpumask_set_cpu(target_cpu, cpu_topo->thread_sibling);
> + cpumask_set_cpu(cpu, target_topo->thread_sibling);
> + }
> +}
> +
> +static const struct dt_device_node *__init dt_find_child_node_by_name(
> + const struct dt_device_node *dt,
> + const char *name)
> +{
> + const struct dt_device_node *np;
> +
> + dt_for_each_child_node(dt, np)
> + if ( np->name && dt_node_name_is_equal(np, name) )
> + return np;
> +
> + return NULL;
> +}
> +
> +void __init map_cpu_to_dt_node(unsigned int cpu,
> + struct dt_device_node *cpu_node)
> +{
> + if ( cpu < ARRAY_SIZE(dt_cpu_table) )
> + dt_cpu_table[cpu] = cpu_node;
> + else
> + printk(XENLOG_WARNING
> + "cpu %u exceeds the max cpus %zu\n",
> + cpu, ARRAY_SIZE(dt_cpu_table));
> +}
> +
> +static unsigned int __init cpu_node_to_id(
> + const struct dt_device_node *cpu_node)
> +{
> + unsigned int cpu;
> +
> + for_each_possible_cpu(cpu)
> + if ( cpu_node == dt_cpu_table[cpu] )
> + return cpu;
> +
> + return INVALID_TOPO_ID;
> +}
> +
> +/*
> + * This function returns the Xen cpu number of the DT node.
> + */
> +static int __init get_cpu_for_node(
> + const struct dt_device_node *dt_node, unsigned int *cpu)
> +{
> + const struct dt_device_node *cpu_node =
> + dt_parse_phandle(dt_node, "cpu", 0);
> +
> + if ( !cpu_node || !dt_device_type_is_equal(cpu_node, "cpu") )
> + {
> + *cpu = INVALID_TOPO_ID;
> + return -EINVAL;
> + }
> +
> + *cpu = cpu_node_to_id(cpu_node);
> +
> + return 0;
> +}
> +
> +static bool __init is_cpu_map_empty(unsigned int cpu)
> +{
> + return (cpu_map[cpu].socket_id == INVALID_TOPO_ID) &&
> + (cpu_map[cpu].cluster_id == INVALID_TOPO_ID) &&
> + (cpu_map[cpu].core_id == INVALID_TOPO_ID) &&
> + (cpu_map[cpu].thread_id == INVALID_TOPO_ID);
> +}
> +
> +static int __init parse_core(const struct dt_device_node *core,
> + unsigned int socket_id,
> + unsigned int cluster_id,
> + unsigned int core_id)
> +{
> + bool leaf = true;
> + unsigned int thread_id;
> + unsigned int cpu;
> + int ret;
> +
> + for ( thread_id = 0; ; thread_id++ )
> + {
> + const struct dt_device_node *thread;
> + char name[20];
> +
> + snprintf(name, sizeof(name), "thread%u", thread_id);
> + thread = dt_find_child_node_by_name(core, name);
> +
> + if ( !thread )
> + break;
> +
> + leaf = false;
> + ret = get_cpu_for_node(thread, &cpu);
> + if ( ret )
> + {
> + printk(XENLOG_ERR
> + "%s: No CPU found for thread\n", dt_node_full_name(thread));
> + return ret;
> + }
> +
> + if ( cpu == INVALID_TOPO_ID )
> + {
> + /*
> + * Ignore this CPU node definition as the corresponding physical
> + * CPU is unavailable.
> + */
> + printk(XENLOG_INFO
> + "%s: CPU for thread is unavailable\n",
> + dt_node_full_name(thread));
> + continue;
> + }
> +
> + if ( !is_cpu_map_empty(cpu) )
> + {
> + printk(XENLOG_ERR
> + "Duplicate CPU definition for CPU%u\n", cpu);
> + return -EINVAL;
> + }
> +
> + cpu_map[cpu].socket_id = socket_id;
> + cpu_map[cpu].cluster_id = cluster_id;
> + cpu_map[cpu].core_id = core_id;
> + cpu_map[cpu].thread_id = thread_id;
> + }
> +
> + ret = get_cpu_for_node(core, &cpu);
> +
> + if ( cpu != INVALID_TOPO_ID )
> + {
> + if ( !leaf )
> + {
> + printk(XENLOG_ERR "%s: Core has both threads and CPU\n",
> + dt_node_full_name(core));
> + return -EINVAL;
> + }
> +
> + if ( !is_cpu_map_empty(cpu) )
> + {
> + printk(XENLOG_ERR "Duplicate CPU definition for CPU%u\n", cpu);
> + return -EINVAL;
> + }
> +
> + cpu_map[cpu].socket_id = socket_id;
> + cpu_map[cpu].cluster_id = cluster_id;
> + cpu_map[cpu].core_id = core_id;
> + cpu_map[cpu].thread_id = 0;
> + }
> + else if ( leaf )
> + {
> + if ( ret )
> + {
> + printk(XENLOG_ERR
> + "%s: No CPU found for leaf core\n",
> + dt_node_full_name(core));
> + return ret;
> + }
> +
> + /*
> + * Ignore this CPU node definition as the corresponding physical
> + * CPU is unavailable.
> + */
> + printk(XENLOG_INFO
> + "%s: CPU for leaf core is unavailable\n",
> + dt_node_full_name(core));
> + }
> +
> + return 0;
> +}
> +
> +static int __init parse_cluster(const struct dt_device_node *cluster,
> + unsigned int socket_id,
> + unsigned int cluster_id)
> +{
> + bool has_cores = false;
> + int ret = 0;
> +
> + if ( dt_find_child_node_by_name(cluster, "cluster0") )
> + {
> + printk(XENLOG_ERR
> + "Topology for clusters of clusters not yet supported\n");
> + return -EINVAL;
> + }
> +
> + for ( unsigned int core_id = 0; ; core_id++ )
> + {
> + const struct dt_device_node *core;
> + char name[20];
> +
> + snprintf(name, sizeof(name), "core%u", core_id);
> + core = dt_find_child_node_by_name(cluster, name);
> +
> + if ( !core )
> + break;
> +
> + has_cores = true;
> +
> + ret = parse_core(core, socket_id, cluster_id, core_id);
> + if ( ret != 0 )
> + return ret;
> + }
> +
> + if ( !has_cores )
> + printk(XENLOG_WARNING "%s: empty cluster\n",
> + dt_node_full_name(cluster));
Incorrect indentation.
> +
> + return ret;
> +}
> +
> +static int __init parse_socket(const struct dt_device_node *socket,
> + unsigned int socket_id)
> +{
> + bool has_cluster = false;
> + int ret = 0;
> +
> + for ( unsigned int cluster_id = 0; ; cluster_id++ )
> + {
> + const struct dt_device_node *cluster;
> + char name[20];
> +
> + snprintf(name, sizeof(name), "cluster%u", cluster_id);
> + cluster = dt_find_child_node_by_name(socket, name);
> +
> + if ( !cluster )
> + break;
> +
> + has_cluster = true;
> + ret = parse_cluster(cluster, socket_id, cluster_id);
> + if ( ret != 0 )
> + return ret;
> + }
> +
> + /*
> + * If no cluster node is defined, assume the socket has
> + * a single cluster.
> + */
> + if ( !has_cluster )
> + ret = parse_cluster(socket, socket_id, 0);
> +
> + return ret;
> +}
> +
> +static int __init parse_package(const struct dt_device_node *package)
> +{
> + bool has_socket = false;
> + int ret = 0;
> +
> + for ( unsigned int socket_id = 0; ; socket_id++ )
> + {
> + const struct dt_device_node *socket;
> + char name[20];
> +
> + snprintf(name, sizeof(name), "socket%u", socket_id);
> + socket = dt_find_child_node_by_name(package, name);
> +
> + if ( !socket )
> + break;
> +
> + has_socket = true;
> + ret = parse_socket(socket, socket_id);
> + if ( ret != 0 )
> + return ret;
> + }
> +
> + /*
> + * If no socket node is defined, assume all clusters reside under
> + * a single socket.
> + */
> + if ( !has_socket )
> + ret = parse_socket(package, 0);
> +
> + return ret;
> +}
> +
> +static int __init parse_dt_topology(void)
> +{
> + const struct dt_device_node *cpus;
> + const struct dt_device_node *map;
> +
> + cpus = dt_find_node_by_path("/cpus");
> + if ( !cpus )
> + return -ENOENT;
> +
> + map = dt_find_child_node_by_name(cpus, "cpu-map");
> + if ( !map )
> + return -ENOENT;
> +
> + return parse_package(map);
> +}
> +
> +int __init dt_init_cpu_topology(void)
> +{
> + unsigned int cpu;
> + int ret;
> +
> + ASSERT(cpu_topology);
> +
> + ret = parse_dt_topology();
> + if ( ret == 0 )
> + for_each_possible_cpu(cpu)
> + setup_siblings_masks(cpu);
I thought about what I told you a few revisions ago about a missing check if we
compare this code to Linux. I think we need to have one i.e. to check that every
CPU is indeed described in our cpu topology. Otherwise, if `cpu-map` does not
describe a CPU, such CPU keeps the invalid values and ends up being placed in
its own socket/cluster/core.
~Michal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler
2026-11-30 6:57 ` [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler Hirokazu Takahashi
@ 2026-12-01 13:20 ` Orzel, Michal
2026-12-02 4:05 ` Hirokazu Takahashi
0 siblings, 1 reply; 12+ messages in thread
From: Orzel, Michal @ 2026-12-01 13:20 UTC (permalink / raw)
To: Hirokazu Takahashi, xen-devel
Cc: jbeulich, Juergen Gross, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné, Timothy Pearson,
Alistair Francis, Baptiste Le Duc, Connor Davis, Oleksii Kurochko,
Dario Faggioli, George Dunlap
On 30-Nov-26 07:57, Hirokazu Takahashi wrote:
> 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@valinux.co.jp>
> Acked-by: Jan Beulich <jbeulich@suse.com>
> Reviewed-by: Juergen Gross <jgross@suse.com> # scheduler part
> ---
> xen/arch/arm/include/asm/processor.h | 4 --
> xen/arch/arm/smpboot.c | 34 ++++++++++++-----
> xen/arch/ppc/include/asm/processor.h | 4 --
> xen/arch/riscv/include/asm/processor.h | 4 --
> xen/common/device-tree/cpu-topology.c | 53 ++++++++++++++++++++++++++
> 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, 110 insertions(+), 23 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..41162f8ea1 100644
> --- a/xen/arch/arm/smpboot.c
> +++ b/xen/arch/arm/smpboot.c
> @@ -103,17 +103,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).
The comment above cpu_sibling_mask definition is still stale i.e. current Xen on
Arm assumes there is no multithread.
BTW. We still have a warning if we find MPIDR MT bit set although this bit does
not really mean the CPU supports SMT. That's bad because on e.g. A78 which is
commonly used these days and that has this bit set, the warning is on. The
warning is right that SMT might impact the security of the system as some things
are shared between threads. This is just a note that we should do something with
that in the future i.e. remove the check that is based on MPIDR and decide what
to do with the warning (e.g. use the cpu topology information instead). No
action for this patch specifically.
With the stale comment removed:
Acked-by: Michal Orzel <michal.orzel@amd.com>
~Michal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0
2026-11-30 6:57 ` [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0 Hirokazu Takahashi
@ 2026-12-01 13:31 ` Orzel, Michal
2026-12-02 4:08 ` Hirokazu Takahashi
0 siblings, 1 reply; 12+ messages in thread
From: Orzel, Michal @ 2026-12-01 13:31 UTC (permalink / raw)
To: Hirokazu Takahashi, xen-devel
Cc: jbeulich, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Volodymyr Babchuk
On 30-Nov-26 07:57, Hirokazu Takahashi wrote:
> The PPTT received by Xen shows the topology of the physical CPUs,
> rather than the vCPUs used by Dom0. Leave topology-aware
> scheduling to Xen.
>
> Signed-off-by: Hirokazu Takahashi <taka@valinux.co.jp>
> ---
> Changes in v13:
> - Do not pass ACPI PPTT to Dom0, as PPTT does not represent the
> topology of Dom0 vCPUs.
>
> xen/arch/arm/acpi/domain_build.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/xen/arch/arm/acpi/domain_build.c b/xen/arch/arm/acpi/domain_build.c
> index db16f7fa94..89c69e647d 100644
> --- a/xen/arch/arm/acpi/domain_build.c
> +++ b/xen/arch/arm/acpi/domain_build.c
> @@ -263,6 +263,34 @@ static void __init acpi_xsdt_modify_entry(u64 entry[],
> }
> }
>
> +static bool __init acpi_xsdt_remove_entry(u64 entry[],
> + unsigned long *entry_count,
> + const char *signature)
> +{
> + unsigned long i;
> + struct acpi_table_header *table;
> + u64 size = sizeof(*table);
> +
> + for ( i = 0; i < *entry_count; i++ )
> + {
> + table = acpi_os_map_memory(entry[i], size);
> + if ( !table )
> + continue;
> +
> + if ( ACPI_COMPARE_NAME(table->signature, signature) )
> + {
> + acpi_os_unmap_memory(table, size);
> + memmove(&entry[i], &entry[i + 1],
> + (*entry_count - i - 1) * sizeof(u64));
> + (*entry_count)--;
> + return true;
> + }
> + acpi_os_unmap_memory(table, size);
> + }
> +
> + return false;
> +}
> +
> static int __init acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
> {
> struct acpi_table_header *table = NULL;
> @@ -298,6 +326,9 @@ static int __init acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
> ACPI_SIG_FADT, tbl_add[TBL_FADT].start);
> acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count,
> ACPI_SIG_MADT, tbl_add[TBL_MADT].start);
> + if ( acpi_xsdt_remove_entry(xsdt->table_offset_entry, &entry_count,
> + "PPTT") )
ACPI_SIG_PPTT
This patch can go in as a standalone change.
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
~Michal
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration
2026-12-01 11:22 ` Orzel, Michal
@ 2026-12-02 3:55 ` Hirokazu Takahashi
0 siblings, 0 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-12-02 3:55 UTC (permalink / raw)
To: Orzel, Michal, xen-devel@lists.xenproject.org
Cc: jbeulich@suse.com, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné
Hi Michal,
> > Parse the 'cpu-map' node in the Device Tree to extract CPU topology
> > information. If the 'cpu-map' node is absent, simply ignore it.
> For the v14, that hopefully will be the last revision of this patch, can you
> please extend the commit msg. For such a big change it deserves a proper
> commit
> msg explaining what, why and how.
Okay, I will
> > +static void __init free_topology_table(void)
> > +{
> > + unsigned int cpu;
> > +
> > + if ( !cpu_topology )
> > + return;
> You did not use goto as I suggested and instead used ifs. It's ok but with that
> this check is now dead.
Okay, I wiil remove the code.
> > --- /dev/null
> > +++ b/xen/common/device-tree/cpu-topology.c
> > @@ -0,0 +1,374 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +/*
> > + * Derived from Linux kernel 7.0's $drivers/base/arch_topology.c
> > + * Parse cpu topology information.
> > + */
> > +
> > +#include <xen/acpi.h>
> xen/acpi.h is not used here and please include xen/dt-cpu-topology.h
Okay.
> > +#include <xen/cpu-topology.h>
> > +#include <xen/cpumask.h>
> > +#include <xen/device_tree.h>
> > +#include <xen/errno.h>
> > +#include <xen/init.h>
> > +static int __init parse_cluster(const struct dt_device_node *cluster,
> > + unsigned int socket_id,
> > + unsigned int cluster_id)
> > +{
> > + bool has_cores = false;
> > + int ret = 0;
> > +
> > + if ( dt_find_child_node_by_name(cluster, "cluster0") )
> > + {
> > + printk(XENLOG_ERR
> > + "Topology for clusters of clusters not yet supported\n");
> > + return -EINVAL;
> > + }
> > +
> > + for ( unsigned int core_id = 0; ; core_id++ )
> > + {
> > + const struct dt_device_node *core;
> > + char name[20];
> > +
> > + snprintf(name, sizeof(name), "core%u", core_id);
> > + core = dt_find_child_node_by_name(cluster, name);
> > +
> > + if ( !core )
> > + break;
> > +
> > + has_cores = true;
> > +
> > + ret = parse_core(core, socket_id, cluster_id, core_id);
> > + if ( ret != 0 )
> > + return ret;
> > + }
> > +
> > + if ( !has_cores )
> > + printk(XENLOG_WARNING "%s: empty cluster\n",
> > + dt_node_full_name(cluster));
> Incorrect indentation.
I will fix it.
> > +int __init dt_init_cpu_topology(void)
> > +{
> > + unsigned int cpu;
> > + int ret;
> > +
> > + ASSERT(cpu_topology);
> > +
> > + ret = parse_dt_topology();
> > + if ( ret == 0 )
> > + for_each_possible_cpu(cpu)
> > + setup_siblings_masks(cpu);
> I thought about what I told you a few revisions ago about a missing check if we
> compare this code to Linux. I think we need to have one i.e. to check that every
> CPU is indeed described in our cpu topology. Otherwise, if `cpu-map` does not
> describe a CPU, such CPU keeps the invalid values and ends up being placed in
> its own socket/cluster/core.
Okay, I wiil add some checks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler
2026-12-01 13:20 ` Orzel, Michal
@ 2026-12-02 4:05 ` Hirokazu Takahashi
0 siblings, 0 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-12-02 4:05 UTC (permalink / raw)
To: Orzel, Michal, xen-devel@lists.xenproject.org
Cc: jbeulich@suse.com, Juergen Gross, Stefano Stabellini,
Julien Grall, Bertrand Marquis, Volodymyr Babchuk, Andrew Cooper,
Anthony PERARD, Roger Pau Monné, Timothy Pearson,
Alistair Francis, Baptiste Le Duc, Connor Davis, Oleksii Kurochko,
Dario Faggioli, George Dunlap
Hi Michal,
> > diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c
> > index 97e227cd92..41162f8ea1 100644
> > --- a/xen/arch/arm/smpboot.c
> > +++ b/xen/arch/arm/smpboot.c
> > @@ -103,17 +103,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).
> The comment above cpu_sibling_mask definition is still stale i.e. current Xen on
> Arm assumes there is no multithread.
Okay, I will remove the comment.
> BTW. We still have a warning if we find MPIDR MT bit set although this bit does
> not really mean the CPU supports SMT. That's bad because on e.g. A78 which is
> commonly used these days and that has this bit set, the warning is on. The
> warning is right that SMT might impact the security of the system as some things
> are shared between threads. This is just a note that we should do something with
> that in the future i.e. remove the check that is based on MPIDR and decide what
> to do with the warning (e.g. use the cpu topology information instead). No
> action for this patch specifically.
I agree.
> With the stale comment removed:
> Acked-by: Michal Orzel <michal.orzel@amd.com>
Thank you,
Hirokazu Takahashi.
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0
2026-12-01 13:31 ` Orzel, Michal
@ 2026-12-02 4:08 ` Hirokazu Takahashi
0 siblings, 0 replies; 12+ messages in thread
From: Hirokazu Takahashi @ 2026-12-02 4:08 UTC (permalink / raw)
To: Orzel, Michal, xen-devel@lists.xenproject.org
Cc: jbeulich@suse.com, Stefano Stabellini, Julien Grall,
Bertrand Marquis, Volodymyr Babchuk
Hi Michal,
> > @@ -298,6 +326,9 @@ static int __init acpi_create_xsdt(struct domain *d, struct membank tbl_add[])
> > ACPI_SIG_FADT, tbl_add[TBL_FADT].start);
> > acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count,
> > ACPI_SIG_MADT, tbl_add[TBL_MADT].start);
> > + if ( acpi_xsdt_remove_entry(xsdt->table_offset_entry, &entry_count,
> > + "PPTT") )
> ACPI_SIG_PPTT
Okay, I will fix it.
> This patch can go in as a standalone change.
> Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Okay, I will post it as a standalone patch.
Thank you,
Hirokazu Takahashi.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-02 4:08 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 6:57 [PATCH v13 0/5] xen/acpi,device-tree: Introduce generic CPU topology support for ACPI and DT Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 1/5] xen/device-tree: Parse 'cpu-map' node for CPU topology exploration Hirokazu Takahashi
2026-12-01 11:22 ` Orzel, Michal
2026-12-02 3:55 ` Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 2/5] xen/sched: Link CPU topology to scheduler Hirokazu Takahashi
2026-12-01 13:20 ` Orzel, Michal
2026-12-02 4:05 ` Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 3/5] xen/sched: Make cpu_nr_siblings() architecture-specific Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 4/5] xen/acpi: Parse PPTT to initialize CPU topology Hirokazu Takahashi
2026-11-30 6:57 ` [PATCH v13 5/5] xen/acpi: Do not pass ACPI PPTT to Dom0 Hirokazu Takahashi
2026-12-01 13:31 ` Orzel, Michal
2026-12-02 4:08 ` Hirokazu Takahashi
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.