QOM CPUState VMStateDescriptions
cover QOM CPUState VMStateDescriptions
Hello,
In response to patches from Juan [1], this series implements a declarative way for CPUs to register their CPU-specific VMStateDescription.
There are subtle differences between CPU and devices in how they register their savevm handlers and VMStateDescription respectively:
* CPUs register one VMStateDescription "cpu_common" plus savevm handlers for the target-specifics (machine.c:cpu_{save,load}).
Devices register one VMStateDescription with a subsection for common state where necessary.
* CPUs use their cpu_index field as instance_id.
Devices pass -1 as instance_id, resulting in highest index on the bus plus 1.
Note: The current cpu_index numbering is not hot-unplug-safe.
My code assumes that registering "cpu_common" for CPUArchState (until changed in CPUState part 9 series) while registering "cpu" for CPUState is compatible, since by not using DeviceState::vmsd infrastructure registration order remains guaranteed the same.
Patches 4-5 demonstrate how two VMStateDescription-prepared but not yet migratable targets would look like if we want to adopt a consistent pattern for VMStateDescription registration and layout throughout targets.
Question is whether we want to take that legacy burden on us or whether to simply expose exec.c:vmstate_cpu_common and embed it PCI-like into the prepared VMStateDescriptions for alpha and openrisc and register them through DeviceClass::vmsd instead.
An alternative might be registering "cpu_common" as before but with instance_id -1 and registering "cpu" through DeviceClass::vmsd, since exec.c:calculate_new_instance_id() takes the name string into account. But that would be inconsistent with how devices behave VMState-wise.
Targets that have not yet been converted to VMState [1, 2] are left untouched.
Known conflicts:
- CPUState part 9 v1 series (target-*/cpu.c:class_init), to be rebased on this.
Available for testing here:git://github.com/afaerber/qemu-cpu.git qom-cpu-vmstate.v1
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-vmstate.v1
What triggered this series was moving the halted and interrupt_request fields from CPU_COMMON to CPUState:
https://lists.nongnu.org/archive/html/qemu-devel/2013-02/msg00203.html
Since both are in vmstate_cpu_common, they needed to be moved together, and "cpu_common" will need to operate on CPUState then. At the same time x86 can no longer access the halted field from CPUX86State via VMSTATE_ macros, so either we need to drop uses of such fields (i.e., version 5) or make it possible to access CPUState fields in x86 VMState through parent_obj field. Further, in explaining intended uses of S390CPU vs. CPUS390XState I was reminded that VMState is currently a limiting factor for placing fields into CPUState-derived types rather than into CPU*State.
Regards,
Andreas
[1] https://lists.nongnu.org/archive/html/qemu-devel/2012-05/msg00524.html
[2] https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg03451.html
Andreas Färber (6):
cpu: Register VMStateDescription through CPUState
target-i386: Update VMStateDescription to X86CPU
target-lm32: Update VMStateDescription to LM32CPU
target-alpha: Register VMStateDescription for AlphaCPU
target-openrisc: Register VMStateDescription for OpenRISCCPU
cpu: Guard cpu_{save,load}() definitions
exec.c | 13 ++- include/qemu-common.h | 2 + include/qom/cpu.h | 3 + target-alpha/cpu-qom.h | 2 + target-alpha/cpu.c | 3 + target-alpha/machine.c | 64 ++++++-------- target-i386/cpu-qom.h | 2 + target-i386/cpu.c | 4 + target-i386/cpu.h | 2 - target-i386/machine.c | 215 ++++++++++++++++++++++----------------------- target-lm32/cpu-qom.h | 2 + target-lm32/cpu.c | 4 + target-lm32/cpu.h | 2 - target-lm32/machine.c | 36 +++----- target-openrisc/cpu.c | 3 + target-openrisc/cpu.h | 2 + target-openrisc/machine.c | 33 +++----
17 Dateien geändert, 200 Zeilen hinzugefügt(+), 192 Zeilen entfernt(-)
Signature · 1 line
1.7.10.4
RFC PATCH 1/6 cpu: Register VMStateDescription through CPUState
In comparison to DeviceClass::vmsd, CPU VMState is split in two, "cpu_common" and "cpu", and uses cpu_index as instance_id instead of -1. Therefore add a CPU-specific CPUClass::vmsd field.
Unlike the legacy CPUArchState registration, rather register CPUState.
--- exec.c | 13 +++++++++++-- include/qom/cpu.h | 3 +++
2 Dateien geändert, 14 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)
exec.c +11 -2
@@ -219,7 +219,7 @@ void cpu_exec_init_all(void)#endif } -#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) +#if !defined(CONFIG_USER_ONLY )static int cpu_common_post_load (void *opaque,int version_id) {
@@ -266,6 +266,9 @@ CPUState *qemu_get_cpu(int index)void cpu_exec_init (CPUArchState *env) {CPUState *cpu =ENV_GET_CPU (env); +#if !defined(CONFIG_USER_ONLY ) && !defined(CPU_SAVE_VERSION ) +CPUClass *cc =CPU_GET_CLASS (cpu); +#endif CPUArchState **penv;int cpu_index;
@@ -290,10 +293,16 @@ void cpu_exec_init(CPUArchState *env)#if defined(CONFIG_USER_ONLY )cpu_list_unlock ();#endif -#if defined(CPU_SAVE_VERSION ) && !defined(CONFIG_USER_ONLY ) +#if !defined(CONFIG_USER_ONLY )vmstate_register (NULL , cpu_index, &vmstate_cpu_common, env); +#if defined(CPU_SAVE_VERSION )register_savevm (NULL ,"cpu" , cpu_index,CPU_SAVE_VERSION , cpu_save, cpu_load, env); +#else +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu_index, cc->vmsd, cpu); + } +#endif #endif }
include/qom/cpu.h +3 -0
@@ -43,6 +43,7 @@ typedef struct CPUState CPUState;* @class_by_name: Callback to map -cpu command line model name to an * instantiatable CPU type. * @reset: Callback to reset the #CPUState to its initial state. +* @vmsd: State description for migration. * * Represents a CPU family or model. */
@@ -54,6 +55,8 @@ typedef struct CPUClass {ObjectClass *(*class_by_name)(const char *cpu_model);void (*reset)(CPUState *cpu); + +const struct VMStateDescription *vmsd; } CPUClass;struct KVMState ;
Signature · 1 line
1.7.10.4
RFC PATCH 2/6 target-i386: Update VMStateDescription to X86CPU
In reply to Andreas FärberExpose vmstate_cpu as vmstate_x86_cpu and hook it up to CPUClass::vmsd. Adapt opaques and VMState fields to X86CPU. Drop cpu_{save,load}().
--- target-i386/cpu-qom.h | 2 + target-i386/cpu.c | 4 + target-i386/cpu.h | 2 - target-i386/machine.c | 215 ++++++++++++++++++++++++-------------------------
4 Dateien geändert, 113 Zeilen hinzugefügt(+), 110 Zeilen entfernt(-)
target-i386/cpu-qom.h +2 -0
@@ -74,5 +74,7 @@ static inline X86CPU *x86_env_get_cpu(CPUX86State *env)#define ENV_GET_CPU (e) CPU(x86_env_get_cpu(e)) +extern const struct VMStateDescription vmstate_x86_cpu; +#endif
target-i386/cpu.c +4 -0
@@ -2214,6 +2214,10 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) xcc->parent_reset = cc->reset; cc->reset = x86_cpu_reset; + +#ifndef CONFIG_USER_ONLY + cc->vmsd = &vmstate_x86_cpu; +#endif }static const TypeInfo x86_cpu_type_info = {
target-i386/cpu.h +0 -2
@@ -1082,8 +1082,6 @@ static inline CPUX86State *cpu_init(const char *cpu_model)#define cpu_list x86_cpu_list#define cpudef_setup x86_cpudef_setup -#define CPU_SAVE_VERSION 12 -/* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel#define MMU_MODE1_SUFFIX _user
target-i386/machine.c +107 -108
347 lines not on this page · raw message
Signature · 1 line
1.7.10.4
RFC PATCH 3/6 target-lm32: Update VMStateDescription to LM32CPU
In reply to Andreas FärberExpose vmstate_cpu as vmstate_lm32_cpu and hook it up to CPUClass::vmsd. Adapt VMState fields to LM32CPU. Drop cpu_{save,load}().
--- target-lm32/cpu-qom.h | 2 ++ target-lm32/cpu.c | 4 ++++ target-lm32/cpu.h | 2 -- target-lm32/machine.c | 36 +++++++++++++-----------------------
4 Dateien geändert, 19 Zeilen hinzugefügt(+), 25 Zeilen entfernt(-)
target-lm32/cpu-qom.h +2 -0
@@ -69,5 +69,7 @@ static inline LM32CPU *lm32_env_get_cpu(CPULM32State *env)#define ENV_GET_CPU (e) CPU(lm32_env_get_cpu(e)) +extern const struct VMStateDescription vmstate_lm32_cpu; +#endif
target-lm32/cpu.c +4 -0
@@ -81,6 +81,10 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) lcc->parent_reset = cc->reset; cc->reset = lm32_cpu_reset; + +#ifndef CONFIG_USER_ONLY + cc->vmsd = &vmstate_lm32_cpu; +#endif }static const TypeInfo lm32_cpu_type_info = {
target-lm32/cpu.h +0 -2
@@ -213,8 +213,6 @@ static inline CPULM32State *cpu_init(const char *cpu_model)#define cpu_gen_code cpu_lm32_gen_code#define cpu_signal_handler cpu_lm32_signal_handler -#define CPU_SAVE_VERSION 1 -int cpu_lm32_handle_mmu_fault (CPULM32State *env,target_ulong address,int rw,int mmu_idx);#define cpu_handle_mmu_fault cpu_lm32_handle_mmu_fault
target-lm32/machine.c +13 -23
@@ -1,33 +1,23 @@#include "hw/hw.h" #include "hw/boards.h" -static const VMStateDescription vmstate_cpu = { +const VMStateDescription vmstate_lm32_cpu = { .name ="cpu" , - .version_id =CPU_SAVE_VERSION , + .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_UINT32_ARRAY (regs, CPULM32State,32 ), -VMSTATE_UINT32 (pc, CPULM32State), -VMSTATE_UINT32 (ie, CPULM32State), -VMSTATE_UINT32 (icc, CPULM32State), -VMSTATE_UINT32 (dcc, CPULM32State), -VMSTATE_UINT32 (cc, CPULM32State), -VMSTATE_UINT32 (eba, CPULM32State), -VMSTATE_UINT32 (dc, CPULM32State), -VMSTATE_UINT32 (deba, CPULM32State), -VMSTATE_UINT32_ARRAY (bp, CPULM32State,4 ), -VMSTATE_UINT32_ARRAY (wp, CPULM32State,4 ), +VMSTATE_UINT32_ARRAY (env.regs,LM32CPU ,32 ), +VMSTATE_UINT32 (env.pc,LM32CPU ), +VMSTATE_UINT32 (env.ie,LM32CPU ), +VMSTATE_UINT32 (env.icc,LM32CPU ), +VMSTATE_UINT32 (env.dcc,LM32CPU ), +VMSTATE_UINT32 (env.cc,LM32CPU ), +VMSTATE_UINT32 (env.eba,LM32CPU ), +VMSTATE_UINT32 (env.dc,LM32CPU ), +VMSTATE_UINT32 (env.deba,LM32CPU ), +VMSTATE_UINT32_ARRAY (env.bp,LM32CPU ,4 ), +VMSTATE_UINT32_ARRAY (env.wp,LM32CPU ,4 ),VMSTATE_END_OF_LIST () } }; - -void cpu_save (QEMUFile *f,void *opaque) -{ -vmstate_save_state (f, &vmstate_cpu, opaque); -} - -int cpu_load (QEMUFile *f,void *opaque,int version_id) -{ -return vmstate_load_state (f, &vmstate_cpu, opaque, version_id); -}
Signature · 1 line
1.7.10.4
RFC 4/6 target-alpha: Register VMStateDescription for AlphaCPU
In reply to Andreas FärberCommit b758aca1f6cdb175634812b79f5560c36c902d00 (target-alpha: Enable the alpha-softmmu target.) introduced cpu_{save,load}() functions but didn't define CPU_SAVE_VERSION, so they were never registered.
Drop cpu_{save,load}() and register the VMStateDescription via CPUClass. This operates on the AlphaCPU object instead of CPUAlphaState.
--- target-alpha/cpu-qom.h | 2 ++ target-alpha/cpu.c | 3 +++ target-alpha/machine.c | 64 ++++++++++++++++++++++--------------------------
3 Dateien geändert, 34 Zeilen hinzugefügt(+), 35 Zeilen entfernt(-)
target-alpha/cpu-qom.h +2 -0
@@ -72,5 +72,7 @@ static inline AlphaCPU *alpha_env_get_cpu(CPUAlphaState *env)#define ENV_GET_CPU (e) CPU(alpha_env_get_cpu(e)) +extern const struct VMStateDescription vmstate_alpha_cpu; +#endif
target-alpha/cpu.c +3 -0
@@ -261,6 +261,9 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) dc->realize = alpha_cpu_realizefn; cc->class_by_name = alpha_cpu_class_by_name; +#ifndef CONFIG_USER_ONLY + cc->vmsd = &vmstate_alpha_cpu; +#endif }static const TypeInfo alpha_cpu_type_info = {
target-alpha/machine.c +29 -35
102 lines not on this page · raw message
Signature · 1 line
1.7.10.4
RFC 5/6 target-openrisc: Register VMStateDescription for OpenRISCCPU
In reply to Andreas FärberSince commit e67db06e9f6d7e514ee2a9b9b769ecd42977f6fb (target-or32: Add target stubs and QOM cpu) a VMStateDescription existed, but CPU_SAVE_VERSION was not set, so it was never registered.
Register it through CPUState.
Use a version_id of 1 and specify minimum versions as well.
--- target-openrisc/cpu.c | 3 +++ target-openrisc/cpu.h | 2 ++ target-openrisc/machine.c | 33 +++++++++++++--------------------
3 Dateien geändert, 18 Zeilen hinzugefügt(+), 20 Zeilen entfernt(-)
target-openrisc/cpu.c +3 -0
@@ -146,6 +146,9 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) cc->reset = openrisc_cpu_reset; cc->class_by_name = openrisc_cpu_class_by_name; +#ifndef CONFIG_USER_ONLY + cc->vmsd = &vmstate_openrisc_cpu; +#endif }static void cpu_register (const OpenRISCCPUInfo *info)
target-openrisc/cpu.h +2 -0
@@ -358,6 +358,8 @@ int cpu_openrisc_signal_handler(int host_signum, void *pinfo, void *puc);#define cpu_signal_handler cpu_openrisc_signal_handler#ifndef CONFIG_USER_ONLY +extern const struct VMStateDescription vmstate_openrisc_cpu; +/* hw/openrisc_pic.c */ void cpu_openrisc_pic_init (OpenRISCCPU *cpu);
target-openrisc/machine.c +13 -20
@@ -20,28 +20,21 @@#include "hw/hw.h" #include "hw/boards.h" -static const VMStateDescription vmstate_cpu = { +const VMStateDescription vmstate_openrisc_cpu = { .name ="cpu" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_UINT32_ARRAY (gpr, CPUOpenRISCState,32 ), -VMSTATE_UINT32 (sr, CPUOpenRISCState), -VMSTATE_UINT32 (epcr, CPUOpenRISCState), -VMSTATE_UINT32 (eear, CPUOpenRISCState), -VMSTATE_UINT32 (esr, CPUOpenRISCState), -VMSTATE_UINT32 (fpcsr, CPUOpenRISCState), -VMSTATE_UINT32 (pc, CPUOpenRISCState), -VMSTATE_UINT32 (npc, CPUOpenRISCState), -VMSTATE_UINT32 (ppc, CPUOpenRISCState), +VMSTATE_UINT32_ARRAY (env.gpr, OpenRISCCPU,32 ), +VMSTATE_UINT32 (env.sr, OpenRISCCPU), +VMSTATE_UINT32 (env.epcr, OpenRISCCPU), +VMSTATE_UINT32 (env.eear, OpenRISCCPU), +VMSTATE_UINT32 (env.esr, OpenRISCCPU), +VMSTATE_UINT32 (env.fpcsr, OpenRISCCPU), +VMSTATE_UINT32 (env.pc, OpenRISCCPU), +VMSTATE_UINT32 (env.npc, OpenRISCCPU), +VMSTATE_UINT32 (env.ppc, OpenRISCCPU),VMSTATE_END_OF_LIST () } }; - -void cpu_save (QEMUFile *f,void *opaque) -{ -vmstate_save_state (f, &vmstate_cpu, opaque); -} - -int cpu_load (QEMUFile *f,void *opaque,int version_id) -{ -return vmstate_load_state (f, &vmstate_cpu, opaque, version_id); -}
Signature · 1 line
1.7.10.4
RFC 6/6 cpu: Guard cpu_{save, load}() definitions
In reply to Andreas FärberA few targets already managed to implement cpu_save() and cpu_load() without defining CPU_SAVE_VERSION that causes them to be registered.
Guard the prototypes with CPU_SAVE_VERSION to avoid this happening again until all targets are converted to VMState or QIDL.
--- include/qemu-common.h | 2 ++
1 Datei geändert, 2 Zeilen hinzugefügt(+)
include/qemu-common.h +2 -0
@@ -276,8 +276,10 @@ bool tcg_enabled(void);void cpu_exec_init_all (void );/* CPU save/load. */ +#ifdef CPU_SAVE_VERSION void cpu_save (QEMUFile *f,void *opaque);int cpu_load (QEMUFile *f,void *opaque,int version_id); +#endif /* Unblock cpu */ void qemu_cpu_kick_self (void );
Signature · 1 line
1.7.10.4