sPAPR: Fix migration when CPUs are removed in random order
cover sPAPR: Fix migration when CPUs are removed in random order
device_add/del based CPU hotplug and unplug support is upstream for sPAPR PowerPC and is under development for x86. Both of these will support CPU device removal in random order (and not necessarily in LIFO order). Random order removal will result in holes in cpu_index range which causes migration to fail. This needs fixes in both generic code as well as arch specific code.
- We need to use arch_id as the instance_id when registering CPU devices using vmstate_register. To support forward migration, as per Igor's suggestion, this needs to be done conditionally based on machine type version.
- From pseries-2.7 onwards, we start using arch_id for migration as well as in XICS code.
In fact, Igor even suggested to move the vmstate registration calls into cpu_common_realizefn and yet-to-be-introduced cpu_common_unrealizefn. But I haven't done that in this patchset as I am hitting an unrelated issue with that movement.
This patchset depends on Greg Kurz's patchset where among other things, he is deriving cpu_dt_it (arch_id) based on core-id.
(https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg00210.html)
Tested changes to XICS code with both kernel_irqchip=on/off. This applies on ppc-for-2.7 branch of David's tree.
Bharata B Rao (5):
cpu: Factor out cpu vmstate_[un]register into separate routines
cpu: Optionally use arch_id instead of cpu_index in cpu
vmstate_register()
spapr: Implement CPUClass.get_arch_id() for PowerPC CPUs
xics: Use arch_id instead of cpu_index in XICS code
spapr: Prefer arch_id over cpu_index
exec.c | 53 +++++++++++++++++++++++++++++---------------- hw/intc/xics.c | 14 ++++++++---- hw/intc/xics_kvm.c | 12 +++++----- hw/intc/xics_spapr.c | 33 ++++++++++++++++++++++------ hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_cpu_core.c | 5 +++++ include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ target-ppc/translate_init.c | 8 +++++++ 9 files changed, 96 insertions(+), 36 deletions(-)
Signature · 1 line
2.7.4
RFC PATCH 1/5 cpu: Factor out cpu vmstate_[un]register into separate routines
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that vmstate_unregister calls are now done under !CONFIG_USER_ONLY to match with vmstate_register calls.
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)
exec.c +28 -19
@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)/* Return the AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)
@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +#else static int cpu_get_free_index (Error **errp)
@@ -638,8 +661,6 @@ static void cpu_release_index(CPUState *cpu)void cpu_exec_exit (CPUState *cpu) { -CPUClass *cc =CPU_GET_CLASS (cpu); -#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif
@@ -656,19 +677,13 @@ void cpu_exec_exit(CPUState *cpu) cpu->cpu_index =-1 ;#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); +#else +cpu_vmstate_unregister (cpu);#endif - -if (cc->vmsd !=NULL ) { -vmstate_unregister (NULL , cc->vmsd, cpu); - } -if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_unregister (NULL , &vmstate_cpu_common, cpu); - } }void cpu_exec_init (CPUState *cpu,Error **errp) { -CPUClass *cc =CPU_GET_CLASS (cpu);Error *local_err =NULL ; cpu->as =NULL ;
@@ -705,15 +720,9 @@ void cpu_exec_init(CPUState *cpu, Error **errp) }QTAILQ_INSERT_TAIL (&cpus, cpu, node);#if defined(CONFIG_USER_ONLY ) - (void ) cc;cpu_list_unlock ();#else -if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); - } -if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); - } +cpu_vmstate_register (cpu);#endif }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 5 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>
Quoted 37 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +15
-2@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)/* Return the AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{
exec.c static void cpu_release_index(CPUState *cpu) · line 642
Quoted 10 lines
exec.c +10
-0+CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +
Given you're factoring this out, would it make sense to defined no-op versions for CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?
Quoted 51 lines
exec.c +3
-17#else static int cpu_get_free_index (Error **errp)@@ -638,8 +661,6 @@ static void cpu_release_index(CPUState *cpu)void cpu_exec_exit (CPUState *cpu) { -CPUClass *cc =CPU_GET_CLASS (cpu); -#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif @@ -656,19 +677,13 @@ void cpu_exec_exit(CPUState *cpu) cpu->cpu_index =-1 ;#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); +#else +cpu_vmstate_unregister (cpu);#endif - -if (cc->vmsd !=NULL ) { -vmstate_unregister (NULL , cc->vmsd, cpu); - } -if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_unregister (NULL , &vmstate_cpu_common, cpu); - } }void cpu_exec_init (CPUState *cpu,Error **errp) { -CPUClass *cc =CPU_GET_CLASS (cpu);Error *local_err =NULL ; cpu->as =NULL ;@@ -705,15 +720,9 @@ void cpu_exec_init(CPUState *cpu, Error **errp) }QTAILQ_INSERT_TAIL (&cpus, cpu, node);#if defined(CONFIG_USER_ONLY ) - (void ) cc;cpu_list_unlock ();#else -if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); - } -if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); - } +cpu_vmstate_register (cpu);#endif }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 52 lines · David Gibson
Quoted 5 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 43 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +21
-2@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)/* Return the AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {
Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu) · line 642
Quoted 4 lines
exec.c +4
-0+vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
But as you note, we could do that with the existing code itself. Commit 741da0d3 limited the vmstate_register calls to !CONFIG_USER_ONLY. I am still not sure why cpu vmstate registration isn't needed for CONFIG_USER_ONLY
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 64 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 54 lines · David Gibson
Quoted 6 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 44 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +21
-2@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Return the AddressSpace corresponding to thespecified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu) · line 642
Quoted 4 lines
exec.c +4
-0+vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?
Quoted 3 lines
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
Quoted 5 lines
But as you note, we could do that with the existing code itself. Commit
741da0d3limited thevmstate_registercalls
to !CONFIG_USER_ONLY. I am still not sure why cpu vmstate registration isn't needed forCONFIG_USER_ONLY
there isn't migration for *-user targets but exec.c is common, hence ifdefs
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 67 lines · Igor Mammedov
Quoted 64 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 62 lines · David Gibson
Quoted 6 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 38 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +15
-2@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Return the AddressSpace corresponding to thespecified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{exec.c static void cpu_release_index(CPUState *cpu) · line 643
Quoted 10 lines
exec.c +10
-0+CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?
Quoted 6 lines
Quoted 3 lines
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
If I implement cpu_common_unrealize() and the associated logic similar to the existing cpu_common_realize(), it would involve changes to all archs. I have done the change only to ppc in the below experimental patch. Is this kind of change preferred or is it possible to do this in non-invasive way ?
exec.c +10 -6
@@ -617,7 +617,7 @@ static void cpu_release_index(CPUState *cpu) }/* TODO: cpu_index is int while .get_arch_id()is int64_t */ -static void cpu_vmstate_register (CPUState *cpu) +void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); int instance_id = cpu->prefer_arch_id_over_cpu_index ?
@@ -631,7 +631,7 @@ static void cpu_vmstate_register(CPUState *cpu) } } -static void cpu_vmstate_unregister (CPUState *cpu) +void cpu_vmstate_unregister (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu);
@@ -660,6 +660,14 @@ static void cpu_release_index(CPUState *cpu) {return ; } + +void cpu_vmstate_register (CPUState *cpu) +{ +} + +void cpu_vmstate_unregister (CPUState *cpu) +{ +}#endif void cpu_exec_exit (CPUState *cpu)
@@ -680,8 +688,6 @@ void cpu_exec_exit(CPUState *cpu) cpu->cpu_index =-1 ;#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_unregister (cpu);#endif }
@@ -724,8 +730,6 @@ void cpu_exec_init(CPUState *cpu, Error **errp)QTAILQ_INSERT_TAIL (&cpus, cpu, node);#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_register (cpu);#endif }
include/qom/cpu.h +2 -0
@@ -874,4 +874,6 @@ extern const struct VMStateDescription vmstate_cpu_common; .offset = 0, \ } +void cpu_vmstate_register (CPUState *cpu); +void cpu_vmstate_unregister (CPUState *cpu);#endif
qom/cpu.c +9 -0
@@ -314,12 +314,20 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) {CPUState *cpu =CPU (dev); +cpu_vmstate_register (cpu);if (dev->hotplugged) {cpu_synchronize_post_init (cpu);cpu_resume (cpu); } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +CPUState *cpu =CPU (dev); + +cpu_vmstate_unregister (cpu); +} +static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);
@@ -367,6 +375,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn;/* * Reason: CPUs still need special care by board code: wiring up * IRQs, adding reset handlers, halting non-first CPUs, ...
target-ppc/cpu-qom.h +1 -0
@@ -173,6 +173,7 @@ typedef struct PowerPCCPUClass {/*< public >*/ DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;void (*parent_reset)(CPUState *cpu);uint32_t pvr;
target-ppc/translate_init.c +3 -0
@@ -9743,10 +9743,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)static void ppc_cpu_unrealizefn (DeviceState *dev,Error **errp) {PowerPCCPU *cpu =POWERPC_CPU (dev); +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env;opc_handler_t **table;int i, j; + pcc->parent_unrealize (dev, errp);cpu_exec_exit (CPU (dev));for (i =0 ; i <PPC_CPU_OPCODES_LEN ; i++) {
@@ -10336,6 +10338,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 73 lines · On Tue, 5 Jul 2016 12:05:35 +0530 Bharata B Rao <[email protected]>…
Quoted 72 lines · Igor Mammedov
Quoted 69 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 55 lines · David Gibson
Quoted 6 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 45 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +0
-0@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Returnthe AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; }
exec.c +21
-2-#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu)
Quoted 4 lines
exec.c +4
-0+vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
Quoted 7 lines
Quoted 3 lines
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
If I implement
cpu_common_unrealize()and the associated logic similar to the existingcpu_common_realize(), it would involve changes to all archs.
maybe I'm missing something but why all arch will be involved? The only ones that could be affected are the ones that have their own cpu_xxx_unrealize() implemented without calling CPUClass::unrealize.
Quoted 141 lines
I have done the change only to ppc in the below experimental patch. Is this kind of change preferred or is it possible to do this in non-invasive way ?
exec.c +10
-6@@ -617,7 +617,7 @@ static void cpu_release_index(CPUState *cpu) }/* TODO: cpu_index is int while .get_arch_id()is int64_t */ -static void cpu_vmstate_register (CPUState *cpu) +void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); int instance_id = cpu->prefer_arch_id_over_cpu_index ?@@ -631,7 +631,7 @@ static void cpu_vmstate_register(CPUState *cpu) } } -static void cpu_vmstate_unregister (CPUState *cpu) +void cpu_vmstate_unregister (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu);@@ -660,6 +660,14 @@ static void cpu_release_index(CPUState *cpu) {return ; } + +void cpu_vmstate_register (CPUState *cpu) +{ +} + +void cpu_vmstate_unregister (CPUState *cpu) +{ +}#endif void cpu_exec_exit (CPUState *cpu)@@ -680,8 +688,6 @@ void cpu_exec_exit(CPUState *cpu) cpu->cpu_index =-1 ;#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_unregister (cpu);#endif }@@ -724,8 +730,6 @@ void cpu_exec_init(CPUState *cpu, Error **errp)QTAILQ_INSERT_TAIL (&cpus, cpu, node);#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_register (cpu);#endif }include/qom/cpu.h +0
-0@@ -874,4 +874,6 @@ extern const struct VMStateDescription
vmstate_cpu_common; .offset =
0, \ }include/qom/cpu.h +2
-0+void cpu_vmstate_register (CPUState *cpu); +void cpu_vmstate_unregister (CPUState *cpu);#endif qom/cpu.c +9
-0@@ -314,12 +314,20 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) {CPUState *cpu =CPU (dev); +cpu_vmstate_register (cpu);if (dev->hotplugged) {cpu_synchronize_post_init (cpu);cpu_resume (cpu); } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +CPUState *cpu =CPU (dev); + +cpu_vmstate_unregister (cpu); +} +static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);@@ -367,6 +375,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn;/* * Reason: CPUs still need special care by board code: wiring up * IRQs, adding reset handlers, halting non-first CPUs, ... target-ppc/cpu-qom.h +1
-0@@ -173,6 +173,7 @@ typedef struct PowerPCCPUClass {/*< public >*/ DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;void (*parent_reset)(CPUState *cpu);uint32_t pvr;target-ppc/translate_init.c +3
-0@@ -9743,10 +9743,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) static void ppc_cpu_unrealizefn(DeviceState *dev,Error **errp) {PowerPCCPU *cpu =POWERPC_CPU (dev); +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env;opc_handler_t **table;int i, j; + pcc->parent_unrealize (dev, errp);cpu_exec_exit (CPU (dev));for (i =0 ; i <PPC_CPU_OPCODES_LEN ; i++) {@@ -10336,6 +10338,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 80 lines · Igor Mammedov
Quoted 77 lines · On Tue, 5 Jul 2016 12:05:35 +0530 Bharata B Rao <[email protected]>…
Quoted 75 lines · Igor Mammedov
Quoted 65 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 55 lines · David Gibson
Quoted 6 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 45 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +0
-0@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Returnthe AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; }
exec.c +21
-2-#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu)
Quoted 4 lines
exec.c +4
-0+vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?Quoted 4 lines
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
Quoted 6 lines
Quoted 3 lines
If I implement
cpu_common_unrealize()and the associated logic similar to the existingcpu_common_realize(), it would involve changes to all archs.maybe I'm missing something but why all arch will be involved? The only ones that could be affected are the ones that have their own
cpu_xxx_unrealize()implemented without callingCPUClass::unrealize.
You are right, I didn't realize that most archs don't define their own cpu_xxx_unrealize call. So this should be a simple change. Will include a patch to move vmstate_[un]register() calls to cpu_common_[un]realize() in the next version.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
Quoted 94 lines · On Tue, 5 Jul 2016 13:08:28 +0530 Bharata B Rao <[email protected]>…
Quoted 85 lines · Igor Mammedov
Quoted 82 lines · On Tue, 5 Jul 2016 12:05:35 +0530 Bharata B Rao <[email protected]>…
Quoted 80 lines · Igor Mammedov
Quoted 69 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 59 lines · David Gibson
Quoted 7 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done
under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 47 lines
--- exec.c | 47++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)
exec.c +0
-0@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Returnthe AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; }
exec.c +22
-2-#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { + vmstate_unregister(NULL, &vmstate_cpu_common,Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu)
Quoted 4 lines
exec.c +3
-0cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?Quoted 5 lines
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
Quoted 7 lines
Quoted 3 lines
If I implement
cpu_common_unrealize()and the associated logic similar to the existingcpu_common_realize(), it would involve changes to all archs.maybe I'm missing something but why all arch will be involved? The only ones that could be affected are the ones that have their own
cpu_xxx_unrealize()implemented without callingCPUClass::unrealize.
Quoted 4 lines
You are right, I didn't realize that most archs don't define their own
cpu_xxx_unrealizecall. So this should be a simple change. Will include a patch to move vmstate_[un]register() calls to cpu_common_[un]realize() in the next version.
just replace this patch with cpu_common_[un]realize() variant
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 1/5] cpu: Factor out cpu vmstate_[un]register into separate routines
In reply to Bharata B RaoQuoted 75 lines · On Tue, 5 Jul 2016 12:05:35 +0530 Bharata B Rao <[email protected]>…
Quoted 67 lines · Igor Mammedov
Quoted 64 lines · On Tue, 5 Jul 2016 10:46:07 +0530 Bharata B Rao <[email protected]>…
Quoted 62 lines · David Gibson
Quoted 6 lines · Bharata B Rao
Consolidates cpu vmstate_[un]register calls into separate routines. No functionality change except that
vmstate_unregistercalls are now done under !CONFIG_USER_ONLY to match withvmstate_registercalls.Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>Quoted 38 lines
--- exec.c | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-)exec.c +15
-2@@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Return the AddressSpace corresponding to thespecified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);static int cpu_get_free_index (Error **errp)@@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) {bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } + +static void cpu_vmstate_register (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); + } +if (cc->vmsd !=NULL ) { +vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); + } +} + +static void cpu_vmstate_unregister (CPUState *cpu) +{exec.c static void cpu_release_index(CPUState *cpu) · line 643
Quoted 10 lines
exec.c +10
-0+CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +} +Given you're factoring this out, would it make sense to defined no-op versions for
CONFIG_USER_ONLY, to reduce the amount of ifdefs at the call site?Quoted 6 lines
Quoted 3 lines
I did that in a subsequent patch that moved the calls to these routines into cpu_common_[un]realize()cpu_common_[un]realize(), but ended up in some unrelated issue and hence didn't include that patch yet.
I'd prefer to see it moved to cpu_common_[un]realize() directly without tis intermediate transition as compat logic could be implemented much cleaner if it's there.
Quoted 6 lines
If I implement
cpu_common_unrealize()and the associated logic similar to the existingcpu_common_realize(), it would involve changes to all archs. I have done the change only to ppc in the below experimental patch. Is this kind of change preferred or is it possible to do this in non-invasive way ?
Even if affects all targets, the change is quite mechanical and should not be a problem I guess.
Quoted 137 lines
exec.c +10
-6@@ -617,7 +617,7 @@ static void cpu_release_index(CPUState *cpu) }/* TODO: cpu_index is int while .get_arch_id()is int64_t */ -static void cpu_vmstate_register (CPUState *cpu) +void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); int instance_id = cpu->prefer_arch_id_over_cpu_index ?@@ -631,7 +631,7 @@ static void cpu_vmstate_register(CPUState *cpu) } } -static void cpu_vmstate_unregister (CPUState *cpu) +void cpu_vmstate_unregister (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu);@@ -660,6 +660,14 @@ static void cpu_release_index(CPUState *cpu) {return ; } + +void cpu_vmstate_register (CPUState *cpu) +{ +} + +void cpu_vmstate_unregister (CPUState *cpu) +{ +}#endif void cpu_exec_exit (CPUState *cpu)@@ -680,8 +688,6 @@ void cpu_exec_exit(CPUState *cpu) cpu->cpu_index =-1 ;#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_unregister (cpu);#endif }@@ -724,8 +730,6 @@ void cpu_exec_init(CPUState *cpu, Error **errp)QTAILQ_INSERT_TAIL (&cpus, cpu, node);#if defined(CONFIG_USER_ONLY )cpu_list_unlock (); -#else -cpu_vmstate_register (cpu);#endif }include/qom/cpu.h +2
-0@@ -874,4 +874,6 @@ extern const struct VMStateDescription vmstate_cpu_common; .offset = 0, \ } +void cpu_vmstate_register (CPUState *cpu); +void cpu_vmstate_unregister (CPUState *cpu);#endif qom/cpu.c +9
-0@@ -314,12 +314,20 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) {CPUState *cpu =CPU (dev); +cpu_vmstate_register (cpu);if (dev->hotplugged) {cpu_synchronize_post_init (cpu);cpu_resume (cpu); } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +CPUState *cpu =CPU (dev); + +cpu_vmstate_unregister (cpu); +} +static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);@@ -367,6 +375,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn;/* * Reason: CPUs still need special care by board code: wiring up * IRQs, adding reset handlers, halting non-first CPUs, ... target-ppc/cpu-qom.h +1
-0@@ -173,6 +173,7 @@ typedef struct PowerPCCPUClass {/*< public >*/ DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;void (*parent_reset)(CPUState *cpu);uint32_t pvr;target-ppc/translate_init.c +3
-0@@ -9743,10 +9743,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)static void ppc_cpu_unrealizefn (DeviceState *dev,Error **errp) {PowerPCCPU *cpu =POWERPC_CPU (dev); +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env;opc_handler_t **table;int i, j; + pcc->parent_unrealize (dev, errp);cpu_exec_exit (CPU (dev));for (i =0 ; i <PPC_CPU_OPCODES_LEN ; i++) {@@ -10336,6 +10338,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)DeviceClass *dc =DEVICE_CLASS (oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;
RFC PATCH 2/5 cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
In reply to Bharata B RaoIntroduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using arch_id instead of cpu_index as instance_id in vmstate_register(). This will help allow successful migration in cases where holes are introduced in cpu_index range after CPU hot removals.
Whether to use arch_id or cpu_index is based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use of arch_id:
1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.
--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)
exec.c +8 -2
@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int while .get_arch_id()is +* of type int64_t. What is the consequence of changing instance_id to int64_t ? +*/ static void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cpu->prefer_arch_id_over_cpu_index ? + cc->get_arch_id (cpu) : cpu->cpu_index;if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , instance_id, &vmstate_cpu_common, cpu); }if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , instance_id, cc->vmsd, cpu); } }
include/hw/boards.h +1 -0
@@ -123,6 +123,7 @@ struct MachineClass {ram_addr_t default_ram_size;bool option_rom_has_mr;bool rom_file_has_mr; +bool prefer_arch_id_over_cpu_index; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);
include/qom/cpu.h +4 -0
@@ -273,6 +273,9 @@ struct qemu_work_item {* @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. +* @prefer_arch_id_over_cpu_index: Set to enforce the use of +* CPUClass.get_arch_id() over cpu_index during vmstate registration +* and any other uses by target machine where arch_id is preferred. * * State of one CPU core or thread. */
@@ -360,6 +363,7 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; +bool prefer_arch_id_over_cpu_index; };QTAILQ_HEAD (CPUTailQ, CPUState);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 13 lines · Bharata B Rao
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:
Quoted 6 lines
1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>
How is migration between a version with this flag and a version without this flag handled?
Quoted 68 lines
--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +8
-2@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int while .get_arch_id()is +* of type int64_t. What is the consequence of changing instance_id to int64_t ? +*/ static void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cpu->prefer_arch_id_over_cpu_index ? + cc->get_arch_id (cpu) : cpu->cpu_index;if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , instance_id, &vmstate_cpu_common, cpu); }if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , instance_id, cc->vmsd, cpu); } }include/hw/boards.h +1
-0@@ -123,6 +123,7 @@ struct MachineClass {ram_addr_t default_ram_size;bool option_rom_has_mr;bool rom_file_has_mr; +bool prefer_arch_id_over_cpu_index; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);include/qom/cpu.h +4
-0@@ -273,6 +273,9 @@ struct qemu_work_item {* @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. +* @prefer_arch_id_over_cpu_index: Set to enforce the use of +* CPUClass.get_arch_id() over cpu_index during vmstate registration +* and any other uses by target machine where arch_id is preferred. * * State of one CPU core or thread. */ @@ -360,6 +363,7 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; +bool prefer_arch_id_over_cpu_index; };QTAILQ_HEAD (CPUTailQ, CPUState);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 18 lines · David Gibson
Quoted 17 lines · Bharata B Rao
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.
Quoted 5 lines
Quoted 2 lines
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>How is migration between a version with this flag and a version without this flag handled?
There can't be such a case as this flag is enabled for a given machine version.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
In reply to Bharata B RaoQuoted 7 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.
Quoted 7 lines
Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
you could reuse compat mechanism like x86 instead of adding doing #1 see PC_COMPAT_2_6 and how it's used
Quoted 72 lines
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */
static voidcpu_vmstate_register(CPUState *cpu){ CPUClass *cc = CPU_GET_CLASS(cpu);exec.c +2
-1+int instance_id = cpu->prefer_arch_id_over_cpu_index ? + cc->get_arch_id (cpu) : cpu->cpu_index;if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common,cpu);
+ vmstate_register(NULL,instance_id,&vmstate_cpu_common,
cpu); }if (cc->vmsd != NULL) {exec.c +1
-1-vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , instance_id, cc->vmsd, cpu); } }include/hw/boards.h +1
-0@@ -123,6 +123,7 @@ struct MachineClass {ram_addr_t default_ram_size;bool option_rom_has_mr;bool rom_file_has_mr; +bool prefer_arch_id_over_cpu_index; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);include/qom/cpu.h +2
-0@@ -273,6 +273,9 @@ struct qemu_work_item {* @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. +* @prefer_arch_id_over_cpu_index: Set to enforce the use of +* CPUClass.get_arch_id() over cpu_index during vmstate registration
+ * and any other uses by target machine wherearch_idis
preferred. *
* State of one CPU core or thread.
*/include/qom/cpu.h +0
-0@@ -360,6 +363,7 @@ struct CPUState { (absolute value) offset as small as possible. This reducescode size, especially for hosts without large memory offsets. */
Quoted 2 lines
uint32_t tcg_exit_req;+ bool
prefer_arch_id_over_cpu_index;
this property applies to all cpu, so shouldn't it be class property?
Quoted 3 lines
};
QTAILQ_HEAD(CPUTailQ, CPUState);
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
In reply to Bharata B RaoQuoted 35 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int
Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */
ARM potentially could have get_arch_id() == MPIDR (return 64bit int) that would get truncated in this case.
I wonder if we could add "int CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and then cpu_realize could call vmstate_register with it.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 45 lines · Igor Mammedov
Quoted 35 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */ARM potentially could have
get_arch_id()== MPIDR (return 64bit int) that would get truncated in this case.
Quoted 3 lines
I wonder if we could add "int
CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and thencpu_realizecould callvmstate_registerwith it.
Hmm how would that help ? instance_id argument to vmstate_register() is being treated as 32 bit integer as pointed by Greg earlier.
If we want to use 64 bit arch_id/migration_id as instance_id arg in vmstate_register, shouldn't we be changing instance_id to 64 bit ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 51 lines · On Tue, 5 Jul 2016 18:13:22 +0530 Bharata B Rao <[email protected]>…
Quoted 46 lines · Igor Mammedov
Quoted 36 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */ARM potentially could have
get_arch_id()== MPIDR (return 64bit int) that would get truncated in this case.Quoted 3 lines
I wonder if we could add "int
CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and thencpu_realizecould callvmstate_registerwith it.
Quoted 5 lines
Hmm how would that help ?
instance_idargument tovmstate_register()is being treated as 32 bit integer as pointed by Greg earlier.If we want to use 64 bit arch_id/migration_id as
instance_idarg invmstate_register, shouldn't we be changinginstance_idto 64 bit ?
Trying to extend instance_id from 32bit to 64bit, looks hard to me as it's on wire format so it's not possible to change without breaking compatibility.
That's why dedicated migration_id should also be 32bit integer to keep it compatible with vmstate_foo() magic. On x86 and ARM that id will be in range [0..maxcpus), it's stable index in possible_cpus array.
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 59 lines · Igor Mammedov
Quoted 51 lines · On Tue, 5 Jul 2016 18:13:22 +0530 Bharata B Rao <[email protected]>…
Quoted 46 lines · Igor Mammedov
Quoted 36 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */ARM potentially could have
get_arch_id()== MPIDR (return 64bit int) that would get truncated in this case.Quoted 3 lines
I wonder if we could add "int
CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and thencpu_realizecould callvmstate_registerwith it.Quoted 5 lines
Hmm how would that help ?
instance_idargument tovmstate_register()is being treated as 32 bit integer as pointed by Greg earlier.If we want to use 64 bit arch_id/migration_id as
instance_idarg invmstate_register, shouldn't we be changinginstance_idto 64 bit ?
Quoted 7 lines
Trying to extend
instance_idfrom 32bit to 64bit, looks hard to me as it's on wire format so it's not possible to change without breaking compatibility.That's why dedicated
migration_idshould also be 32bit integer to keep it compatible withvmstate_foo()magic. On x86 and ARM that id will be in range [0..maxcpus), it's stable index inpossible_cpusarray.
Since we were planning to use arch_id (aka device tree id) as the stable index for CPU cores on PowerPC, we would have to use int64_t arch_id itself as int instance_id I suppose. The range could be [0...maxcpus*8] for us.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
Quoted 64 lines · Bharata B Rao
Quoted 63 lines · Igor Mammedov
Quoted 51 lines · On Tue, 5 Jul 2016 18:13:22 +0530 Bharata B Rao <[email protected]>…
Quoted 46 lines · Igor Mammedov
Quoted 36 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */ARM potentially could have
get_arch_id()== MPIDR (return 64bit int) that would get truncated in this case.Quoted 3 lines
I wonder if we could add "int
CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and thencpu_realizecould callvmstate_registerwith it.Quoted 5 lines
Hmm how would that help ?
instance_idargument tovmstate_register()is being treated as 32 bit integer as pointed by Greg earlier.If we want to use 64 bit arch_id/migration_id as
instance_idarg invmstate_register, shouldn't we be changinginstance_idto 64 bit ?Trying to extend
instance_idfrom 32bit to 64bit, looks hard to me as it's on wire format so it's not possible to change without breaking compatibility.
Quoted 8 lines
Quoted 3 lines
That's why dedicated
migration_idshould also be 32bit integer to keep it compatible withvmstate_foo()magic. On x86 and ARM that id will be in range [0..maxcpus), it's stable index inpossible_cpusarray.Since we were planning to use
arch_id(aka device tree id) as the stable index for CPU cores on PowerPC, we would have to useint64_tarch_iditself as intinstance_idI suppose. The range could be [0...maxcpus*8] for us.
Huh? I don't see how this comment relates to the one before.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
In reply to Igor MammedovQuoted 59 lines · On Wed, 6 Jul 2016 07:25:44 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 51 lines · On Tue, 5 Jul 2016 18:13:22 +0530 Bharata B Rao <[email protected]>…
Quoted 46 lines · Igor Mammedov
Quoted 36 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +2
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int Quoted 4 lines
while .get_arch_id()is
+ * of typeint64_t. What is the consequence of changinginstance_idtoint64_t?
+ */ARM potentially could have
get_arch_id()== MPIDR (return 64bit int) that would get truncated in this case.Quoted 3 lines
I wonder if we could add "int
CPUState::migration_id" and let machine code set it to what it uses for stable cpu id and thencpu_realizecould callvmstate_registerwith it.Quoted 5 lines
Hmm how would that help ?
instance_idargument tovmstate_register()is being treated as 32 bit integer as pointed by Greg earlier.If we want to use 64 bit arch_id/migration_id as
instance_idarg invmstate_register, shouldn't we be changinginstance_idto 64 bit ?
Quoted 8 lines
Trying to extend
instance_idfrom 32bit to 64bit, looks hard to me as it's on wire format so it's not possible to change without breaking compatibility.That's why dedicated
migration_idshould also be 32bit integer to keep it compatible withvmstate_foo()magic. On x86 and ARM that id will be in range [0..maxcpus), it's stable index inpossible_cpusarray.
On pseries-2.7, CPUs are stored in a 2-dimensional array but it also contains max_cpus elements actually.
Bharata sent this patch to add @stable_cpu_id to CPUState:
https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg01702.html
Do we really need the associated property if we provide a stable index in the [0..max_cpus) range ? This does not depend on the machine type or version unless I've missed something.
Quoted 7 lines
Quoted 6 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/5] cpu: Optionally use arch_id instead of cpu_index in cpu vmstate_register()
In reply to Bharata B RaoQuoted 30 lines · On Tue, 5 Jul 2016 10:12:49 +0530 Bharata B Rao <[email protected]>…
Introduce CPUState.prefer_arch_id_over_cpu_index and MachineClass.prefer_arch_id_over_cpu_index that allow target machines to optionally switch to using
arch_idinstead ofcpu_indexasinstance_idinvmstate_register(). This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.Whether to use
arch_idorcpu_indexis based on machine type version and hence added MachineClass.prefer_arch_id_over_cpu_index. However the enforcement is via and during CPU creation and hence added CPUState.prefer_arch_id_over_cpu_index. So it becomes a two step process for the target to enable the use ofarch_id:1. Set MachineClass.prefer_arch_id_over_cpu_index.
2. Ensure CPUState.prefer_arch_id_over_cpu_index is set for all CPUs based on 1. above.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 10 ++++++++-- include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-)exec.c +0
-0
exec.c static void cpu_release_index(CPUState *cpu) · line 622
Quoted 7 lines
exec.c +4
-0@@ -616,15 +616,21 @@ static void cpu_release_index(CPUState *cpu)bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); } +/* +* TODO: cpu_index and instance_id are of type int while .get_arch_id()is +* of type int64_t. What is the consequence of changing instance_id to int64_t ? +*/
The current migration code assumes instance_id is a 32-bit word:
migration/savevm.c: qemu_put_be32(f, se->instance_id);
Quoted 50 lines
exec.c +4
-2static void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cpu->prefer_arch_id_over_cpu_index ? + cc->get_arch_id (cpu) : cpu->cpu_index;if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { -vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu); +vmstate_register (NULL , instance_id, &vmstate_cpu_common, cpu); }if (cc->vmsd !=NULL ) { -vmstate_register (NULL , cpu->cpu_index, cc->vmsd, cpu); +vmstate_register (NULL , instance_id, cc->vmsd, cpu); } }include/hw/boards.h +1
-0@@ -123,6 +123,7 @@ struct MachineClass {ram_addr_t default_ram_size;bool option_rom_has_mr;bool rom_file_has_mr; +bool prefer_arch_id_over_cpu_index; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);include/qom/cpu.h +4
-0@@ -273,6 +273,9 @@ struct qemu_work_item {* @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to queued_work_*. * @queued_work_first: First asynchronous work pending. +* @prefer_arch_id_over_cpu_index: Set to enforce the use of +* CPUClass.get_arch_id() over cpu_index during vmstate registration +* and any other uses by target machine where arch_id is preferred. * * State of one CPU core or thread. */ @@ -360,6 +363,7 @@ struct CPUState {(absolute value) offset as small as possible. This reduces code size, especially for hosts without large memory offsets. */ uint32_t tcg_exit_req; +bool prefer_arch_id_over_cpu_index; };QTAILQ_HEAD (CPUTailQ, CPUState);
RFC PATCH 3/5 spapr: Implement CPUClass.get_arch_id() for PowerPC CPUs
In reply to Bharata B Rao--- target-ppc/translate_init.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target-ppc/translate_init.c +8 -0
@@ -10357,6 +10357,13 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int64_t ppc_cpu_get_arch_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +return cpu->cpu_dt_id; +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);
@@ -10409,6 +10416,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)#ifndef CONFIG_USER_ONLY cc->virtio_is_big_endian = ppc_cpu_is_big_endian;#endif + cc->get_arch_id = ppc_cpu_get_arch_id; dc->fw_name ="PowerPC,UNKNOWN" ; }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH v0 3/5] spapr: Implement CPUClass.get_arch_id() for PowerPC CPUs
Quoted 1 line · Bharata B Rao
Signed-off-by Bharata B Rao <[email protected]>
Longer term we should probably change the field name to arch_id. In theory we could have something like this on a platform that didn't do device trees.
Quoted 30 lines
--- target-ppc/translate_init.c | 8 ++++++++ 1 file changed, 8 insertions(+)target-ppc/translate_init.c +8
-0@@ -10357,6 +10357,13 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int64_t ppc_cpu_get_arch_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +return cpu->cpu_dt_id; +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10409,6 +10416,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)#ifndef CONFIG_USER_ONLY cc->virtio_is_big_endian = ppc_cpu_is_big_endian;#endif + cc->get_arch_id = ppc_cpu_get_arch_id; dc->fw_name ="PowerPC,UNKNOWN" ; }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
RFC PATCH 4/5 xics: Use arch_id instead of cpu_index in XICS code
In reply to Bharata B Raoxics maintains an array of ICPState structures which is indexed by cpu_index. Change this to index the ICPState array by arch_id for pseries-2.7 onwards. This allows migration of guest to suceed when there are holes in cpu_index range due to CPU hot removal.
--- hw/intc/xics.c | 14 ++++++++++---- hw/intc/xics_kvm.c | 12 ++++++------ hw/intc/xics_spapr.c | 33 ++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 17 deletions(-)
hw/intc/xics.c +10 -4
@@ -50,9 +50,12 @@ int xics_get_cpu_index_by_dt_id(int cpu_dt_id)void xics_cpu_destroy (XICSState *xics,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu); -ICPState *ss = &xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = &xics->ss[server]; -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);assert (cs == ss->cs); ss->output =NULL ;
@@ -63,10 +66,13 @@ void xics_cpu_setup(XICSState *xics, PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -ICPState *ss = &xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = &xics->ss[server];XICSStateClass *info =XICS_COMMON_GET_CLASS (xics); -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers); ss->cs = cs;
hw/intc/xics_kvm.c +6 -6
@@ -326,14 +326,14 @@ static const TypeInfo ics_kvm_info = {*/ static void xics_kvm_cpu_setup (XICSState *xics,PowerPCCPU *cpu) { -CPUState *cs; -ICPState *ss; +CPUState *cs =CPU (cpu);KVMXICSState *xicskvm =XICS_SPAPR_KVM (xics); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = ss = &xics->ss[server]; - cs =CPU (cpu); - ss = &xics->ss[cs->cpu_index]; - -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);if (xicskvm->kernel_xics_fd ==-1 ) {abort (); }
hw/intc/xics_spapr.c +26 -7
@@ -43,16 +43,21 @@ static target_ulong h_cppr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;target_ulong cppr = args[0 ]; -icp_set_cppr (spapr->xics, cs->cpu_index, cppr); +icp_set_cppr (spapr->xics, server, cppr);return H_SUCCESS ; }static target_ulong h_ipi (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) { -target_ulong server =xics_get_cpu_index_by_dt_id (args[0 ]); +CPUState *cs =CPU (cpu); +target_ulong server = cs->prefer_arch_id_over_cpu_index ? args[0 ] : +xics_get_cpu_index_by_dt_id (args[0 ]);target_ulong mfrr = args[1 ];if (server >= spapr->xics->nr_servers) {
@@ -67,7 +72,10 @@ static target_ulong h_xirr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -uint32_t xirr =icp_accept (spapr->xics->ss + cs->cpu_index); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +uint32_t xirr =icp_accept (spapr->xics->ss + server); args[0 ] = xirr;return H_SUCCESS ;
@@ -77,7 +85,10 @@ static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -ICPState *ss = &spapr->xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = &spapr->xics->ss[server];uint32_t xirr =icp_accept (ss); args[0 ] = xirr;
@@ -89,9 +100,12 @@ static target_ulong h_eoi(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;target_ulong xirr = args[0 ]; -icp_eoi (spapr->xics, cs->cpu_index, xirr); +icp_eoi (spapr->xics, server, xirr);return H_SUCCESS ; }
@@ -99,8 +113,11 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;uint32_t mfrr; -uint32_t xirr =icp_ipoll (spapr->xics->ss + cs->cpu_index, &mfrr); +uint32_t xirr =icp_ipoll (spapr->xics->ss + server, &mfrr); args[0 ] = xirr; args[1 ] = mfrr;
@@ -113,6 +130,7 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { + CPUState *cs = CPU(cpu);ICSState *ics = spapr->xics->ics;uint32_t nr, server, priority;
@@ -122,7 +140,8 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, } nr =rtas_ld (args,0 ); - server =xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); + server = cs->prefer_arch_id_over_cpu_index ?rtas_ld (args,1 ) : +xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); priority =rtas_ld (args,2 ); if (!ics_valid_irq(ics, nr) || (server >= ics->xics->nr_servers)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH v0 4/5] xics: Use arch_id instead of cpu_index in XICS code
Quoted 17 lines · Bharata B Rao
xics maintains an array of ICPState structures which is indexed by
cpu_index. Change this to index the ICPState array byarch_idfor pseries-2.7 onwards. This allows migration of guest to suceed when there are holes incpu_indexrange due to CPU hot removal.Signed-off-by Bharata B Rao <[email protected]>--- hw/intc/xics.c | 14 ++++++++++---- hw/intc/xics_kvm.c | 12 ++++++------ hw/intc/xics_spapr.c | 33 ++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 17 deletions(-)hw/intc/xics.c +0
-0
hw/intc/xics.c int xics_get_cpu_index_by_dt_id(int cpu_dt_id) · line 55
Quoted 7 lines
hw/intc/xics.c +3
-1@@ -50,9 +50,12 @@ int xics_get_cpu_index_by_dt_id(int cpu_dt_id)void xics_cpu_destroy (XICSState *xics,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu); -ICPState *ss = &xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;
Requiring this conditional in all the callsites is pretty ugly. I'd prefer to see a get_arch_id() helper that implements this fallback internally.
Quoted 145 lines
hw/intc/xics.c +7
-3+ICPState *ss = &xics->ss[server]; -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);assert (cs == ss->cs); ss->output =NULL ;@@ -63,10 +66,13 @@ void xics_cpu_setup(XICSState *xics, PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -ICPState *ss = &xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = &xics->ss[server];XICSStateClass *info =XICS_COMMON_GET_CLASS (xics); -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers); ss->cs = cs;hw/intc/xics_kvm.c +6
-6@@ -326,14 +326,14 @@ static const TypeInfo ics_kvm_info = {*/ static void xics_kvm_cpu_setup (XICSState *xics,PowerPCCPU *cpu) { -CPUState *cs; -ICPState *ss; +CPUState *cs =CPU (cpu);KVMXICSState *xicskvm =XICS_SPAPR_KVM (xics); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = ss = &xics->ss[server]; - cs =CPU (cpu); - ss = &xics->ss[cs->cpu_index]; - -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);if (xicskvm->kernel_xics_fd ==-1 ) {abort (); }hw/intc/xics_spapr.c +26
-7@@ -43,16 +43,21 @@ static target_ulong h_cppr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;target_ulong cppr = args[0 ]; -icp_set_cppr (spapr->xics, cs->cpu_index, cppr); +icp_set_cppr (spapr->xics, server, cppr);return H_SUCCESS ; }static target_ulong h_ipi (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) { -target_ulong server =xics_get_cpu_index_by_dt_id (args[0 ]); +CPUState *cs =CPU (cpu); +target_ulong server = cs->prefer_arch_id_over_cpu_index ? args[0 ] : +xics_get_cpu_index_by_dt_id (args[0 ]);target_ulong mfrr = args[1 ];if (server >= spapr->xics->nr_servers) {@@ -67,7 +72,10 @@ static target_ulong h_xirr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -uint32_t xirr =icp_accept (spapr->xics->ss + cs->cpu_index); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +uint32_t xirr =icp_accept (spapr->xics->ss + server); args[0 ] = xirr;return H_SUCCESS ;@@ -77,7 +85,10 @@ static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -ICPState *ss = &spapr->xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index; +ICPState *ss = &spapr->xics->ss[server];uint32_t xirr =icp_accept (ss); args[0 ] = xirr;@@ -89,9 +100,12 @@ static target_ulong h_eoi(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;target_ulong xirr = args[0 ]; -icp_eoi (spapr->xics, cs->cpu_index, xirr); +icp_eoi (spapr->xics, server, xirr);return H_SUCCESS ; }@@ -99,8 +113,11 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); +int server = cs->prefer_arch_id_over_cpu_index ? cc->get_arch_id (cs) : + cs->cpu_index;uint32_t mfrr; -uint32_t xirr =icp_ipoll (spapr->xics->ss + cs->cpu_index, &mfrr); +uint32_t xirr =icp_ipoll (spapr->xics->ss + server, &mfrr); args[0 ] = xirr; args[1 ] = mfrr;@@ -113,6 +130,7 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { + CPUState *cs = CPU(cpu);ICSState *ics = spapr->xics->ics;uint32_t nr, server, priority;@@ -122,7 +140,8 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, } nr =rtas_ld (args,0 ); - server =xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); + server = cs->prefer_arch_id_over_cpu_index ?rtas_ld (args,1 ) : +xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); priority =rtas_ld (args,2 ); if (!ics_valid_irq(ics, nr) || (server >= ics->xics->nr_servers)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [RFC PATCH v0 4/5] xics: Use arch_id instead of cpu_index in XICS code
Quoted 22 lines · On Tue, 5 Jul 2016 14:59:20 +1000 David Gibson <[email protected]>…
Quoted 21 lines · Bharata B Rao
xics maintains an array of ICPState structures which is indexed by
cpu_index. Change this to index the ICPState array byarch_idfor pseries-2.7 onwards. This allows migration of guest to suceed when there are holes incpu_indexrange due to CPU hot removal.Signed-off-by Bharata B Rao <[email protected]>--- hw/intc/xics.c | 14 ++++++++++---- hw/intc/xics_kvm.c | 12 ++++++------ hw/intc/xics_spapr.c | 33 ++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 17 deletions(-)hw/intc/xics.c +0
-1@@ -50,9 +50,12 @@ int xics_get_cpu_index_by_dt_id(int cpu_dt_id)void xics_cpu_destroy (XICSState *xics,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu); -ICPState *ss = &xics->ss[cs->cpu_index];
Quoted 8 lines
Quoted 4 lines
hw/intc/xics.c +2
-0+CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):
+cs->cpu_index;Requiring this conditional in all the callsites is pretty ugly. I'd prefer to see a
get_arch_id()helper that implements this fallback internally.
A cpu can look at prefer_arch_id_over_cpu_index and switch behavior of get_arch_id() internally.
Quoted 157 lines
Quoted 156 lines
hw/intc/xics.c +4
-2+ICPState *ss = &xics->ss[server]; -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);assert (cs == ss->cs); ss->output =NULL ;@@ -63,10 +66,13 @@ void xics_cpu_setup(XICSState *xics, PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -ICPState *ss = &xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics.c +3
-1+ cs->cpu_index; +ICPState *ss = &xics->ss[server];XICSStateClass *info =XICS_COMMON_GET_CLASS (xics); -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers); ss->cs = cs;hw/intc/xics_kvm.c +3
-2@@ -326,14 +326,14 @@ static const TypeInfo ics_kvm_info = {*/ static void xics_kvm_cpu_setup (XICSState *xics,PowerPCCPU *cpu) { -CPUState *cs; -ICPState *ss; +CPUState *cs =CPU (cpu);KVMXICSState *xicskvm =XICS_SPAPR_KVM (xics); +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_kvm.c +3
-4+ cs->cpu_index; +ICPState *ss = ss = &xics->ss[server]; - cs =CPU (cpu); - ss = &xics->ss[cs->cpu_index]; - -assert (cs->cpu_index < xics->nr_servers); +assert (server < xics->nr_servers);if (xicskvm->kernel_xics_fd ==-1 ) {abort (); }hw/intc/xics_spapr.c +2
-0@@ -43,16 +43,21 @@ static target_ulong h_cppr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_spapr.c +2
-1+ cs->cpu_index;target_ulong cppr = args[0 ]; -icp_set_cppr (spapr->xics, cs->cpu_index, cppr); +icp_set_cppr (spapr->xics, server, cppr);return H_SUCCESS ; } static target_ulong h_ipi(PowerPCCPU *cpu, sPAPRMachineState*spapr,
target_ulongopcode,target_ulong*args)
{hw/intc/xics_spapr.c +2
-1-target_ulong server =xics_get_cpu_index_by_dt_id (args[0 ]); +CPUState *cs =CPU (cpu); + target_ulong server = cs->prefer_arch_id_over_cpu_index ?args[0] :
hw/intc/xics_spapr.c +3
-1+xics_get_cpu_index_by_dt_id (args[0 ]);target_ulong mfrr = args[1 ];if (server >= spapr->xics->nr_servers) {@@ -67,7 +72,10 @@ static target_ulong h_xirr(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -uint32_t xirr =icp_accept (spapr->xics->ss + cs->cpu_index); +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_spapr.c +4
-1+ cs->cpu_index; +uint32_t xirr =icp_accept (spapr->xics->ss + server); args[0 ] = xirr;return H_SUCCESS ;@@ -77,7 +85,10 @@ static target_ulong h_xirr_x(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); -ICPState *ss = &spapr->xics->ss[cs->cpu_index]; +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_spapr.c +4
-0+ cs->cpu_index; +ICPState *ss = &spapr->xics->ss[server];uint32_t xirr =icp_accept (ss); args[0 ] = xirr;@@ -89,9 +100,12 @@ static target_ulong h_eoi(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_spapr.c +4
-1+ cs->cpu_index;target_ulong xirr = args[0 ]; -icp_eoi (spapr->xics, cs->cpu_index, xirr); +icp_eoi (spapr->xics, server, xirr);return H_SUCCESS ; }@@ -99,8 +113,11 @@ static target_ulong h_ipoll(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, target_ulong *args) { CPUState *cs = CPU(cpu); +CPUClass *cc =CPU_GET_CLASS (cs); + int server = cs->prefer_arch_id_over_cpu_index ?
cc->get_arch_id(cs):hw/intc/xics_spapr.c +1
-1+ cs->cpu_index;uint32_t mfrr; - uint32_t xirr = icp_ipoll(spapr->xics->ss + cs->cpu_index,&mfrr);
hw/intc/xics_spapr.c +4
-1+uint32_t xirr =icp_ipoll (spapr->xics->ss + server, &mfrr); args[0 ] = xirr; args[1 ] = mfrr;@@ -113,6 +130,7 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { + CPUState *cs = CPU(cpu);ICSState *ics = spapr->xics->ics;uint32_t nr, server, priority;@@ -122,7 +140,8 @@ static void rtas_set_xive(PowerPCCPU *cpu, sPAPRMachineState *spapr, } nr =rtas_ld (args,0 ); - server =xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); + server = cs->prefer_arch_id_over_cpu_index ?rtas_ld (args,1 ) : +xics_get_cpu_index_by_dt_id (rtas_ld (args,1 )); priority =rtas_ld (args,2 ); if (!ics_valid_irq(ics, nr) || (server >=
ics->xics->nr_servers)
RFC PATCH 5/5 spapr: Prefer arch_id over cpu_index
In reply to Bharata B RaoStarting from pseries-2.7, prefer the use of arch_id (cpu_dt_id) over cpu_index for cpu vmstate registration and in XICS code.
This allows migration to work when CPU cores are not necessarily unplugged in LIFO order.
--- hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_cpu_core.c | 5 +++++ 2 files changed, 7 insertions(+)
hw/ppc/spapr.c +2 -0
@@ -2426,6 +2426,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; mc->query_hotpluggable_cpus = spapr_query_hotpluggable_cpus; + mc->prefer_arch_id_over_cpu_index = true; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;
@@ -2512,6 +2513,7 @@ static void spapr_machine_2_6_class_options(MachineClass *mc)sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc);spapr_machine_2_7_class_options (mc); + mc->prefer_arch_id_over_cpu_index = false; smc->dr_cpu_enabled = false;SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_6 ); }
hw/ppc/spapr_cpu_core.c +5 -0
@@ -281,6 +281,8 @@ static void spapr_cpu_core_realize_child(Object *child, Error **errp)static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) { +MachineState *machine =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (machine);sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev));CPUCore *cc =CPU_CORE (OBJECT (dev));const char *typename =object_class_get_name (sc->cpu_class);
@@ -295,6 +297,9 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp) obj = sc->threads + i * size;object_initialize (obj, size, typename); +if (mc->prefer_arch_id_over_cpu_index) { +CPU (obj)->prefer_arch_id_over_cpu_index = true; + }snprintf (id,sizeof (id),"thread[%d]" , i);object_property_add_child (OBJECT (sc), id, obj, &local_err);if (local_err) {
Signature · 1 line
2.7.4
Quoted 14 lines · On Tue, 5 Jul 2016 10:12:47 +0530 Bharata B Rao <[email protected]>…
device_add/del based CPU hotplug and unplug support is upstream for sPAPR PowerPC and is under development for x86. Both of these will support CPU device removal in random order (and not necessarily in LIFO order). Random order removal will result in holes in
cpu_indexrange which causes migration to fail. This needs fixes in both generic code as well as arch specific code.- We need to use
arch_idas theinstance_idwhen registering CPU devices usingvmstate_register. To support forward migration, as per Igor's suggestion, this needs to be done conditionally based on machine type version.
- From pseries-2.7 onwards, we start usingarch_idfor migration as well as in XICS code.
Quoted 9 lines
In fact, Igor even suggested to move the vmstate registration calls into
cpu_common_realizefnand yet-to-be-introducedcpu_common_unrealizefn. But I haven't done that in this patchset as I am hitting an unrelated issue with that movement.This patchset depends on Greg Kurz's patchset where among other things, he is deriving
cpu_dt_it(arch_id) based on core-id.
(https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg00210.html)
I'm respinning my patchset according to the latest comments I got. This includes rebasing on top of Eduardo's tree to have the global parse_features bits, as mentioned here:
https://lists.nongnu.org/archive/html/qemu-devel/2016-07/msg00622.html
I'll rework this patch to apply on the current code:
https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg07564.html
Quoted 22 lines
Tested changes to XICS code with both kernel_irqchip=on/off. This applies on ppc-for-2.7 branch of David's tree.
Bharata B Rao (5):
cpu: Factor out cpu vmstate_[un]register into separate routines
cpu: Optionally usearch_idinstead ofcpu_indexin cpu
vmstate_register()
spapr: ImplementCPUClass.get_arch_id()for PowerPC CPUs
xics: Usearch_idinstead ofcpu_indexin XICS code
spapr: Preferarch_idovercpu_indexexec.c | 53 +++++++++++++++++++++++++++++---------------- hw/intc/xics.c | 14 ++++++++---- hw/intc/xics_kvm.c | 12 +++++----- hw/intc/xics_spapr.c | 33 ++++++++++++++++++++++------ hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_cpu_core.c | 5 +++++ include/hw/boards.h | 1 + include/qom/cpu.h | 4 ++++ target-ppc/translate_init.c | 8 +++++++ 9 files changed, 96 insertions(+), 36 deletions(-)