hw/cpu: Slightly sanitize CPU API
cover hw/cpu: Slightly sanitize CPU API
API cleanups, mostly removing system-specific code out of cpu-common.c. Code churn renaming functions, in the hope to make things a bit simpler to understand.
Small patch set extracted from a series clarifying CPU / accel synchronization, itself a preliminary work to introduce split acceleration, eventually.
Philippe Mathieu-Daudé (8):
hw/cpu: Correct CPU_GET_CLASS() comment
hw/cpu: Include missing 'qemu/accel.h' header
hw/cpu: Move internal declarations to new 'cpu-internal.h' header hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize() hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize() hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize() hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn() hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c
hw/core/cpu-internal.h | 23 +++++++++++++++++++++++ include/hw/core/cpu.h | 15 ++++++--------- hw/core/cpu-common.c | 32 +++++++------------------------- hw/core/cpu-system.c | 29 ++++++++++++++++++++++++++++- hw/core/cpu-user.c | 8 +++++++- target/alpha/cpu.c | 2 +- target/arm/cpu.c | 2 +- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 2 +- target/hppa/cpu.c | 2 +- target/i386/cpu.c | 10 +++++----- target/i386/kvm/kvm-cpu.c | 4 ++-- target/loongarch/cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 2 +- target/or1k/cpu.c | 2 +- target/ppc/cpu_init.c | 4 ++-- target/riscv/cpu.c | 2 +- target/riscv/kvm/kvm-cpu.c | 2 +- target/riscv/tcg/tcg-cpu.c | 2 +- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 2 +- target/sparc/cpu.c | 2 +- target/tricore/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 27 files changed, 99 insertions(+), 64 deletions(-) create mode 100644 hw/core/cpu-internal.h
Signature · 1 line
2.53.0
PATCH 1/8 hw/cpu: Correct CPU_GET_CLASS() comment
commit 0e86d7a71e8 ("cpus: Cache CPUClass early in instance_init() handler") renamed cpu_exec_realizefn() -> cpu_common_initfn(); update the comment.
--- include/hw/core/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/core/cpu.h +1 -1
@@ -60,7 +60,7 @@ typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,* expensive given the eventual call to * object_class_dynamic_cast_assert(). Because of this the CPUState * has a cached value for the class in cs->cc which is set up in -* cpu_exec_realizefn() for use in hot code paths. +* cpu_common_initfn() for use in hot code paths. */ typedef struct CPUClass CPUClass ; DECLARE_CLASS_CHECKERS(CPUClass, CPU,
Signature · 1 line
2.53.0
PATCH 2/8 hw/cpu: Include missing 'qemu/accel.h' header
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
cpu_common_realize() calls accel_cpu_common_realize(), itself declared in "qemu/accel.h". Include the latter, otherwise we get when refactoring unrelated headers:
hw/core/cpu-common.c:233:10: error: implicit declaration of function ‘accel_cpu_common_realize’
233 | if (!accel_cpu_common_realize(cpu, errp)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~--- hw/core/cpu-common.c | 1 + 1 file changed, 1 insertion(+)
hw/core/cpu-common.c +1 -0
@@ -23,6 +23,7 @@#include "qapi/error.h" #include "hw/core/cpu.h" #include "system/hw_accel.h" +#include "qemu/accel.h" #include "qemu/log.h" #include "qemu/main-loop.h" #include "qemu/lockcnt.h"
Signature · 1 line
2.53.0
PATCH 3/8 hw/cpu: Move internal declarations to new 'cpu-internal.h' header
In reply to Philippe Mathieu-DaudéSome declarations are only used within hw/core/, in particular by the 3 cpu-{common,user,system}.c. Restrict the declarations scope by moving them to a new "cpu-internal.h" local header.
Rename cpu_exec_initfn() -> cpu_exec_init() because we usually have the 'fn' suffix for handler, not API entry point methods.
--- hw/core/cpu-internal.h | 22 ++++++++++++++++++++++ include/hw/core/cpu.h | 6 ------ hw/core/cpu-common.c | 3 ++- hw/core/cpu-system.c | 3 ++- hw/core/cpu-user.c | 3 ++- 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 hw/core/cpu-internal.h
hw/core/cpu-internal.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* QEMU private CPU interface between user / system modes) +* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef HW_CORE_CPU_INTERNAL_H +#define HW_CORE_CPU_INTERNAL_H + +#include "hw/core/qdev.h" +#include "hw/core/cpu.h" + +void cpu_class_init_props (DeviceClass *dc); +void cpu_exec_class_post_init (CPUClass *cc); + +void cpu_exec_init (CPUState *cpu); + +void cpu_vmstate_register (CPUState *cpu); +void cpu_vmstate_unregister (CPUState *cpu); + +#endif
include/hw/core/cpu.h +0 -6
@@ -1178,12 +1178,6 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)*/ void qemu_process_cpu_events (CPUState *cpu); -/* $(top_srcdir)/cpu.c */ -void cpu_class_init_props (DeviceClass *dc); -void cpu_exec_class_post_init (CPUClass *cc); -void cpu_exec_initfn (CPUState *cpu); -void cpu_vmstate_register (CPUState *cpu); -void cpu_vmstate_unregister (CPUState *cpu);bool cpu_exec_realizefn (CPUState *cpu,Error **errp);void cpu_exec_unrealizefn (CPUState *cpu);void cpu_exec_reset_hold (CPUState *cpu);
hw/core/cpu-common.c +2 -1
@@ -39,6 +39,7 @@#ifdef CONFIG_PLUGIN #include "qemu/plugin.h" #endif +#include "cpu-internal.h" CPUState *cpu_by_arch_id (int64_t id) {
@@ -326,7 +327,7 @@ static void cpu_common_initfn(Object *obj)QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints); -cpu_exec_initfn (cpu); +cpu_exec_init (cpu);/* * Plugin initialization must wait until the cpu start executing
hw/core/cpu-system.c +2 -1
@@ -30,6 +30,7 @@#include "hw/core/sysemu-cpu-ops.h" #include "migration/vmstate.h" #include "system/tcg.h" +#include "cpu-internal.h" bool cpu_has_work (CPUState *cpu) {
@@ -188,7 +189,7 @@ void cpu_exec_class_post_init(CPUClass *cc)g_assert (cc->sysemu_ops->has_work); } -void cpu_exec_initfn (CPUState *cpu) +void cpu_exec_init (CPUState *cpu) { cpu->memory =get_system_memory ();object_ref (OBJECT (cpu->memory));
hw/core/cpu-user.c +2 -1
@@ -11,6 +11,7 @@#include "hw/core/qdev-properties.h" #include "hw/core/cpu.h" #include "migration/vmstate.h" +#include "cpu-internal.h" static const Property cpu_user_props[] = {/*
@@ -32,7 +33,7 @@ void cpu_exec_class_post_init(CPUClass *cc)/* nothing to do */ } -void cpu_exec_initfn (CPUState *cpu) +void cpu_exec_init (CPUState *cpu) {/* nothing to do */ }
Signature · 1 line
2.53.0
PATCH 4/8 hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize()
In reply to Philippe Mathieu-DaudéKeep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.
--- hw/core/cpu-common.c | 4 ++-- target/i386/kvm/kvm-cpu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/core/cpu-common.c +2 -2
@@ -246,7 +246,7 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)return true; } -static void cpu_common_realizefn (DeviceState *dev,Error **errp) +static void cpu_exec_realize (DeviceState *dev,Error **errp) {CPUState *cpu =CPU (dev);Object *machine =qdev_get_machine ();
@@ -379,7 +379,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data) k->gdb_read_register = cpu_common_gdb_read_register; k->gdb_write_register = cpu_common_gdb_write_register;set_bit (DEVICE_CATEGORY_CPU , dc->categories); - dc->realize = cpu_common_realizefn; + dc->realize = cpu_exec_realize; dc->unrealize = cpu_common_unrealizefn; rc->phases.hold = cpu_common_reset_hold; rc->phases.exit = cpu_common_reset_exit;
target/i386/kvm/kvm-cpu.c +1 -1
@@ -63,7 +63,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)* host_cpu_realizefn() * kvm_set_guest_phys_bits() * check/update ucode_rev, phys_bits, guest_phys_bits, mwait -* cpu_common_realizefn() (via xcc->parent_realize) +* cpu_exec_realize() (via xcc->parent_realize) */ if (xcc->max_features) {if (enable_cpu_pm) {
Signature · 1 line
2.53.0
PATCH 5/8 hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize()
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Keep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.
--- include/hw/core/cpu.h | 3 ++- hw/core/cpu-common.c | 2 +- target/alpha/cpu.c | 2 +- target/arm/cpu.c | 2 +- target/avr/cpu.c | 2 +- target/hexagon/cpu.c | 2 +- target/hppa/cpu.c | 2 +- target/i386/cpu.c | 10 +++++----- target/i386/kvm/kvm-cpu.c | 2 +- target/loongarch/cpu.c | 2 +- target/m68k/cpu.c | 2 +- target/microblaze/cpu.c | 2 +- target/mips/cpu.c | 2 +- target/or1k/cpu.c | 2 +- target/ppc/cpu_init.c | 2 +- target/riscv/cpu.c | 2 +- target/riscv/kvm/kvm-cpu.c | 2 +- target/riscv/tcg/tcg-cpu.c | 2 +- target/rx/cpu.c | 2 +- target/s390x/cpu.c | 2 +- target/sh4/cpu.c | 2 +- target/sparc/cpu.c | 2 +- target/tricore/cpu.c | 2 +- target/xtensa/cpu.c | 2 +- 24 files changed, 29 insertions(+), 28 deletions(-)
include/hw/core/cpu.h +2 -1
@@ -1178,7 +1178,8 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)*/ void qemu_process_cpu_events (CPUState *cpu); -bool cpu_exec_realizefn (CPUState *cpu,Error **errp); +/** cpu_common_realize: CPU DeviceRealize common handler */ +bool cpu_common_realize (CPUState *cpu,Error **errp);void cpu_exec_unrealizefn (CPUState *cpu);void cpu_exec_reset_hold (CPUState *cpu);
hw/core/cpu-common.c +1 -1
@@ -230,7 +230,7 @@ const char *parse_cpu_option(const char *cpu_option)return cpu_type; } -bool cpu_exec_realizefn (CPUState *cpu,Error **errp) +bool cpu_common_realize (CPUState *cpu,Error **errp) {if (!accel_cpu_common_realize (cpu, errp)) {return false;
target/alpha/cpu.c +1 -1
@@ -117,7 +117,7 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp) cs->tcg_cflags |=CF_PCREL ;#endif -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/arm/cpu.c +1 -1
@@ -1891,7 +1891,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) }#endif -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/avr/cpu.c +1 -1
@@ -131,7 +131,7 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp)AVRCPUClass *mcc =AVR_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/hexagon/cpu.c +1 -1
@@ -450,7 +450,7 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)HexagonCPUClass *mcc =HEXAGON_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/hppa/cpu.c +1 -1
@@ -181,7 +181,7 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)HPPACPUClass *acc =HPPA_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/i386/cpu.c +5 -5
@@ -10164,7 +10164,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* These may be set by the accel-specific code, * and the results are subsequently checked / assumed in this function. */ -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
@@ -10179,7 +10179,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)if (cpu->guest_phys_bits ==-1 ) {/* * If it was not set by the user, or by the accelerator via -* cpu_exec_realizefn, clear. +* cpu_common_realize, clear. */ cpu->guest_phys_bits =0 ; }
@@ -10188,7 +10188,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)/* * The default is the same as KVM's. Note that this check * needs to happen after the evenual setting of ucode_rev in -* accel-specific code in cpu_exec_realizefn. +* accel-specific code in cpu_common_realize. */ if (IS_AMD_CPU (env)) { cpu->ucode_rev =0x01000065 ;
@@ -10201,7 +10201,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* mwait extended info: needed for Core compatibility * We always wake on interrupt even if host does not have the capability. * -* requires the accel-specific code in cpu_exec_realizefn to +* requires the accel-specific code in cpu_common_realize to * have already acquired the CPUID data into cpu->mwait. */ cpu->mwait.ecx |=CPUID_MWAIT_EMX |CPUID_MWAIT_IBE ;
@@ -10230,7 +10230,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* Note that this code assumes features expansion has already been done * (as it checks for CPUID_EXT2_LM), and also assumes that potential * phys_bits adjustments to match the host have been already done in -* accel-specific code in cpu_exec_realizefn. +* accel-specific code in cpu_common_realize. */ if (env->features[FEAT_8000_0001_EDX ] &CPUID_EXT2_LM ) {if (cpu->phys_bits && cpu->phys_bits <32 ) {
target/i386/kvm/kvm-cpu.c +1 -1
@@ -57,7 +57,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)* * x86_cpu_realizefn(): * x86_cpu_expand_features() -* cpu_exec_realizefn(): +* cpu_common_realize(): * accel_cpu_common_realize() * kvm_cpu_realizefn() * host_cpu_realizefn()
target/loongarch/cpu.c +1 -1
@@ -704,7 +704,7 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)LoongArchCPUClass *lacc =LOONGARCH_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/m68k/cpu.c +1 -1
@@ -389,7 +389,7 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)register_m68k_insns (&cpu->env); -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/microblaze/cpu.c +1 -1
@@ -251,7 +251,7 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)int i =0 ;Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/mips/cpu.c +1 -1
@@ -544,7 +544,7 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp) }mips_cp0_period_set (cpu); -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/or1k/cpu.c +1 -1
@@ -170,7 +170,7 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)OpenRISCCPUClass *occ =OPENRISC_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/ppc/cpu_init.c +1 -1
@@ -6921,7 +6921,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/riscv/cpu.c +1 -1
@@ -1226,7 +1226,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/riscv/kvm/kvm-cpu.c +1 -1
@@ -2006,7 +2006,7 @@ static void kvm_cpu_instance_init(CPUState *cs)* We'll get here via the following path: * * riscv_cpu_realize() -* -> cpu_exec_realizefn() +* -> cpu_common_realize() * -> kvm_cpu_realize() (via accel_cpu_common_realize()) */ static bool kvm_cpu_realize (CPUState *cs,Error **errp)
target/riscv/tcg/tcg-cpu.c +1 -1
@@ -1304,7 +1304,7 @@ static void riscv_cpu_set_profile(RISCVCPU *cpu,* We'll get here via the following path: * * riscv_cpu_realize() -* -> cpu_exec_realizefn() +* -> cpu_common_realize() * -> tcg_cpu_realize() (via accel_cpu_common_realize()) */ static bool riscv_tcg_cpu_realize (CPUState *cs,Error **errp)
target/rx/cpu.c +1 -1
@@ -147,7 +147,7 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp)RXCPUClass *rcc =RX_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/s390x/cpu.c +1 -1
@@ -249,7 +249,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp) }#endif -cpu_exec_realizefn (cs, &err); +cpu_common_realize (cs, &err);if (err !=NULL ) { goto out; }
target/sh4/cpu.c +1 -1
@@ -250,7 +250,7 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp)SuperHCPUClass *scc =SUPERH_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/sparc/cpu.c +1 -1
@@ -892,7 +892,7 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)/* Default NaN value: sign bit clear, all frac bits set */ set_float_default_nan_pattern (0b01111111 , &env->fp_status); -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/tricore/cpu.c +1 -1
@@ -99,7 +99,7 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)CPUTriCoreState *env = &cpu->env;Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
target/xtensa/cpu.c +1 -1
@@ -257,7 +257,7 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)xtensa_irq_init (&XTENSA_CPU (dev)->env);#endif -cpu_exec_realizefn (cs, &local_err); +cpu_common_realize (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
Signature · 1 line
2.53.0
PATCH 6/8 hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize()
In reply to Philippe Mathieu-DaudéKeep cpu_common_*() pattern for publicly exposed common methods used by target code. Use cpu_exec_*() pattern for internal ones, mostly to distinct between system / user mode.
--- include/hw/core/cpu.h | 4 +++- hw/core/cpu-common.c | 4 ++-- target/ppc/cpu_init.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
include/hw/core/cpu.h +3 -1
@@ -1180,7 +1180,9 @@ void qemu_process_cpu_events(CPUState *cpu);/** cpu_common_realize: CPU DeviceRealize common handler */ bool cpu_common_realize (CPUState *cpu,Error **errp); -void cpu_exec_unrealizefn (CPUState *cpu); +/** cpu_common_realize: CPU DeviceUnrealize common handler */ +void cpu_common_unrealize (CPUState *cpu); +void cpu_exec_reset_hold (CPUState *cpu);extern const VMStateDescription vmstate_cpu_common;
hw/core/cpu-common.c +2 -2
@@ -284,10 +284,10 @@ static void cpu_common_unrealizefn(DeviceState *dev)#endif /* NOTE: latest generic point before the cpu is fully unrealized */ -cpu_exec_unrealizefn (cpu); +cpu_common_unrealize (cpu); } -void cpu_exec_unrealizefn (CPUState *cpu) +void cpu_common_unrealize (CPUState *cpu) {cpu_vmstate_unregister (cpu);
target/ppc/cpu_init.c +1 -1
@@ -6956,7 +6956,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)return ; unrealize: -cpu_exec_unrealizefn (cs); +cpu_common_unrealize (cs); }static void ppc_cpu_unrealize (DeviceState *dev)
Signature · 1 line
2.53.0
PATCH 7/8 hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn()
In reply to Philippe Mathieu-Daudécpu_common_realizefn() contains code only used by system mode emulation. Extract it to a new cpu_exec_realize() helper. In the next commit this helper will be moved to cpu-system.c where it belongs.
--- hw/core/cpu-common.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
hw/core/cpu-common.c +8 -4
@@ -246,9 +246,8 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)return true; } -static void cpu_exec_realize (DeviceState *dev,Error **errp) +static void cpu_exec_realize (CPUState *cpu,Error **errp) { -CPUState *cpu =CPU (dev);Object *machine =qdev_get_machine ();/* qdev_get_machine() can return something that's not TYPE_MACHINE
@@ -264,10 +263,15 @@ static void cpu_exec_realize(DeviceState *dev, Error **errp) } } -if (dev->hotplugged) { +if (DEVICE (cpu)->hotplugged) {cpu_synchronize_post_init (cpu);cpu_resume (cpu); } +} + +static void cpu_common_realizefn (DeviceState *dev,Error **errp) +{ +cpu_exec_realize (CPU (dev), errp);/* NOTE: latest generic point where the cpu is fully realized */ }
@@ -379,7 +383,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data) k->gdb_read_register = cpu_common_gdb_read_register; k->gdb_write_register = cpu_common_gdb_write_register;set_bit (DEVICE_CATEGORY_CPU , dc->categories); - dc->realize = cpu_exec_realize; + dc->realize = cpu_common_realizefn; dc->unrealize = cpu_common_unrealizefn; rc->phases.hold = cpu_common_reset_hold; rc->phases.exit = cpu_common_reset_exit;
Signature · 1 line
2.53.0
PATCH 8/8 hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c
In reply to Philippe Mathieu-DaudéCurrent cpu_exec_realize() body only contains system-mode related code. Move that method out of cpu-common.c to cpu-system.c, removing the system / machine mentions in this common file. Add an empty stub for user-mode.
--- hw/core/cpu-internal.h | 1 + hw/core/cpu-common.c | 24 ------------------------ hw/core/cpu-system.c | 26 ++++++++++++++++++++++++++ hw/core/cpu-user.c | 5 +++++ 4 files changed, 32 insertions(+), 24 deletions(-)
hw/core/cpu-internal.h +1 -0
@@ -15,6 +15,7 @@ void cpu_class_init_props(DeviceClass *dc);void cpu_exec_class_post_init (CPUClass *cc);void cpu_exec_init (CPUState *cpu); +void cpu_exec_realize (CPUState *cpu,Error **errp);void cpu_vmstate_register (CPUState *cpu);void cpu_vmstate_unregister (CPUState *cpu);
hw/core/cpu-common.c +0 -24
@@ -33,7 +33,6 @@#include "exec/log.h" #include "exec/gdbstub.h" #include "system/tcg.h" -#include "hw/core/boards.h" #include "hw/core/qdev-properties.h" #include "trace.h" #ifdef CONFIG_PLUGIN
@@ -246,29 +245,6 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)return true; } -static void cpu_exec_realize (CPUState *cpu,Error **errp) -{ -Object *machine =qdev_get_machine (); - -/* qdev_get_machine() can return something that's not TYPE_MACHINE -* if this is one of the user-only emulators; in that case there's -* no need to check the ignore_memory_transaction_failures board flag. -*/ -if (object_dynamic_cast (machine,TYPE_MACHINE )) { -MachineClass *mc =MACHINE_GET_CLASS (machine); - -if (mc) { - cpu->ignore_memory_transaction_failures = - mc->ignore_memory_transaction_failures; - } - } - -if (DEVICE (cpu)->hotplugged) { -cpu_synchronize_post_init (cpu); -cpu_resume (cpu); - } -} -static void cpu_common_realizefn (DeviceState *dev,Error **errp) {cpu_exec_realize (CPU (dev), errp);
hw/core/cpu-system.c +26 -0
@@ -25,10 +25,12 @@#include "exec/target_page.h" #include "system/memory.h" #include "qemu/target-info.h" +#include "hw/core/boards.h" #include "hw/core/qdev.h" #include "hw/core/qdev-properties.h" #include "hw/core/sysemu-cpu-ops.h" #include "migration/vmstate.h" +#include "system/hw_accel.h" #include "system/tcg.h" #include "cpu-internal.h"
@@ -221,6 +223,30 @@ static int cpu_common_pre_load(void *opaque)return 0 ; } +void cpu_exec_realize (CPUState *cpu,Error **errp) +{ +Object *machine =qdev_get_machine (); + +/* qdev_get_machine() can return something that's not TYPE_MACHINE +* if this is one of the user-only emulators; in that case there's +* no need to check the ignore_memory_transaction_failures board flag. +*/ +if (object_dynamic_cast (machine,TYPE_MACHINE )) { +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (mc) { + cpu->ignore_memory_transaction_failures = + mc->ignore_memory_transaction_failures; + } + } + +if (DEVICE (cpu)->hotplugged) { +cpu_synchronize_post_init (cpu); +cpu_resume (cpu); + } + +} +static bool cpu_common_exception_index_needed (void *opaque) {CPUState *cpu = opaque;
hw/core/cpu-user.c +5 -0
@@ -38,6 +38,11 @@ void cpu_exec_init(CPUState *cpu)/* nothing to do */ } +void cpu_exec_realize (CPUState *cpu,Error **errp) +{ +/* nothing to do */ +} +void cpu_vmstate_register (CPUState *cpu) { assert(qdev_get_vmsd(DEVICE(cpu)) == NULL ||
Signature · 1 line
2.53.0
Quoted 8 lines · Philippe Mathieu-Daudé
API cleanups, mostly removing system-specific code out of
cpu-common.c. Code churn renaming functions, in the hope to make things a bit simpler to understand.Small patch set extracted from a series clarifying CPU / accel synchronization, itself a preliminary work to introduce split acceleration, eventually.
Quoted 9 lines
Philippe Mathieu-Daudé (8):
hw/cpu: CorrectCPU_GET_CLASS()comment
hw/cpu: Include missing 'qemu/accel.h' header
hw/cpu: Move internal declarations to new 'cpu-internal.h' header hw/cpu: Renamecpu_common_realizefn()->cpu_exec_realize()hw/cpu: Renamecpu_exec_realizefn()->cpu_common_realize()hw/cpu: Renamecpu_exec_unrealizefn()->cpu_common_unrealize()hw/cpu: Extractcpu_exec_realize()out ofcpu_common_realizefn()hw/cpu: Move system-specificcpu_exec_realize()tocpu-system.c
r~
Quoted 8 lines · Philippe Mathieu-Daudé
API cleanups, mostly removing system-specific code out of
cpu-common.c. Code churn renaming functions, in the hope to make things a bit simpler to understand.Small patch set extracted from a series clarifying CPU / accel synchronization, itself a preliminary work to introduce split acceleration, eventually.
Quoted 9 lines
Philippe Mathieu-Daudé (8):
hw/cpu: CorrectCPU_GET_CLASS()comment
hw/cpu: Include missing 'qemu/accel.h' header
hw/cpu: Move internal declarations to new 'cpu-internal.h' header hw/cpu: Renamecpu_common_realizefn()->cpu_exec_realize()hw/cpu: Renamecpu_exec_realizefn()->cpu_common_realize()hw/cpu: Renamecpu_exec_unrealizefn()->cpu_common_unrealize()hw/cpu: Extractcpu_exec_realize()out ofcpu_common_realizefn()hw/cpu: Move system-specificcpu_exec_realize()tocpu-system.c
Series queued.