target-arm: convert to VMState, fix bugs
cover target-arm: convert to VMState, fix bugs
This patch series converts target-arm to doing migration via a VMState structure, and fixes some minor bugs in migration of the CPU as well. The bulk of it is a patch Juan sent out back in the middle of last year
https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00550.html
which I have rebased and messed about with somewhat:
* rebased and fixed conflicts
* updated to use cpu_class_set_vmsd()
* updated with new/removed fields since original patch
* corrected subsection names so vmload doesn't fail
* changed to use custom VMStateInfo for cpsr rather than presave/postload hooks
The last of these was the subject of some discussion when Juan posted the patch (see URL above for the thread). The fundamental problem that has to be solved is "how do you deal with cases where the representation in the in memory struct is not the same as the on the wire representation?":
(a) Juan's original patch does "write wire format to random dummy field in the struct and then clean things up in presave/postload hooks".
(b) My patch follows what Alpha, i386 and some devices do: define a custom VMStateInfo which reads/writes the wire format and does the conversion to/from the struct.
(c) There was a mooted third approach of defining new vmstate macros and functionality so you could specify conversion functions for a field but leave actual reading and writing of the wire format to the core savevm code.
The argument against (b) was that it makes introducing a new migration wire format harder, but on the other hand it's a year later and nobody has, and we already have examples of this in tree so another user is no big deal. So it doesn't seem to me to merit the effort of actually implementing (c). I've gone for (b) because I think it's better than (a).
Overall I think the whole series is an improvement over the separate save/load fields; I'd also like to get this changeover done before we start having to worry about freezing the ARM migration format.
Juan Quintela (1):
target-arm: port ARM CPU save/load to use VMState
Peter Maydell (2):
target-arm: Add some missing CPU state fields to VMState
target-arm: Correctly restore FPSCR
target-arm/cpu-qom.h | 4 + target-arm/cpu.c | 1 + target-arm/cpu.h | 2 - target-arm/machine.c | 430 +++++++++++++++++++++++++------------------------- 4 files changed, 221 insertions(+), 216 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/3 target-arm: port ARM CPU save/load to use VMState
From: Juan Quintela <[email protected]>
Port the ARM CPU save/load code to use VMState. Some state is saved in a slightly different order to simplify things -- for example arrays are saved one after the other rather than 'striped', and we always save all 32 VFP registers even if the CPU happens to only have 16.
Use one subsection for each feature. This means that we don't need to bump the version field each time that a new feature gets introduced.
[PMM: fixed conflicts, updated to use cpu_class_set_vmsd(), updated
with new/removed fields since original patch, changed to use custom VMStateInfo for cpsr rather than presave/postload hooks, corrected subsection names so vmload doesn't fail]
--- target-arm/cpu-qom.h | 4 + target-arm/cpu.c | 1 + target-arm/cpu.h | 2 - target-arm/machine.c | 387 +++++++++++++++++++++++--------------------------- 4 files changed, 179 insertions(+), 215 deletions(-)
target-arm/cpu-qom.h +4 -0
@@ -111,6 +111,10 @@ static inline ARMCPU *arm_env_get_cpu(CPUARMState *env)#define ENV_OFFSET offsetof(ARMCPU, env) +#ifndef CONFIG_USER_ONLY +extern const struct VMStateDescription vmstate_arm_cpu; +#endif +void register_cp_regs_for_features (ARMCPU *cpu);void arm_cpu_do_interrupt (CPUState *cpu);
target-arm/cpu.c +1 -0
@@ -814,6 +814,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->class_by_name = arm_cpu_class_by_name; cc->do_interrupt = arm_cpu_do_interrupt; +cpu_class_set_vmsd (cc, &vmstate_arm_cpu); }static void cpu_register (const ARMCPUInfo *info)
target-arm/cpu.h +0 -2
@@ -640,8 +640,6 @@ static inline CPUARMState *cpu_init(const char *cpu_model)#define cpu_signal_handler cpu_arm_signal_handler#define cpu_list arm_cpu_list -#define CPU_SAVE_VERSION 9 -/* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel#define MMU_MODE1_SUFFIX _user
target-arm/machine.c +174 -213
411 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/3 target-arm: Add some missing CPU state fields to VMState
In reply to Peter MaydellA number of CPU state fields were accidentally omitted from our migration state: some OMAP specific cp15 registers, and some related to state for load/store exclusive insns. Add them.
--- target-arm/machine.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
target-arm/machine.c +10 -3
@@ -116,9 +116,9 @@ static const VMStateInfo vmstate_cpsr = {const VMStateDescription vmstate_arm_cpu = { .name ="cpu" , - .version_id =10 , - .minimum_version_id =10 , - .minimum_version_id_old =10 , + .version_id =11 , + .minimum_version_id =11 , + .minimum_version_id_old =11 , .fields = (VMStateField []) {VMSTATE_UINT32_ARRAY (env.regs,ARMCPU ,16 ), {
@@ -172,9 +172,16 @@ const VMStateDescription vmstate_arm_cpu = {VMSTATE_UINT32 (env.cp15.c13_tls2,ARMCPU ),VMSTATE_UINT32 (env.cp15.c13_tls3,ARMCPU ),VMSTATE_UINT32 (env.cp15.c15_cpar,ARMCPU ), +VMSTATE_UINT32 (env.cp15.c15_ticonfig,ARMCPU ), +VMSTATE_UINT32 (env.cp15.c15_i_max,ARMCPU ), +VMSTATE_UINT32 (env.cp15.c15_i_min,ARMCPU ), +VMSTATE_UINT32 (env.cp15.c15_threadid,ARMCPU ),VMSTATE_UINT32 (env.cp15.c15_power_control,ARMCPU ),VMSTATE_UINT32 (env.cp15.c15_diagnostic,ARMCPU ),VMSTATE_UINT32 (env.cp15.c15_power_diagnostic,ARMCPU ), +VMSTATE_UINT32 (env.exclusive_addr,ARMCPU ), +VMSTATE_UINT32 (env.exclusive_val,ARMCPU ), +VMSTATE_UINT32 (env.exclusive_high,ARMCPU ),VMSTATE_UINT64 (env.features,ARMCPU ),VMSTATE_END_OF_LIST () },
Signature · 1 line
1.7.9.5
PATCH 3/3 target-arm: Correctly restore FPSCR
In reply to Peter MaydellUse the helper functions to save and restore the FPSCR, so that we correctly propagate rounding mode and flushing behaviour into the float_status fields. This also allows us to stop saving the vector length/stride fields separately.
--- target-arm/machine.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-)
target-arm/machine.c +41 -7
@@ -9,17 +9,51 @@ static bool vfp_needed(void *opaque)return arm_feature (env,ARM_FEATURE_VFP ); } +static int get_fpscr (QEMUFile *f,void *opaque,size_t size) +{ +ARMCPU *cpu = opaque; +CPUARMState *env = &cpu->env; +uint32_t val =qemu_get_be32 (f); + +vfp_set_fpscr (env, val); +return 0 ; +} + +static void put_fpscr (QEMUFile *f,void *opaque,size_t size) +{ +ARMCPU *cpu = opaque; +CPUARMState *env = &cpu->env; + +qemu_put_be32 (f,vfp_get_fpscr (env)); +} + +static const VMStateInfo vmstate_fpscr = { + .name ="fpscr" , + .get = get_fpscr, + .put = put_fpscr, +}; +static const VMStateDescription vmstate_vfp = { .name ="cpu/vfp" , - .version_id =1 , - .minimum_version_id =1 , - .minimum_version_id_old =1 , + .version_id =2 , + .minimum_version_id =2 , + .minimum_version_id_old =2 , .fields = (VMStateField []) {VMSTATE_FLOAT64_ARRAY (env.vfp.regs,ARMCPU ,32 ), -VMSTATE_UINT32_ARRAY (env.vfp.xregs,ARMCPU ,16 ), -/* TODO: Should use proper FPSCR access functions. */ -VMSTATE_INT32 (env.vfp.vec_len,ARMCPU ), -VMSTATE_INT32 (env.vfp.vec_stride,ARMCPU ), +/* The xregs array is a little awkward because element 1 (FPSCR) +* requires a specific accessor, so we have to split it up in +* the vmstate: +*/ +VMSTATE_UINT32 (env.vfp.xregs[0 ],ARMCPU ), +VMSTATE_UINT32_SUB_ARRAY (env.vfp.xregs,ARMCPU ,2 ,14 ), + { + .name ="fpscr" , + .version_id =0 , + .size =sizeof (uint32_t ), + .info = &vmstate_fpscr, + .flags =VMS_SINGLE , + .offset =0 , + },VMSTATE_END_OF_LIST () } };
Signature · 1 line
1.7.9.5
Ping for review -- I plan to put these into a target-arm pullreq at the end of the week if nobody has any review comments.
thanks
-- PMM
Quoted 59 lines · Peter Maydell
This patch series converts target-arm to doing migration via a VMState structure, and fixes some minor bugs in migration of the CPU as well. The bulk of it is a patch Juan sent out back in the middle of last year
https://lists.gnu.org/archive/html/qemu-devel/2012-05/msg00550.html
which I have rebased and messed about with somewhat:
* rebased and fixed conflicts
* updated to usecpu_class_set_vmsd()
* updated with new/removed fields since original patch
* corrected subsection names so vmload doesn't fail
* changed to use custom VMStateInfo for cpsr rather than presave/postload hooksThe last of these was the subject of some discussion when Juan posted the patch (see URL above for the thread). The fundamental problem that has to be solved is "how do you deal with cases where the representation in the in memory struct is not the same as the on the wire representation?":
(a) Juan's original patch does "write wire format to random dummy field in the struct and then clean things up in presave/postload hooks".
(b) My patch follows what Alpha, i386 and some devices do: define a custom VMStateInfo which reads/writes the wire format and does the conversion to/from the struct.
(c) There was a mooted third approach of defining new vmstate macros and functionality so you could specify conversion functions for a field but leave actual reading and writing of the wire format to the core savevm code.The argument against (b) was that it makes introducing a new migration wire format harder, but on the other hand it's a year later and nobody has, and we already have examples of this in tree so another user is no big deal. So it doesn't seem to me to merit the effort of actually implementing (c). I've gone for (b) because I think it's better than (a).
Overall I think the whole series is an improvement over the separate save/load fields; I'd also like to get this changeover done before we start having to worry about freezing the ARM migration format.
Juan Quintela (1):
target-arm: port ARM CPU save/load to use VMStatePeter Maydell (2):
target-arm: Add some missing CPU state fields to VMState
target-arm: Correctly restore FPSCRtarget-arm/cpu-qom.h | 4 + target-arm/cpu.c | 1 + target-arm/cpu.h | 2 - target-arm/machine.c | 430 +++++++++++++++++++++++++------------------------- 4 files changed, 221 insertions(+), 216 deletions(-)--
1.7.9.5