unsubscribe ________________________________ 发件人: qemu-devel-bounces+liuping24=outlook....@nongnu.org <qemu-devel-bounces+liuping24=outlook....@nongnu.org> 代表 Gavin Shan <gs...@redhat.com> 发送时间: 2024年8月11日 21:59 收件人: Salil Mehta <salil.me...@huawei.com>; qemu-devel@nongnu.org <qemu-devel@nongnu.org>; qemu-...@nongnu.org <qemu-...@nongnu.org>; m...@redhat.com <m...@redhat.com> 抄送: m...@kernel.org <m...@kernel.org>; jean-phili...@linaro.org <jean-phili...@linaro.org>; jonathan.came...@huawei.com <jonathan.came...@huawei.com>; lpieral...@kernel.org <lpieral...@kernel.org>; peter.mayd...@linaro.org <peter.mayd...@linaro.org>; richard.hender...@linaro.org <richard.hender...@linaro.org>; imamm...@redhat.com <imamm...@redhat.com>; andrew.jo...@linux.dev <andrew.jo...@linux.dev>; da...@redhat.com <da...@redhat.com>; phi...@linaro.org <phi...@linaro.org>; eric.au...@redhat.com <eric.au...@redhat.com>; w...@kernel.org <w...@kernel.org>; a...@kernel.org <a...@kernel.org>; oliver.up...@linux.dev <oliver.up...@linux.dev>; pbonz...@redhat.com <pbonz...@redhat.com>; raf...@kernel.org <raf...@kernel.org>; borntrae...@linux.ibm.com <borntrae...@linux.ibm.com>; alex.ben...@linaro.org <alex.ben...@linaro.org>; npig...@gmail.com <npig...@gmail.com>; hars...@linux.ibm.com <hars...@linux.ibm.com>; li...@armlinux.org.uk <li...@armlinux.org.uk>; dar...@os.amperecomputing.com <dar...@os.amperecomputing.com>; il...@os.amperecomputing.com <il...@os.amperecomputing.com>; vis...@os.amperecomputing.com <vis...@os.amperecomputing.com>; karl.heub...@oracle.com <karl.heub...@oracle.com>; miguel.l...@oracle.com <miguel.l...@oracle.com>; salil.me...@opnsrc.net <salil.me...@opnsrc.net>; zhukeqi...@huawei.com <zhukeqi...@huawei.com>; wangxiongfe...@huawei.com <wangxiongfe...@huawei.com>; wangyana...@huawei.com <wangyana...@huawei.com>; jiakern...@gmail.com <jiakern...@gmail.com>; maob...@loongson.cn <maob...@loongson.cn>; lixiang...@loongson.cn <lixiang...@loongson.cn>; shahu...@redhat.com <shahu...@redhat.com>; zhao1....@intel.com <zhao1....@intel.com>; linux...@huawei.com <linux...@huawei.com> 主题: Re: [PATCH RFC V3 02/29] cpu-common: Add common CPU utility for possible vCPUs
On 6/14/24 9:36 AM, Salil Mehta wrote: > This patch adds various utility functions that may be required to fetch or > check > the state of possible vCPUs. It also introduces the concept of *disabled* > vCPUs, > which are part of the *possible* vCPUs but are not enabled. This state will be > used during machine initialization and later during the plugging or unplugging > of vCPUs. We release the QOM CPU objects for all disabled vCPUs. > > Co-developed-by: Keqian Zhu <zhukeqi...@huawei.com> > Signed-off-by: Keqian Zhu <zhukeqi...@huawei.com> > Signed-off-by: Salil Mehta <salil.me...@huawei.com> > --- > cpu-common.c | 31 +++++++++++++++++++++++++ > include/hw/core/cpu.h | 54 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 85 insertions(+) > > diff --git a/cpu-common.c b/cpu-common.c > index ce78273af5..49d2a50835 100644 > --- a/cpu-common.c > +++ b/cpu-common.c > @@ -24,6 +24,7 @@ > #include "sysemu/cpus.h" > #include "qemu/lockable.h" > #include "trace/trace-root.h" > +#include "hw/boards.h" > > QemuMutex qemu_cpu_list_lock; > static QemuCond exclusive_cond; > @@ -107,6 +108,36 @@ void cpu_list_remove(CPUState *cpu) > cpu_list_generation_id++; > } > > +CPUState *qemu_get_possible_cpu(int index) > +{ > + MachineState *ms = MACHINE(qdev_get_machine()); > + const CPUArchIdList *possible_cpus = ms->possible_cpus; > + > + assert((index >= 0) && (index < possible_cpus->len)); > + > + return CPU(possible_cpus->cpus[index].cpu); > +} > + > +bool qemu_present_cpu(CPUState *cpu) > +{ > + return cpu; > +} > + > +bool qemu_enabled_cpu(CPUState *cpu) > +{ > + return cpu && !cpu->disabled; > +} > + > +uint64_t qemu_get_cpu_archid(int cpu_index) > +{ > + MachineState *ms = MACHINE(qdev_get_machine()); > + const CPUArchIdList *possible_cpus = ms->possible_cpus; > + > + assert((cpu_index >= 0) && (cpu_index < possible_cpus->len)); > + > + return possible_cpus->cpus[cpu_index].arch_id; > +} > + > CPUState *qemu_get_cpu(int index) > { > CPUState *cpu; > diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h > index 60b160d0b4..60b4778da9 100644 > --- a/include/hw/core/cpu.h > +++ b/include/hw/core/cpu.h > @@ -528,6 +528,18 @@ struct CPUState { > CPUPluginState *plugin_state; > #endif > > + /* > + * Some architectures do not allow the *presence* of vCPUs to be changed > + * after the guest has booted, based on information specified by the > + * VMM/firmware via ACPI MADT at boot time. Thus, to enable vCPU hotplug > on > + * these architectures, possible vCPUs can have a CPUState object in a > + * 'disabled' state or may not have a CPUState object at all. This is > + * possible when vCPU hotplug is supported, and vCPUs are > + * 'yet-to-be-plugged' in the QOM or have been hot-unplugged. By default, > + * every CPUState is enabled across all architectures. > + */ > + bool disabled; > + The information to determine vCPU's state has been distributed to two data structs: MachineState::possible_cpus::cpus[] and CPUState. Why not just to maintain the vCPU's state from MachineState::possible_cpus::cpus[]? For example, adding a new field, or something similiar, to 'struct CPUArchId' as below. typedef struct CPUArchId { #define CPU_ARCH_ID_FLAG_PRESENT (1 << 0) #define CPU_ARCH_ID_FLAG_ENABLED (1 << 1) uint32_t flags; : } CPUArchId; In order to determine if a CPUState instance is enabled or not. CPUState::cpu_index is used as the index to MachineState::possible_cpus::cpus[]. The flags can be parsed to determine the vCPU's state. > /* TODO Move common fields from CPUArchState here. */ > int cpu_index; > int cluster_index; > @@ -914,6 +926,48 @@ static inline bool cpu_in_exclusive_context(const > CPUState *cpu) > */ > CPUState *qemu_get_cpu(int index); > > +/** > + * qemu_get_possible_cpu: > + * @index: The CPUState@cpu_index value of the CPU to obtain. > + * Input index MUST be in range [0, Max Possible CPUs) > + * > + * If CPUState object exists,then it gets a CPU matching > + * @index in the possible CPU array. > + * > + * Returns: The possible CPU or %NULL if CPU does not exist. > + */ > +CPUState *qemu_get_possible_cpu(int index); > + > +/** > + * qemu_present_cpu: > + * @cpu: The vCPU to check > + * > + * Checks if the vCPU is amongst the present possible vcpus. > + * > + * Returns: True if it is present possible vCPU else false > + */ > +bool qemu_present_cpu(CPUState *cpu); > + > +/** > + * qemu_enabled_cpu: > + * @cpu: The vCPU to check > + * > + * Checks if the vCPU is enabled. > + * > + * Returns: True if it is 'enabled' else false > + */ > +bool qemu_enabled_cpu(CPUState *cpu); > + > +/** > + * qemu_get_cpu_archid: > + * @cpu_index: possible vCPU for which arch-id needs to be retreived > + * > + * Fetches the vCPU arch-id from the present possible vCPUs. > + * > + * Returns: arch-id of the possible vCPU > + */ > +uint64_t qemu_get_cpu_archid(int cpu_index); > + > /** > * cpu_exists: > * @id: Guest-exposed CPU ID to lookup. Thanks, Gavin