target-mips: port MIPS CPU to VMState
cover target-mips: port MIPS CPU to VMState
Hi,
This small patchset converts MIPS CPU to use VMStateDescription:
[1/2]: ports all the MIPS CPU fields to new VMStateDescription structure [2/2]: adds MSA and corrects FP state. These changes include ported Maciej's
updates made for old cpu_load/cpu_save sent some time ago.
I tested them by just checking whether the restored guest system still works after savevm/loadvm and migrate commands.
This series applies on top of the pending mips-next pull request:
http://patchwork.ozlabs.org/patch/439769/
Comments and suggestions are welcome.
Thanks,
Leon
Leon Alrae (2):
target-mips: replace cpu_save/cpu_load with VMStateDescription
target-mips: add missing MSA and correct FP in VMState
target-mips/cpu-qom.h | 4 + target-mips/cpu.c | 1 + target-mips/cpu.h | 2 - target-mips/machine.c | 570 +++++++++++++++++++++++--------------------------- 4 files changed, 265 insertions(+), 312 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/2 target-mips: replace cpu_save/cpu_load with VMStateDescription
Create VMStateDescription for MIPS CPU. The new structure contains exactly the same fields as before, therefore leaving existing version_id.
--- target-mips/cpu-qom.h | 4 + target-mips/cpu.c | 1 + target-mips/cpu.h | 2 - target-mips/machine.c | 567 ++++++++++++++++++++++---------------------------- 4 files changed, 257 insertions(+), 317 deletions(-)
target-mips/cpu-qom.h +4 -0
@@ -74,6 +74,10 @@ static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)#define ENV_OFFSET offsetof(MIPSCPU, env) +#ifndef CONFIG_USER_ONLY +extern const struct VMStateDescription vmstate_mips_cpu; +#endif +void mips_cpu_do_interrupt (CPUState *cpu);bool mips_cpu_exec_interrupt (CPUState *cpu,int int_req); void mips_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
target-mips/cpu.c +1 -0
@@ -148,6 +148,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; + dc->vmsd = &vmstate_mips_cpu;#endif cc->gdb_num_core_regs =73 ;
target-mips/cpu.h +0 -2
@@ -614,8 +614,6 @@ void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf);extern void cpu_wrdsp (uint32_t rs,uint32_t mask_num,CPUMIPSState *env);extern uint32_t cpu_rddsp (uint32_t mask_num,CPUMIPSState *env); -#define CPU_SAVE_VERSION 5 -/* MMU modes definitions. We carefully match the indices with our hflags layout. */ #define MMU_MODE0_SUFFIX _kernel
target-mips/machine.c +252 -315
593 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 1/2] target-mips: replace cpu_save/cpu_load with VMStateDescription
Hi Leon,
Am 18.02.2015 um 15:51 schrieb Leon Alrae:
Quoted 10 lines
Create VMStateDescription for MIPS CPU. The new structure contains exactly the same fields as before, therefore leaving existing
version_id.Signed-off-by Leon Alrae <[email protected]>--- target-mips/cpu-qom.h | 4 + target-mips/cpu.c | 1 + target-mips/cpu.h | 2 - target-mips/machine.c | 567 ++++++++++++++++++++++---------------------------- 4 files changed, 257 insertions(+), 317 deletions(-)
[...]
target-mips/cpu.c static void mips_cpu_class_init(ObjectClass *c, void *data) · line 151
Quoted 9 lines
target-mips/cpu.c +1
-0@@ -148,6 +148,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; + dc->vmsd = &vmstate_mips_cpu;
This looks wrong. There's two ways to do a CPU VMSD, 1) via dc->vmsd, and 2) via cc->vmsd. When going for the new dc->vmsd, the common CPU state would need to be referenced from vmstate_mips_cpu below. Doing so would break backwards compatibility, so you probably want cc->vmsd, causing a separate VMSD for the common parts to be registered.
Regards,
Andreas
Quoted 3 lines
target-mips/cpu.c +0
-0#endif cc->gdb_num_core_regs =73 ;
[...]
Quoted 5 lines
target-mips/machine.c +0
-0@@ -1,341 +1,278 @@
[...]
Quoted 8 lines
target-mips/machine.c +8
-0+const VMStateDescription vmstate_mips_cpu = { + .name ="cpu" , + .version_id =5 , + .minimum_version_id =5 , + .fields = (VMStateField []) { +/* active TC */ +VMSTATE_STRUCT (env.active_tc,MIPSCPU ,1 , vmstate_tc, TCState), +
[snip]
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
Re: [Qemu-devel] [PATCH 1/2] target-mips: replace cpu_save/cpu_load with VMStateDescription
Hi,
Quoted 14 lines · Andreas Färber
Hi Leon,
Am 18.02.2015 um 15:51 schrieb Leon Alrae:
Quoted 10 lines
Create VMStateDescription for MIPS CPU. The new structure contains exactly the same fields as before, therefore leaving existing
version_id.Signed-off-by Leon Alrae <[email protected]>--- target-mips/cpu-qom.h | 4 + target-mips/cpu.c | 1 + target-mips/cpu.h | 2 - target-mips/machine.c | 567 ++++++++++++++++++++++---------------------------- 4 files changed, 257 insertions(+), 317 deletions(-)[...]
Quoted 15 lines
target-mips/cpu.c static void mips_cpu_class_init(ObjectClass *c, void *data) · line 151
Quoted 9 lines
target-mips/cpu.c +1
-0@@ -148,6 +148,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) cc->do_unassigned_access = mips_cpu_unassigned_access; cc->do_unaligned_access = mips_cpu_do_unaligned_access; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; + dc->vmsd = &vmstate_mips_cpu;This looks wrong. There's two ways to do a CPU VMSD, 1) via
dc->vmsd, and 2) viacc->vmsd. When going for the newdc->vmsd, the common CPU state would need to be referenced fromvmstate_mips_cpubelow. Doing so would break backwards compatibility, so you probably wantcc->vmsd, causing a separate VMSD for the common parts to be registered.
Ah, I see it now in cpu_exec_init() that vmstate_cpu_common won't get registered if I set dc->vmsd. Thanks for pointing that out.
Regards,
Leon
PATCH 2/2 target-mips: add missing MSA and correct FP in VMState
In reply to Leon AlraeCorrect the structure and store MSA and FP flush_to_zero.
--- target-mips/machine.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
target-mips/machine.c +18 -5
@@ -6,15 +6,23 @@static int get_fpr (QEMUFile *f,void *pv,size_t size) { +int i;fpr_t *v = pv; -qemu_get_be64s (f, &v->d); +/* Restore entire MSA vector register */ +for (i =0 ; i <MSA_WRLEN /64 ; i++) { +qemu_get_sbe64s (f, &v->wr.d[i]); + }return 0 ; }static void put_fpr (QEMUFile *f,void *pv,size_t size) { +int i;fpr_t *v = pv; -qemu_put_be64s (f, &v->d); +/* Save entire MSA vector register */ +for (i =0 ; i <MSA_WRLEN /64 ; i++) { +qemu_put_sbe64s (f, &v->wr.d[i]); + } }const VMStateInfo vmstate_info_fpr = {
@@ -31,7 +39,7 @@ const VMStateInfo vmstate_info_fpr = {static VMStateField vmstate_fpu_fields[] = {VMSTATE_FPR_ARRAY (fpr, CPUMIPSFPUContext,32 ), -VMSTATE_INT8 (fp_status.float_detect_tininess, CPUMIPSFPUContext), +VMSTATE_UINT8 (fp_status.flush_to_zero, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_rounding_mode, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_exception_flags, CPUMIPSFPUContext),VMSTATE_UINT32 (fcr0, CPUMIPSFPUContext),
@@ -70,6 +78,11 @@ static VMStateField vmstate_tc_fields[] = {VMSTATE_UINTTL (CP0_TCScheFBack, TCState),VMSTATE_INT32 (CP0_Debug_tcstatus, TCState),VMSTATE_UINTTL (CP0_UserLocal, TCState), +VMSTATE_INT32 (msacsr, TCState), +VMSTATE_INT8 (msa_fp_status.float_rounding_mode, TCState), +VMSTATE_INT8 (msa_fp_status.float_exception_flags, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_to_zero, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_inputs_to_zero, TCState),VMSTATE_END_OF_LIST () };
@@ -183,8 +196,8 @@ const VMStateDescription vmstate_tlb = {const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , - .version_id =5 , - .minimum_version_id =5 , + .version_id =6 , + .minimum_version_id =6 , .fields = (VMStateField []) {/* active TC */ VMSTATE_STRUCT (env.active_tc,MIPSCPU ,1 , vmstate_tc, TCState),
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH 2/2] target-mips: add missing MSA and correct FP in VMState
Quoted 8 lines · Leon Alrae
static VMStateField vmstate_fpu_fields[] = {
VMSTATE_FPR_ARRAY(fpr, CPUMIPSFPUContext, 32),target-mips/machine.c +1
-1-VMSTATE_INT8 (fp_status.float_detect_tininess, CPUMIPSFPUContext), +VMSTATE_UINT8 (fp_status.flush_to_zero, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_rounding_mode, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_exception_flags, CPUMIPSFPUContext), VMSTATE_UINT32(fcr0, CPUMIPSFPUContext),
target-mips/machine.c static VMStateField vmstate_tc_fields[] = { · line 87
Quoted 10 lines
target-mips/machine.c +5
-0@@ -70,6 +78,11 @@ static VMStateField vmstate_tc_fields[] = {VMSTATE_UINTTL (CP0_TCScheFBack, TCState),VMSTATE_INT32 (CP0_Debug_tcstatus, TCState),VMSTATE_UINTTL (CP0_UserLocal, TCState), +VMSTATE_INT32 (msacsr, TCState), +VMSTATE_INT8 (msa_fp_status.float_rounding_mode, TCState), +VMSTATE_INT8 (msa_fp_status.float_exception_flags, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_to_zero, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_inputs_to_zero, TCState),VMSTATE_END_OF_LIST () };
Surely these fp_status fields are simply implementation of the architectural CSR registers?
IMO you shouldn't store things related to TCG state, but always how the architecture represents it. That way you're free to change the TCG implementation without breaking save/restore.
r~
Re: [Qemu-devel] [PATCH 2/2] target-mips: add missing MSA and correct FP in VMState
Quoted 23 lines · Richard Henderson
Quoted 8 lines · Leon Alrae
static VMStateField vmstate_fpu_fields[] = {
VMSTATE_FPR_ARRAY(fpr, CPUMIPSFPUContext, 32),target-mips/machine.c +1
-1-VMSTATE_INT8 (fp_status.float_detect_tininess, CPUMIPSFPUContext), +VMSTATE_UINT8 (fp_status.flush_to_zero, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_rounding_mode, CPUMIPSFPUContext),VMSTATE_INT8 (fp_status.float_exception_flags, CPUMIPSFPUContext), VMSTATE_UINT32(fcr0, CPUMIPSFPUContext),target-mips/machine.c static VMStateField vmstate_tc_fields[] = { · line 87
Quoted 10 lines
target-mips/machine.c +5
-0@@ -70,6 +78,11 @@ static VMStateField vmstate_tc_fields[] = {VMSTATE_UINTTL (CP0_TCScheFBack, TCState),VMSTATE_INT32 (CP0_Debug_tcstatus, TCState),VMSTATE_UINTTL (CP0_UserLocal, TCState), +VMSTATE_INT32 (msacsr, TCState), +VMSTATE_INT8 (msa_fp_status.float_rounding_mode, TCState), +VMSTATE_INT8 (msa_fp_status.float_exception_flags, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_to_zero, TCState), +VMSTATE_UINT8 (msa_fp_status.flush_inputs_to_zero, TCState),VMSTATE_END_OF_LIST () };Surely these
fp_statusfields are simply implementation of the architectural CSR registers?
Quoted 3 lines
IMO you shouldn't store things related to TCG state, but always how the architecture represents it. That way you're free to change the TCG implementation without breaking save/restore.
Good point. Saving fp_status and msa_fp_status doesn't seem to be needed at all as they can be restored from FCSR and MSACSR respectively. Presumably I can use vmstate post_load() for that.
Thanks,
Leon
Re: [Qemu-devel] [PATCH 2/2] target-mips: add missing MSA and correct FP in VMState
Quoted 9 lines · Leon Alrae
Quoted 6 lines
Surely these
fp_statusfields are simply implementation of the architectural CSR registers?IMO you shouldn't store things related to TCG state, but always how the architecture represents it. That way you're free to change the TCG implementation without breaking save/restore.
Good point. Saving
fp_statusandmsa_fp_statusdoesn't seem to be needed at all as they can be restored from FCSR and MSACSR respectively.
Agreed. Richard, thanks for the suggestion!
Maciej