Skip to content

Commit e60cbee

Browse files
calmisibonzini
authored andcommitted
i386/topology: Introduce helpers for various topology info of different level
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 8f78378 commit e60cbee

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

include/hw/i386/topology.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,29 @@ static inline bool x86_has_extended_topo(unsigned long *topo_bitmap)
203203
test_bit(CPU_TOPOLOGY_LEVEL_DIE, topo_bitmap);
204204
}
205205

206+
static inline unsigned x86_module_per_pkg(X86CPUTopoInfo *topo_info)
207+
{
208+
return topo_info->modules_per_die * topo_info->dies_per_pkg;
209+
}
210+
211+
static inline unsigned x86_cores_per_pkg(X86CPUTopoInfo *topo_info)
212+
{
213+
return topo_info->cores_per_module * x86_module_per_pkg(topo_info);
214+
}
215+
216+
static inline unsigned x86_threads_per_pkg(X86CPUTopoInfo *topo_info)
217+
{
218+
return topo_info->threads_per_core * x86_cores_per_pkg(topo_info);
219+
}
220+
221+
static inline unsigned x86_threads_per_module(X86CPUTopoInfo *topo_info)
222+
{
223+
return topo_info->threads_per_core * topo_info->cores_per_module;
224+
}
225+
226+
static inline unsigned x86_threads_per_die(X86CPUTopoInfo *topo_info)
227+
{
228+
return x86_threads_per_module(topo_info) * topo_info->modules_per_die;
229+
}
230+
206231
#endif /* HW_I386_TOPOLOGY_H */

target/i386/cpu.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,11 @@ static uint32_t num_threads_by_topo_level(X86CPUTopoInfo *topo_info,
312312
case CPU_TOPOLOGY_LEVEL_CORE:
313313
return topo_info->threads_per_core;
314314
case CPU_TOPOLOGY_LEVEL_MODULE:
315-
return topo_info->threads_per_core * topo_info->cores_per_module;
315+
return x86_threads_per_module(topo_info);
316316
case CPU_TOPOLOGY_LEVEL_DIE:
317-
return topo_info->threads_per_core * topo_info->cores_per_module *
318-
topo_info->modules_per_die;
317+
return x86_threads_per_die(topo_info);
319318
case CPU_TOPOLOGY_LEVEL_SOCKET:
320-
return topo_info->threads_per_core * topo_info->cores_per_module *
321-
topo_info->modules_per_die * topo_info->dies_per_pkg;
319+
return x86_threads_per_pkg(topo_info);
322320
default:
323321
g_assert_not_reached();
324322
}
@@ -6506,8 +6504,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
65066504
topo_info.cores_per_module = cs->nr_cores / env->nr_dies / env->nr_modules;
65076505
topo_info.threads_per_core = cs->nr_threads;
65086506

6509-
threads_per_pkg = topo_info.threads_per_core * topo_info.cores_per_module *
6510-
topo_info.modules_per_die * topo_info.dies_per_pkg;
6507+
threads_per_pkg = x86_threads_per_pkg(&topo_info);
65116508

65126509
/* Calculate & apply limits for different index ranges */
65136510
if (index >= 0xC0000000) {

0 commit comments

Comments
 (0)