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.
- migration_id is newly introduced and used as instance_id when registering CPU devices using vmstate_register. migration_id is set by the target machine code. 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 migration_id for migration as well as in XICS code.
vmstate registration calls are moved to cpu_common_realizefn and newly introduced cpu_common_unrealizefn.
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.
Changes in v1
-------------
- Introduced CPUState::migration_id to be used with vmstate_register()
- migration_id is now set by target machine code via CPUClass::get_migration_id()
- Use of migration is controlled by a property CPUState:use_migration_id.
- Use of SPAPR_COMPAT_2_6 to set use-migration-id property for all CPUs starting from pseries-2.7 onwards.
- Calling vmstate_[un]register() from cpu_common_[un]realizefn calls.
v0: http://lists.nongnu.org/archive/html/qemu-ppc/2016-07/msg00090.html
Bharata B Rao (5):
cpu,target-ppc: Move cpu_vmstate_[un]register calls to
cpu_common_[un]realize
cpu: Introduce CPUState::migration_id
spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
xics: Use migration_id instead of cpu_index in XICS code cpu,spapr: Use migration_id from pseries-2.7 onwards
exec.c | 54 ++++++++++++++++++++++++++++----------------- hw/intc/xics.c | 12 ++++++---- hw/intc/xics_kvm.c | 11 +++++---- hw/intc/xics_spapr.c | 28 +++++++++++++++++------ hw/ppc/spapr.c | 5 +++++ include/qom/cpu.h | 8 +++++++ qom/cpu.c | 29 ++++++++++++++++++++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 15 +++++++++++++ 9 files changed, 127 insertions(+), 37 deletions(-)
Signature · 1 line
2.7.4
RFC PATCH 1/5 cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
Move vmstate_register() call to cpu_common_realize(). Introduce cpu_common_unrealize() and move vmstate_unregister() to it.
Change those archs that implement their own CPU unrealize routine to mandatorily call CPUClass::unrealize().
--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)
exec.c +33 -20
@@ -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 ); } + +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); + } +} + +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)
@@ -634,12 +657,18 @@ 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) { -CPUClass *cc =CPU_GET_CLASS (cpu); -#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif
@@ -657,18 +686,10 @@ void cpu_exec_exit(CPUState *cpu)#if defined(CONFIG_USER_ONLY )cpu_list_unlock ();#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 +726,7 @@ 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); - }#endif }
include/qom/cpu.h +2 -0
@@ -870,4 +870,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 +7 -0
@@ -310,10 +310,16 @@ static void cpu_common_parse_features(CPUState *cpu, char *features, } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +cpu_vmstate_unregister (CPU (dev)); +} +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);
@@ -367,6 +373,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 +2 -0
@@ -163,6 +163,7 @@ struct ppc_segment_page_sizes;/** * PowerPCCPUClass: * @parent_realize: The parent class' realize handler. +* @parent_unrealize: The parent class' unrealize handler. * @parent_reset: The parent class' reset handler. * * A PowerPC CPU model.
@@ -173,6 +174,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
@@ -9773,10 +9773,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++) {
@@ -10364,6 +10366,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;
Signature · 1 line
2.7.4
RFC PATCH 2/5 cpu: Introduce CPUState::migration_id
In reply to Bharata B RaoAdd CPUState::migration_id and use that as instance_id in vmstate_register() call.
Introduce use-migration-id property that allows target machines to optionally switch to using migration_id instead of cpu_index. This will help allow successful migration in cases where holes are introduced in cpu_index range after CPU hot removals.
The default implementation of CPUClass:get_migration_id() continues to return cpu_index.
--- exec.c | 5 +++-- include/qom/cpu.h | 6 ++++++ qom/cpu.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)
exec.c +3 -2
@@ -619,12 +619,13 @@ static void cpu_release_index(CPUState *cpu)void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cc->get_migration_id (cpu);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/qom/cpu.h +6 -0
@@ -187,6 +187,7 @@ typedef struct CPUClass {bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request);void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +int (*get_migration_id)(CPUState *cpu); } CPUClass;#ifdef HOST_WORDS_BIGENDIAN
@@ -273,6 +274,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. +* @migration_id: Use as instance_id argument in cpu vmstate_register calls +* @use_migration_id: Set to enforce the use of CPUClass.get_migration_id() +* over cpu_index during vmstate registration. * * State of one CPU core or thread. */
@@ -360,6 +364,8 @@ 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; +int migration_id; +bool use_migration_id; };QTAILQ_HEAD (CPUTailQ, CPUState);
qom/cpu.c +21 -0
@@ -326,6 +326,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } } +static bool cpu_common_get_use_migration_id (Object *obj,Error **errp) +{ +return CPU (obj)->use_migration_id; +} + +static void cpu_common_set_use_migration_id (Object *obj,bool value, +Error **err) +{ +CPU (obj)->use_migration_id = value; +} +static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);
@@ -336,6 +347,10 @@ static void cpu_common_initfn(Object *obj)qemu_mutex_init (&cpu->work_mutex);QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints); + +object_property_add_bool (obj,"use-migration-id" , + cpu_common_get_use_migration_id, + cpu_common_set_use_migration_id,NULL ); }static void cpu_common_finalize (Object *obj)
@@ -348,6 +363,11 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu)return cpu->cpu_index; } +static int cpu_common_get_migration_id (CPUState *cpu) +{ +return cpu->cpu_index; +} +static void cpu_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -372,6 +392,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_enter = cpu_common_noop; k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; + k->get_migration_id = cpu_common_get_migration_id; dc->realize = cpu_common_realizefn; dc->unrealize = cpu_common_unrealizefn;/*
Signature · 1 line
2.7.4
RFC PATCH 3/5 spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B Raocpu_index is used as migration_id by default. For machine type versions that set use-migration-id property, cpu_dt_it is returned.
--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target-ppc/translate_init.c +12 -0
@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id; + }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);
@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_id; dc->fw_name ="PowerPC,UNKNOWN" ; }
Signature · 1 line
2.7.4
RFC PATCH 4/5 xics: Use migration_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 migration_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.
NOTE: In rtas_set_xive() and h_ipi(), cpu_dt_id is implicitly assume to be equivalent to migration_id.
--- hw/intc/xics.c | 12 ++++++++---- hw/intc/xics_kvm.c | 11 +++++------ hw/intc/xics_spapr.c | 28 +++++++++++++++++++++------- 3 files changed, 34 insertions(+), 17 deletions(-)
hw/intc/xics.c +8 -4
@@ -50,9 +50,11 @@ 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 = cc->get_migration_id (cs); +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 +65,12 @@ 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 = cc->get_migration_id (cs); +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 +5 -6
@@ -326,14 +326,13 @@ 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 = cc->get_migration_id (cs); +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 +21 -7
@@ -43,16 +43,20 @@ 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 = cc->get_migration_id (cs);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->use_migration_id ? args[0 ] : +xics_get_cpu_index_by_dt_id (args[0 ]);target_ulong mfrr = args[1 ];if (server >= spapr->xics->nr_servers) {
@@ -67,7 +71,9 @@ 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 = cc->get_migration_id (cs); +uint32_t xirr =icp_accept (spapr->xics->ss + server); args[0 ] = xirr;return H_SUCCESS ;
@@ -77,7 +83,9 @@ 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 = cc->get_migration_id (cs); +ICPState *ss = &spapr->xics->ss[server];uint32_t xirr =icp_accept (ss); args[0 ] = xirr;
@@ -89,9 +97,11 @@ 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 = cc->get_migration_id (cs);target_ulong xirr = args[0 ]; -icp_eoi (spapr->xics, cs->cpu_index, xirr); +icp_eoi (spapr->xics, server, xirr);return H_SUCCESS ; }
@@ -99,8 +109,10 @@ 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 = cc->get_migration_id (cs);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 +125,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 +135,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->use_migration_id ?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
RFC PATCH 5/5 cpu, spapr: Use migration_id from pseries-2.7 onwards
In reply to Bharata B RaoTurn on use-migration-id property. Starting from pseries-2.7, prefer the use of migration_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.
TODO: Property use-migration-id is by default turned on, check if this needs to turned off for older machine type versions of all archs.
--- hw/ppc/spapr.c | 5 +++++ qom/cpu.c | 1 + 2 files changed, 6 insertions(+)
hw/ppc/spapr.c +5 -0
@@ -2501,6 +2501,11 @@ DEFINE_SPAPR_MACHINE(2_7, "2.7", true); .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ .property = "ddw",\ .value = stringify(off),\ + }, \ + { \ + .driver = TYPE_CPU,\ + .property = "use-migration-id",\ + .value = stringify(off),\ }, static void spapr_machine_2_6_instance_options(MachineState *machine)
qom/cpu.c +1 -0
@@ -351,6 +351,7 @@ static void cpu_common_initfn(Object *obj)object_property_add_bool (obj,"use-migration-id" , cpu_common_get_use_migration_id, cpu_common_set_use_migration_id,NULL ); +object_property_set_bool (obj, true,"use-migration-id" ,NULL ); }static void cpu_common_finalize (Object *obj)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [RFC PATCH v1 4/5] xics: Use migration_id instead of cpu_index in XICS code
In reply to Bharata B RaoQuoted 20 lines · Bharata B Rao
xics maintains an array of ICPState structures which is indexed by
cpu_index. Change this to index the ICPState array bymigration_idfor pseries-2.7 onwards. This allows migration of guest to suceed when there are holes incpu_indexrange due to CPU hot removal.NOTE: In
rtas_set_xive()andh_ipi(),cpu_dt_idis implicitly assume to be equivalent tomigration_id.Signed-off-by Bharata B Rao <[email protected]>--- hw/intc/xics.c | 12 ++++++++---- hw/intc/xics_kvm.c | 11 +++++------ hw/intc/xics_spapr.c | 28 +++++++++++++++++++++------- 3 files changed, 34 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,11 @@ 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 = cc->get_migration_id (cs); +ICPState *ss = &xics->ss[server];
A helper like this will make code much more compact at other places:
static inline int xics_get_server(PowerPCCPU cpu)
{
CPUState *cs = CPU(cpu);
CPUClass *cc = CPU_GET_CLASS(cs);
return cc->get_migration_id(cs);
}void xics_cpu_destroy(XICSState *xics, PowerPCCPU *cpu)
{
int server = xics_get_server(cpu);
ICPState *ss = &xics->ss[server];....
}
Regards
Nikunj
Re: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
In reply to Bharata B RaoQuoted 48 lines · On Wed, 6 Jul 2016 14:29:17 +0530 Bharata B Rao <[email protected]>…
Move
vmstate_register()call tocpu_common_realize(). Introducecpu_common_unrealize()and movevmstate_unregister()to it.Change those archs that implement their own CPU unrealize routine to mandatorily call
CPUClass::unrealize().Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)exec.c +14
-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 ); } + +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); + } +} + +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); + } +}
Is there any reason to keep these in exec.c,
I'd put them in qom/cpu.c
Quoted 145 lines
exec.c +8
-18#else static int cpu_get_free_index (Error **errp)@@ -634,12 +657,18 @@ 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) { -CPUClass *cc =CPU_GET_CLASS (cpu); -#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif @@ -657,18 +686,10 @@ void cpu_exec_exit(CPUState *cpu)#if defined(CONFIG_USER_ONLY )cpu_list_unlock ();#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 +726,7 @@ 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); - }#endif }include/qom/cpu.h +0
-0@@ -870,4 +870,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 +7
-0@@ -310,10 +310,16 @@ static void cpu_common_parse_features(CPUState *cpu, char *features, } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +cpu_vmstate_unregister (CPU (dev)); +} +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);@@ -367,6 +373,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 +2
-0@@ -163,6 +163,7 @@ struct ppc_segment_page_sizes;/** * PowerPCCPUClass: * @parent_realize: The parent class' realize handler. +* @parent_unrealize: The parent class' unrealize handler. * @parent_reset: The parent class' reset handler. * * A PowerPC CPU model. @@ -173,6 +174,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@@ -9773,10 +9773,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++) {@@ -10364,6 +10366,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 v1 2/5] cpu: Introduce CPUState::migration_id
In reply to Bharata B RaoQuoted 57 lines · On Wed, 6 Jul 2016 14:29:18 +0530 Bharata B Rao <[email protected]>…
Add
CPUState::migration_idand use that asinstance_idinvmstate_register()call.Introduce use-migration-id property that allows target machines to optionally switch to using
migration_idinstead ofcpu_index. This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.The default implementation of CPUClass:get_migration_id() continues to return
cpu_index.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 5 +++-- include/qom/cpu.h | 6 ++++++ qom/cpu.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)exec.c +3
-2@@ -619,12 +619,13 @@ static void cpu_release_index(CPUState *cpu)void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cc->get_migration_id (cpu);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/qom/cpu.h +2
-0@@ -187,6 +187,7 @@ typedef struct CPUClass {bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request);void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +int (*get_migration_id)(CPUState *cpu); } CPUClass;#ifdef HOST_WORDS_BIGENDIAN @@ -273,6 +274,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. +* @migration_id: Use as instance_id argument in cpu
Quoted 1 line
vmstate_registercalls
with this field get_migration_id() callback is redundant. You can drop get_migration_id() and assign value to migration_id in machine specific code /spapr/ppc/x86/.../ before realize is called. That should simplify this patch and its users as well.
Quoted 23 lines
+ * @use_migration_id: Set to enforce the use of
CPUClass.get_migration_id()
+ * overcpu_indexduring vmstate registration.
*
* State of one CPU core or thread.
*/include/qom/cpu.h +0
-0@@ -360,6 +364,8 @@ struct CPUState { (absolute value) offset as small as possible. This reducescode size, especially for hosts without large memory offsets. */
uint32_t tcg_exit_req;include/qom/cpu.h +2
-0+int migration_id; +bool use_migration_id; };QTAILQ_HEAD (CPUTailQ, CPUState);qom/cpu.c +0
-0@@ -326,6 +326,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } }
qom/cpu.c static void cpu_common_realizefn(DeviceState · line 338
Quoted 10 lines
qom/cpu.c +9
-0+static bool cpu_common_get_use_migration_id (Object *obj,Error **errp) +{ +return CPU (obj)->use_migration_id; +} + +static void cpu_common_set_use_migration_id (Object *obj,bool value, +Error **err) +{ +CPU (obj)->use_migration_id = value; +}
It's possible to create dumb property in a more compact way, see DEFINE_PROP_BOOL()
Quoted 34 lines
qom/cpu.c +10
-0static void cpu_common_initfn (Object *obj) {CPUState *cpu =CPU (obj);@@ -336,6 +347,10 @@ static void cpu_common_initfn(Object *obj)qemu_mutex_init (&cpu->work_mutex);QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints); + +object_property_add_bool (obj,"use-migration-id" , + cpu_common_get_use_migration_id, + cpu_common_set_use_migration_id,NULL ); }static void cpu_common_finalize (Object *obj)@@ -348,6 +363,11 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) return cpu->cpu_index; } +static int cpu_common_get_migration_id (CPUState *cpu) +{ +return cpu->cpu_index; +} +static void cpu_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -372,6 +392,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_enter = cpu_common_noop; k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; + k->get_migration_id = cpu_common_get_migration_id; dc->realize = cpu_common_realizefn; dc->unrealize = cpu_common_unrealizefn;/*
Re: [Qemu-devel] [RFC PATCH v1 5/5] cpu, spapr: Use migration_id from pseries-2.7 onwards
In reply to Bharata B RaoQuoted 38 lines · On Wed, 6 Jul 2016 14:29:21 +0530 Bharata B Rao <[email protected]>…
Turn on use-migration-id property. Starting from pseries-2.7, prefer the use of
migration_id(cpu_dt_id) overcpu_indexfor cpu vmstate registration and in XICS code.This allows migration to work when CPU cores are not necessarily unplugged in LIFO order.
TODO: Property use-migration-id is by default turned on, check if this needs to turned off for older machine type versions of all archs.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 5 +++++ qom/cpu.c | 1 + 2 files changed, 6 insertions(+)hw/ppc/spapr.c +5
-0@@ -2501,6 +2501,11 @@ DEFINE_SPAPR_MACHINE(2_7, "2.7", true); .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ .property = "ddw",\ .value = stringify(off),\ + }, \ + { \ + .driver = TYPE_CPU,\ + .property = "use-migration-id",\ + .value = stringify(off),\ }, static void spapr_machine_2_6_instance_options(MachineState *machine)qom/cpu.c +0
-0
qom/cpu.c static void cpu_common_initfn(Object *obj) · line 354
Quoted 4 lines
qom/cpu.c +1
-0@@ -351,6 +351,7 @@ static void cpu_common_initfn(Object *obj)object_property_add_bool (obj,"use-migration-id" , cpu_common_get_use_migration_id, cpu_common_set_use_migration_id,NULL ); +object_property_set_bool (obj, true,"use-migration-id" ,NULL );
this hunk doesn't belong here, it should be in patch that introduces, default FALSE and targets that use it can flip it on and off depending on machine version.
Quoted 3 lines
qom/cpu.c +0
-0}static void cpu_common_finalize (Object *obj)
Re: [Qemu-devel] [RFC PATCH v1 5/5] cpu, spapr: Use migration_id from pseries-2.7 onwards
In reply to Bharata B RaoQuoted 22 lines · On Wed, 6 Jul 2016 14:29:21 +0530 Bharata B Rao <[email protected]>…
Turn on use-migration-id property. Starting from pseries-2.7, prefer the use of
migration_id(cpu_dt_id) overcpu_indexfor cpu vmstate registration and in XICS code.This allows migration to work when CPU cores are not necessarily unplugged in LIFO order.
TODO: Property use-migration-id is by default turned on, check if this needs to turned off for older machine type versions of all archs.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 5 +++++ qom/cpu.c | 1 + 2 files changed, 6 insertions(+)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c DEFINE_SPAPR_MACHINE(2_7, "2.7", true); · line 2508
Quoted 8 lines
hw/ppc/spapr.c +5
-0@@ -2501,6 +2501,11 @@ DEFINE_SPAPR_MACHINE(2_7, "2.7", true); .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ .property = "ddw",\ .value = stringify(off),\ + }, \ + { \ + .driver = TYPE_CPU,\ + .property = "use-migration-id",\ + .value = stringify(off),\
nit,
why not to use "off" directly, stringify looks odd here.
Quoted 15 lines
hw/ppc/spapr.c +0
-0},static void spapr_machine_2_6_instance_options (MachineState *machine)qom/cpu.c +1
-0@@ -351,6 +351,7 @@ static void cpu_common_initfn(Object *obj)object_property_add_bool (obj,"use-migration-id" , cpu_common_get_use_migration_id, cpu_common_set_use_migration_id,NULL ); +object_property_set_bool (obj, true,"use-migration-id" ,NULL ); }static void cpu_common_finalize (Object *obj)
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B RaoQuoted 13 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0
target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 9 lines
target-ppc/translate_init.c +6
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;
Could cpu_dt_id have value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index in possible_cpus on ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
Quoted 16 lines
target-ppc/translate_init.c +6
-0+ }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_id; dc->fw_name = "PowerPC,UNKNOWN"; }
Re: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
In reply to Igor MammedovQuoted 56 lines · Igor Mammedov
Quoted 53 lines · On Wed, 6 Jul 2016 14:29:17 +0530 Bharata B Rao <[email protected]>…
Move
vmstate_register()call tocpu_common_realize(). Introducecpu_common_unrealize()and movevmstate_unregister()to it.Change those archs that implement their own CPU unrealize routine to mandatorily call
CPUClass::unrealize().Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)exec.c +19
-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 ); } + +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); + } +} + +void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu);
Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu) · line 641
Quoted 5 lines
exec.c +5
-0+ } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +}Is there any reason to keep these in
exec.c,
I'd put them inqom/cpu.c
I started with it, had to move vmstate_cpu_common and its pre/post_load routines and one of them called tlb_flush() whose header qom/cpu.c didn't like. So I saved the movement for later.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 2/5] cpu: Introduce CPUState::migration_id
In reply to Igor MammedovQuoted 54 lines · Igor Mammedov
Quoted 51 lines · On Wed, 6 Jul 2016 14:29:18 +0530 Bharata B Rao <[email protected]>…
Add
CPUState::migration_idand use that asinstance_idinvmstate_register()call.Introduce use-migration-id property that allows target machines to optionally switch to using
migration_idinstead ofcpu_index. This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.The default implementation of CPUClass:get_migration_id() continues to return
cpu_index.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 5 +++-- include/qom/cpu.h | 6 ++++++ qom/cpu.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)exec.c +3
-2@@ -619,12 +619,13 @@ static void cpu_release_index(CPUState *cpu)void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cc->get_migration_id (cpu);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/qom/cpu.h +1
-0@@ -187,6 +187,7 @@ typedef struct CPUClass {bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request);void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +int (*get_migration_id)(CPUState *cpu); } CPUClass;
Quoted 11 lines
Quoted 7 lines
include/qom/cpu.h +1
-0#ifdef HOST_WORDS_BIGENDIAN @@ -273,6 +274,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. +* @migration_id: Use as instance_id argument in cpu
vmstate_registercallswith this field
get_migration_id()callback is redundant. You can dropget_migration_id()and assign value tomigration_idin machine specific code /spapr/ppc/x86/.../ before realize is called. That should simplify this patch and its users as well.
Let me give that a try and see how it looks.
Quoted 24 lines
Quoted 24 lines
+ * @use_migration_id: Set to enforce the use of
CPUClass.get_migration_id()
+ * overcpu_indexduring vmstate registration.
*
* State of one CPU core or thread.
*/include/qom/cpu.h +0
-0@@ -360,6 +364,8 @@ struct CPUState { (absolute value) offset as small as possible. This reducescode size, especially for hosts without large memory offsets. */
uint32_t tcg_exit_req;include/qom/cpu.h +2
-0+int migration_id; +bool use_migration_id; };QTAILQ_HEAD (CPUTailQ, CPUState);qom/cpu.c +0
-0@@ -326,6 +326,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } }
Quoted 12 lines
qom/cpu.c static void cpu_common_realizefn(DeviceState *dev, Error **errp) · line 338
Quoted 10 lines
qom/cpu.c +9
-0+static bool cpu_common_get_use_migration_id (Object *obj,Error **errp) +{ +return CPU (obj)->use_migration_id; +} + +static void cpu_common_set_use_migration_id (Object *obj,bool value, +Error **err) +{ +CPU (obj)->use_migration_id = value; +}It's possible to create dumb property in a more compact way, see
DEFINE_PROP_BOOL()
I stated with it and defined dc->props, but then felt it is a bit too much to define a list just for one property. But if that preferable let me switch back to it.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Igor MammedovQuoted 19 lines · Igor Mammedov
Quoted 16 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif }
Quoted 10 lines
target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 6 lines
target-ppc/translate_init.c +6
-0+static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;Could
cpu_dt_idhave value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index inpossible_cpuson ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
For the existing max_cpus limit, 32 bit should be fine, but obviously that is not good and future safe.
I had a brief look at the implementation around possible_cpus in x86, let me see if I can do something similar for generating stable ids for PowerPC. I thought device tree ID would be our stable id, but that being 64 bit and migration code requiring 32 bit value isn't helping :(
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 5/5] cpu, spapr: Use migration_id from pseries-2.7 onwards
In reply to Igor MammedovQuoted 20 lines · Igor Mammedov
Quoted 17 lines · On Wed, 6 Jul 2016 14:29:21 +0530 Bharata B Rao <[email protected]>…
Turn on use-migration-id property. Starting from pseries-2.7, prefer the use of
migration_id(cpu_dt_id) overcpu_indexfor cpu vmstate registration and in XICS code.This allows migration to work when CPU cores are not necessarily unplugged in LIFO order.
TODO: Property use-migration-id is by default turned on, check if this needs to turned off for older machine type versions of all archs.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 5 +++++ qom/cpu.c | 1 + 2 files changed, 6 insertions(+)
Quoted 15 lines
hw/ppc/spapr.c DEFINE_SPAPR_MACHINE(2_7, "2.7", true); · line 2508
Quoted 13 lines
hw/ppc/spapr.c +5
-0@@ -2501,6 +2501,11 @@ DEFINE_SPAPR_MACHINE(2_7, "2.7", true); .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ .property = "ddw",\ .value = stringify(off),\ + }, \ + { \ + .driver = TYPE_CPU,\ + .property = "use-migration-id",\ + .value = stringify(off),\nit,
why not to use "off" directly, stringify looks odd here.
Was just following the previous property "ddw" did, will check if stringify can be dropped.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B RaoQuoted 3 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.
It looks wrong to hijack cpu_dt_id to fix migration.
For pseries-2.7, you need to pass the sum of the index of the core in spapr->cores and the index of the thread in sc->threads.
All other machines just need to pass the index of the cpu in their respective arrays, which happens to be equal to cs->cpu_index.
Quoted 35 lines
Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +12
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id; + }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_id; dc->fw_name ="PowerPC,UNKNOWN" ; }
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B RaoQuoted 31 lines · On Wed, 6 Jul 2016 19:51:01 +0530 Bharata B Rao <[email protected]>…
Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif }Quoted 10 lines
target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 6 lines
target-ppc/translate_init.c +6
-0+static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;Could
cpu_dt_idhave value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index inpossible_cpuson ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
Quoted 3 lines
For the existing
max_cpuslimit, 32 bit should be fine, but obviously that is not good and future safe.
And BTW, cpu_dt_id is actually an int
Quoted 6 lines
I had a brief look at the implementation around
possible_cpusin x86, let me see if I can do something similar for generating stable ids for PowerPC. I thought device tree ID would be our stable id, but that being 64 bit and migration code requiring 32 bit value isn't helping :(
Yes you have stable ids, look at my other answer to this patch.
Quoted 3 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
In reply to Bharata B RaoQuoted 67 lines · On Wed, 6 Jul 2016 19:46:13 +0530 Bharata B Rao <[email protected]>…
Quoted 57 lines · Igor Mammedov
Quoted 54 lines · On Wed, 6 Jul 2016 14:29:17 +0530 Bharata B Rao <[email protected]>…
Move
vmstate_register()call tocpu_common_realize(). Introducecpu_common_unrealize()and movevmstate_unregister()to it.Change those archs that implement their own CPU unrealize routine to mandatorily call
CPUClass::unrealize().Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)exec.c +19
-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 ); } + +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); + } +} + +void cpu_vmstate_unregister (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu);Quoted 8 lines
exec.c static void cpu_release_index(CPUState *cpu) · line 641
Quoted 5 lines
exec.c +5
-0+ } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } +}Is there any reason to keep these in
exec.c,
I'd put them inqom/cpu.c
Quoted 3 lines
I started with it, had to move
vmstate_cpu_commonand its pre/post_load routines and one of them calledtlb_flush()whose headerqom/cpu.cdidn't like. So I saved the movement for later.
ok,
alternatively you can check for use_migration_id in exec.c without moving vmstate_* around.
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 2/5] cpu: Introduce CPUState::migration_id
In reply to Bharata B RaoQuoted 108 lines · On Wed, 6 Jul 2016 19:48:03 +0530 Bharata B Rao <[email protected]>…
Quoted 55 lines · Igor Mammedov
Quoted 52 lines · On Wed, 6 Jul 2016 14:29:18 +0530 Bharata B Rao <[email protected]>…
Add
CPUState::migration_idand use that asinstance_idinvmstate_register()call.Introduce use-migration-id property that allows target machines to optionally switch to using
migration_idinstead ofcpu_index. This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.The default implementation of CPUClass:get_migration_id() continues to return
cpu_index.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 5 +++-- include/qom/cpu.h | 6 ++++++ qom/cpu.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)exec.c +3
-2@@ -619,12 +619,13 @@ static void cpu_release_index(CPUState *cpu)void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cc->get_migration_id (cpu);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/qom/cpu.h +1
-0@@ -187,6 +187,7 @@ typedef struct CPUClass {bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request);void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +int (*get_migration_id)(CPUState *cpu); } CPUClass;Quoted 11 lines
Quoted 7 lines
#ifdef
HOST_WORDS_BIGENDIANinclude/qom/cpu.h +1
-0@@ -273,6 +274,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. +* @migration_id: Use as instance_id argument in cpu
vmstate_registercallswith this field
get_migration_id()callback is redundant. You can dropget_migration_id()and assign value tomigration_idin machine specific code /spapr/ppc/x86/.../ before realize is called. That should simplify this patch and its users as well.Let me give that a try and see how it looks.
Quoted 24 lines
Quoted 24 lines
+ * @use_migration_id: Set to enforce the use of
CPUClass.get_migration_id()
+ * overcpu_indexduring vmstate registration.
*
* State of one CPU core or thread.
*/include/qom/cpu.h +0
-0@@ -360,6 +364,8 @@ struct CPUState { (absolute value) offset as small as possible. Thisreduces code size, especially for hosts without large memory offsets. */
uint32_ttcg_exit_req;include/qom/cpu.h +2
-0+int migration_id; +bool use_migration_id; };QTAILQ_HEAD (CPUTailQ, CPUState);qom/cpu.c +0
-0@@ -326,6 +326,17 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) } }Quoted 13 lines
qom/cpu.c static void cpu_common_realizefn(DeviceState *dev, Error **errp) · line 338
Quoted 11 lines
qom/cpu.c +9
-0+static bool cpu_common_get_use_migration_id (Object *obj,Error **errp) +{ +return CPU (obj)->use_migration_id; +} + +static void cpu_common_set_use_migration_id (Object *obj,bool value, +Error **err) +{ +CPU (obj)->use_migration_id = value; +}It's possible to create dumb property in a more compact way, see
DEFINE_PROP_BOOL()
Quoted 3 lines
I stated with it and defined
dc->props, but then felt it is a bit too much to define a list just for one property. But if that preferable let me switch back to it.
static prop is less code to maintain and not scattered all around file, so it's more preferred if it can do the job.
Quoted 5 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
In reply to Igor MammedovQuoted 70 lines · Igor Mammedov
Quoted 67 lines · On Wed, 6 Jul 2016 19:46:13 +0530 Bharata B Rao <[email protected]>…
Quoted 65 lines · Igor Mammedov
Quoted 49 lines · On Wed, 6 Jul 2016 14:29:17 +0530 Bharata B Rao <[email protected]>…
Move
vmstate_register()call tocpu_common_realize(). Introducecpu_common_unrealize()and movevmstate_unregister()to it.Change those archs that implement their own CPU unrealize routine to mandatorily call
CPUClass::unrealize().Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)exec.c +14
-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 ); } + +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); + } +} + +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); + } +}Is there any reason to keep these in
exec.c,
I'd put them inqom/cpu.c
Quoted 7 lines
Quoted 3 lines
I started with it, had to move
vmstate_cpu_commonand its pre/post_load routines and one of them calledtlb_flush()whose headerqom/cpu.cdidn't like. So I saved the movement for later.ok,
alternatively you can check for
use_migration_idinexec.cwithout moving vmstate_* around.
Ok, just to be clear, you are suggesting that I move back to my first implementation which just consolidated vmstate_* calls and called them from within cpu_exec_init/exit() ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Greg KurzQuoted 6 lines · Greg Kurz
Quoted 3 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.
Quoted 7 lines
It looks wrong to hijack
cpu_dt_idto fix migration.For pseries-2.7, you need to pass the sum of the index of the core in
spapr->coresand the index of the thread insc->threads.All other machines just need to pass the index of the cpu in their respective arrays, which happens to be equal to
cs->cpu_index.
Yes, that is indeed good and simplifies things. Thanks for noting this.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize
In reply to Bharata B RaoQuoted 7 lines · Bharata B Rao
Move
vmstate_register()call tocpu_common_realize(). Introducecpu_common_unrealize()and movevmstate_unregister()to it.Change those archs that implement their own CPU unrealize routine to mandatorily call
CPUClass::unrealize().Signed-off-by Bharata B Rao <[email protected]>
Quoted 195 lines
--- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-)exec.c +33
-20@@ -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 ); } + +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); + } +} + +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)@@ -634,12 +657,18 @@ 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) { -CPUClass *cc =CPU_GET_CLASS (cpu); -#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif @@ -657,18 +686,10 @@ void cpu_exec_exit(CPUState *cpu)#if defined(CONFIG_USER_ONLY )cpu_list_unlock ();#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 +726,7 @@ 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); - }#endif }include/qom/cpu.h +2
-0@@ -870,4 +870,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 +7
-0@@ -310,10 +310,16 @@ static void cpu_common_parse_features(CPUState *cpu, char *features, } } +static void cpu_common_unrealizefn (DeviceState *dev,Error **errp) +{ +cpu_vmstate_unregister (CPU (dev)); +} +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);@@ -367,6 +373,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 +2
-0@@ -163,6 +163,7 @@ struct ppc_segment_page_sizes;/** * PowerPCCPUClass: * @parent_realize: The parent class' realize handler. +* @parent_unrealize: The parent class' unrealize handler. * @parent_reset: The parent class' reset handler. * * A PowerPC CPU model. @@ -173,6 +174,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@@ -9773,10 +9773,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++) {@@ -10364,6 +10366,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;
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 v1 2/5] cpu: Introduce CPUState::migration_id
In reply to Bharata B RaoQuoted 52 lines · Bharata B Rao
Add
CPUState::migration_idand use that asinstance_idinvmstate_register()call.Introduce use-migration-id property that allows target machines to optionally switch to using
migration_idinstead ofcpu_index. This will help allow successful migration in cases where holes are introduced incpu_indexrange after CPU hot removals.The default implementation of CPUClass:get_migration_id() continues to return
cpu_index.Suggested-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>--- exec.c | 5 +++-- include/qom/cpu.h | 6 ++++++ qom/cpu.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-)exec.c +3
-2@@ -619,12 +619,13 @@ static void cpu_release_index(CPUState *cpu)void cpu_vmstate_register (CPUState *cpu) {CPUClass *cc =CPU_GET_CLASS (cpu); +int instance_id = cc->get_migration_id (cpu);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/qom/cpu.h +1
-0@@ -187,6 +187,7 @@ typedef struct CPUClass {bool (*cpu_exec_interrupt)(CPUState *cpu,int interrupt_request);void (*disas_set_info)(CPUState *cpu,disassemble_info *info); +int (*get_migration_id)(CPUState *cpu); } CPUClass;#ifdef HOST_WORDS_BIGENDIAN
include/qom/cpu.h struct qemu_work_item { · line 279
Quoted 6 lines
include/qom/cpu.h +3
-0@@ -273,6 +274,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. +* @migration_id: Use as instance_id argument in cpu vmstate_register calls +* @use_migration_id: Set to enforce the use of CPUClass.get_migration_id() +* over cpu_index during vmstate registration.
I don't really understand the purpose of the use-migration-id bool. Can't you just leave the migration-id as cpu_index by default if you don't want a different migration id. AFAICT this flag is never tested.
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 v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Igor MammedovQuoted 19 lines · Igor Mammedov
Quoted 16 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif }
Quoted 10 lines
target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 6 lines
target-ppc/translate_init.c +6
-0+static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;Could
cpu_dt_idhave value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index inpossible_cpuson ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
No, I'm pretty sure the DT id fits in a 32-bit field in the device tree itself, so it should be safe.
Quoted 18 lines
Quoted 17 lines
target-ppc/translate_init.c +6
-0+ }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_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
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B RaoQuoted 31 lines · Bharata B Rao
Quoted 19 lines · Igor Mammedov
Quoted 16 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif }Quoted 10 lines
target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 6 lines
target-ppc/translate_init.c +6
-0+static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;Could
cpu_dt_idhave value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index inpossible_cpuson ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
Quoted 2 lines
For the existing
max_cpuslimit, 32 bit should be fine, but obviously that is not good and future safe.
I think we should be OK. The hardware IDs these are modelled on are 32-bit - I'm pretty sure #address-cells in /cpus is 1, not 2.
And even with a lot of wastage for alignment gaps of various sorts, we're a *long* way off from supporting 4 billion cpus...
Quoted 9 lines
I had a brief look at the implementation around
possible_cpusin x86, let me see if I can do something similar for generating stable ids for PowerPC. I thought device tree ID would be our stable id, but that being 64 bit and migration code requiring 32 bit value isn't helping :(Regards,
Bharata.
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 v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to Bharata B RaoQuoted 4 lines · Bharata B Rao
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>
This seems ceonceptually wrong. The logic to determine the stable ID is still coming from the CPU code. But kind of the point here is that in most cases the stable IDs really belong to the machine type, not the CPU.
Would it make more sense to just have migration-id be a settable property, which the machine type needs to set between init and realize? (or leave as default == cpu_index).
That way we could have machine version dependent differences without this awkward use_migration_id flag (after all, if it's not always used as the id for migration, 'migration_id' is kind of a bad name...).
Quoted 34 lines
--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +12
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id; + }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_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
Re: [Qemu-devel] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to David GibsonQuoted 32 lines · On Thu, 7 Jul 2016 10:57:28 +1000 David Gibson <[email protected]>…
Quoted 31 lines · Bharata B Rao
Quoted 29 lines · Igor Mammedov
Quoted 13 lines · On Wed, 6 Jul 2016 14:29:19 +0530 Bharata B Rao <[email protected]>…
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +0
-0target-ppc/translate_init.c static gchar *ppc_gdb_arch_name(CPUState *cs) · line 10367
Quoted 9 lines
target-ppc/translate_init.c +6
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id;Could
cpu_dt_idhave value bigger than 32bit int? If yes, it's not safe to do so, that's the reason why I'm going to use index inpossible_cpuson ARM and for the sake of uniformity do the same for x86 (even though it's possible to use 32bit APIC ID).
Quoted 9 lines
Quoted 2 lines
For the existing
max_cpuslimit, 32 bit should be fine, but obviously that is not good and future safe.I think we should be OK. The hardware IDs these are modelled on are 32-bit - I'm pretty sure #address-cells in /cpus is 1, not 2.
And even with a lot of wastage for alignment gaps of various sorts, we're a *long* way off from supporting 4 billion cpus...
Indeed ! Even in the "worst" case, which is running a guest with 1 thread per core on a POWER8 host with full cores (8 HW threads), the current maximum value for cpu_dt_id is 254 * 8 == 2032 :)
Quoted 10 lines
Quoted 9 lines
I had a brief look at the implementation around
possible_cpusin x86, let me see if I can do something similar for generating stable ids for PowerPC. I thought device tree ID would be our stable id, but that being 64 bit and migration code requiring 32 bit value isn't helping :(Regards,
Bharata.
Re: [Qemu-devel] [Qemu-ppc] [RFC PATCH v1 3/5] spapr: Implement CPUClass::get_migration_id() for PowerPC CPUs
In reply to David GibsonQuoted 51 lines · David Gibson
Quoted 4 lines · Bharata B Rao
cpu_indexis used asmigration_idby default. For machine type versions that set use-migration-id property,cpu_dt_itis returned.Signed-off-by Bharata B Rao <[email protected]>This seems ceonceptually wrong. The logic to determine the stable ID is still coming from the CPU code. But kind of the point here is that in most cases the stable IDs really belong to the machine type, not the CPU.
Would it make more sense to just have migration-id be a settable property, which the machine type needs to set between init and realize? (or leave as default ==
cpu_index).That way we could have machine version dependent differences without this awkward
use_migration_idflag (after all, if it's not always used as the id for migration, 'migration_id' is kind of a bad name...).Quoted 32 lines
--- target-ppc/translate_init.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)target-ppc/translate_init.c +12
-0@@ -10359,6 +10359,17 @@ static gchar *ppc_gdb_arch_name(CPUState *cs)#endif } +static int ppc_cpu_get_migration_id (CPUState *cs) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); + +if (cs->use_migration_id) { +return (int ) cpu->cpu_dt_id; + }else { +return cs->cpu_index; + } +} +static void ppc_cpu_class_init (ObjectClass *oc,void *data) {PowerPCCPUClass *pcc =POWERPC_CPU_CLASS (oc);@@ -10412,6 +10423,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_migration_id = ppc_cpu_get_migration_id;
Quoted 3 lines
target-ppc/translate_init.c static void ppc_cpu_class_init(ObjectClass *oc, void *data) · line 10429
Quoted 2 lines
target-ppc/translate_init.c +0
-0dc->fw_name ="PowerPC,UNKNOWN" ; }
Could this be another potential user for the PPCMachineClass solution I was looking at for timebase migration in
https://lists.gnu.org/archive/html/qemu-devel/2016-04/msg01208.html? It seems like a similar problem where machine-level state is needed for migration purposes.
ATB,
Mark.