mbox series

[v2,00/10] i386: Track X86CPUTopoInfo in CPUX86State and track features in env->features[]

Message ID 20241219110125.1266461-1-xiaoyao.li@intel.com (mailing list archive)
Headers show
Series i386: Track X86CPUTopoInfo in CPUX86State and track features in env->features[] | expand

Message

Xiaoyao Li Dec. 19, 2024, 11:01 a.m. UTC
This v2 series is follow up work of [1],[2].

The initial purpose is to track CPUID_HT in env->features[] for x86.
It's supposed to be implemented in x86_cpu_realizefn() and before
qemu_init_vcpu(). However, CPUID_HT bit needs to be evaluated based on
topology information, either 1) nr_cores and nr_threads of CPUState or
2) MachineState::smp.

1) are initialized in qemu_init_vcpu() which is too late. So [1] was
sent to initialize nr_threads and nr_cores of CPUState earlier. It
touches all the ARCHes and people disliked it. Followup attempt to
initialize them in cpu_common_initfn() was also rejected. [3]

2) needs to grab MachineState in cpu context and was disagreed[3]

As suggested by Igor[3], aduit nr_threads and nr_cores and initialize
them in pre_plug() callback for the ARCHes where they are actually needed.
I found nr_cores is only used by x86 and nr_threads is used by
X86/MIPS/PPC[4]. I didn't play with MIPS and PPC before and I'm
incapable to write patch for them. So I send an RFC work [2], which
drops nr_cores from CPUState and it instead maintains a substitute for
x86 only. The RFC work left how to handle nr_threads as open however I
didn't get any feedback yet.

Eventually, I decided to fix x86 only. The sulution is to maintain a
X86CPUTopoInfo in CPUX86State, so that x86 doesn't need to use
nr_threads and nr_cores anymore and the dependency on qemu_init_vcpu()
goes away.

x86 is the only user of CPUState::nr_core currently. When it switches to
use CPUX86state::X86CPUTopoInfo, CPUState::nr_core loses its only user
and can be dropped in patch 8.

In the future, if MIPS and PPC starts to maintain nr_threads in its own
CPU state, common CPUState::nr_threads can be dropped as well.

Besides the patches to fulfill the main goal to track CPUID_HT in
env->features[] for x86. This series also contains the cleanup patches
during the work.


[1] https://lore.kernel.org/qemu-devel/20241108070609.3653085-1-xiaoyao.li@intel.com/
[2] https://lore.kernel.org/qemu-devel/20241205145716.472456-1-xiaoyao.li@intel.com/
[3] https://lore.kernel.org/qemu-devel/20241125103857.78a23715@imammedo.users.ipa.redhat.com/
[4] https://lore.kernel.org/qemu-devel/045f9cb1-2b17-4b2c-985f-3c34e3626b36@intel.com/

Xiaoyao Li (10):
  i386/cpu: Extract a common fucntion to setup value of
    MSR_CORE_THREAD_COUNT
  i386/cpu: Drop the variable smp_cores and smp_threads in
    x86_cpu_pre_plug()
  i386/cpu: Drop cores_per_pkg in cpu_x86_cpuid()
  i386/topology: Update the comment of x86_apicid_from_topo_ids()
  i386/topology: Introduce helpers for various topology info of
    different level
  i386/cpu: Track a X86CPUTopoInfo directly in CPUX86State
  i386/cpu: Hoist check of CPUID_EXT3_TOPOEXT against threads_per_core
  cpu: Remove nr_cores from struct CPUState
  i386/cpu: Set up CPUID_HT in x86_cpu_expand_features() instead of
    cpu_x86_cpuid()
  i386/cpu: Set and track CPUID_EXT3_CMP_LEG in
    env->features[FEAT_8000_0001_ECX]

 hw/core/cpu-common.c                 |   1 -
 hw/i386/x86-common.c                 |  22 +++---
 include/hw/core/cpu.h                |   2 -
 include/hw/i386/topology.h           |  30 ++++++-
 system/cpus.c                        |   1 -
 target/i386/cpu-sysemu.c             |  11 +++
 target/i386/cpu.c                    | 113 ++++++++++++---------------
 target/i386/cpu.h                    |   8 +-
 target/i386/hvf/x86_emu.c            |   3 +-
 target/i386/kvm/kvm.c                |   5 +-
 target/i386/tcg/sysemu/misc_helper.c |   3 +-
 11 files changed, 103 insertions(+), 96 deletions(-)