102 lines
4.0 KiB
Diff
102 lines
4.0 KiB
Diff
From 693fa1348914dfa37ce5fa4a654e67d573e4941a Mon Sep 17 00:00:00 2001
|
|
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
Date: Fri, 18 Jul 2025 18:03:44 +0200
|
|
Subject: [PATCH 011/115] i386/topology: Introduce helpers for various topology
|
|
info of different level
|
|
|
|
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
RH-MergeRequest: 391: TDX support, including attestation and device assignment
|
|
RH-Jira: RHEL-15710 RHEL-20798 RHEL-49728
|
|
RH-Acked-by: Yash Mankad <None>
|
|
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
RH-Acked-by: David Hildenbrand <david@redhat.com>
|
|
RH-Commit: [11/115] 52179ff6718bd4bfd9eac78efd20e7e5337d3b07 (bonzini/rhel-qemu-kvm)
|
|
|
|
Introduce various helpers for getting the topology info of different
|
|
semantics. Using the helper is more self-explanatory.
|
|
|
|
Besides, the semantic of the helper will stay unchanged even when new
|
|
topology is added in the future. At that time, updating the
|
|
implementation of the helper without affecting the callers.
|
|
|
|
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
|
|
Link: https://lore.kernel.org/r/20241219110125.1266461-6-xiaoyao.li@intel.com
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
(cherry picked from commit e60cbeec190d349682bf97cf55446e8ae260b11a)
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
(cherry picked from commit 12b80c6f6e6edf61c998aa5bac9d0c44a81144a0)
|
|
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
---
|
|
include/hw/i386/topology.h | 25 +++++++++++++++++++++++++
|
|
target/i386/cpu.c | 11 ++++-------
|
|
2 files changed, 29 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
|
|
index 1880df621a..e533a117c3 100644
|
|
--- a/include/hw/i386/topology.h
|
|
+++ b/include/hw/i386/topology.h
|
|
@@ -217,4 +217,29 @@ static inline bool x86_has_extended_topo(unsigned long *topo_bitmap)
|
|
test_bit(CPU_TOPO_LEVEL_DIE, topo_bitmap);
|
|
}
|
|
|
|
+static inline unsigned x86_module_per_pkg(X86CPUTopoInfo *topo_info)
|
|
+{
|
|
+ return topo_info->modules_per_die * topo_info->dies_per_pkg;
|
|
+}
|
|
+
|
|
+static inline unsigned x86_cores_per_pkg(X86CPUTopoInfo *topo_info)
|
|
+{
|
|
+ return topo_info->cores_per_module * x86_module_per_pkg(topo_info);
|
|
+}
|
|
+
|
|
+static inline unsigned x86_threads_per_pkg(X86CPUTopoInfo *topo_info)
|
|
+{
|
|
+ return topo_info->threads_per_core * x86_cores_per_pkg(topo_info);
|
|
+}
|
|
+
|
|
+static inline unsigned x86_threads_per_module(X86CPUTopoInfo *topo_info)
|
|
+{
|
|
+ return topo_info->threads_per_core * topo_info->cores_per_module;
|
|
+}
|
|
+
|
|
+static inline unsigned x86_threads_per_die(X86CPUTopoInfo *topo_info)
|
|
+{
|
|
+ return x86_threads_per_module(topo_info) * topo_info->modules_per_die;
|
|
+}
|
|
+
|
|
#endif /* HW_I386_TOPOLOGY_H */
|
|
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
|
|
index b639769ef3..1c79eb9a06 100644
|
|
--- a/target/i386/cpu.c
|
|
+++ b/target/i386/cpu.c
|
|
@@ -312,13 +312,11 @@ static uint32_t num_threads_by_topo_level(X86CPUTopoInfo *topo_info,
|
|
case CPU_TOPO_LEVEL_CORE:
|
|
return topo_info->threads_per_core;
|
|
case CPU_TOPO_LEVEL_MODULE:
|
|
- return topo_info->threads_per_core * topo_info->cores_per_module;
|
|
+ return x86_threads_per_module(topo_info);
|
|
case CPU_TOPO_LEVEL_DIE:
|
|
- return topo_info->threads_per_core * topo_info->cores_per_module *
|
|
- topo_info->modules_per_die;
|
|
+ return x86_threads_per_die(topo_info);
|
|
case CPU_TOPO_LEVEL_PACKAGE:
|
|
- return topo_info->threads_per_core * topo_info->cores_per_module *
|
|
- topo_info->modules_per_die * topo_info->dies_per_pkg;
|
|
+ return x86_threads_per_pkg(topo_info);
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
@@ -6957,8 +6955,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
|
topo_info.cores_per_module = cs->nr_cores / env->nr_dies / env->nr_modules;
|
|
topo_info.threads_per_core = cs->nr_threads;
|
|
|
|
- threads_per_pkg = topo_info.threads_per_core * topo_info.cores_per_module *
|
|
- topo_info.modules_per_die * topo_info.dies_per_pkg;
|
|
+ threads_per_pkg = x86_threads_per_pkg(&topo_info);
|
|
|
|
/* Calculate & apply limits for different index ranges */
|
|
if (index >= 0xC0000000) {
|
|
--
|
|
2.50.1
|
|
|