diff mbox

VARIANT 2: use machine specific callback to pick CPU's migration instance_id

Message ID 1468244550-33910-2-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov July 11, 2016, 1:42 p.m. UTC
it uses less CPU only code but needs per machine glue (pc+q53 for x86)
to keep migration instance_id == cpu_index for old machine
types.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 exec.c            |  8 ++++++--
 hw/i386/pc.c      | 16 ++++++++++++++++
 hw/i386/pc_piix.c |  3 +++
 hw/i386/pc_q35.c  |  3 +++
 include/qom/cpu.h |  1 +
 5 files changed, 29 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 0122ef7..60778ab 100644
--- a/exec.c
+++ b/exec.c
@@ -670,6 +670,7 @@  void cpu_exec_init(CPUState *cpu, Error **errp)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
     Error *local_err = NULL;
+    int migration_id;
 
     cpu->as = NULL;
     cpu->num_ases = 0;
@@ -708,11 +709,14 @@  void cpu_exec_init(CPUState *cpu, Error **errp)
     (void) cc;
     cpu_list_unlock();
 #else
+    migration_id = cc->get_migration_id ?
+        cc->get_migration_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, migration_id, &vmstate_cpu_common, cpu);
     }
     if (cc->vmsd != NULL) {
-        vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu);
+        vmstate_register(NULL, migration_id, cc->vmsd, cpu);
     }
 #endif
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index cd1745e..703791f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -2006,13 +2006,29 @@  static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
     }
 }
 
+static int pc_cpu_get_migration_id(CPUState *cs)
+{
+    CPUArchId apic_id, *found_cpu;
+    CPUClass *cc = CPU_GET_CLASS(cs);
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+
+    apic_id.arch_id = cc->get_arch_id(cs);
+    found_cpu = bsearch(&apic_id, pcms->possible_cpus->cpus,
+        pcms->possible_cpus->len, sizeof(*pcms->possible_cpus->cpus),
+        pc_apic_cmp);
+    assert(found_cpu);
+    return found_cpu - pcms->possible_cpus->cpus;
+}
+
 static void pc_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
     PCMachineClass *pcmc = PC_MACHINE_CLASS(oc);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
     NMIClass *nc = NMI_CLASS(oc);
+    CPUClass *cc = CPU_CLASS(object_class_by_name(TYPE_CPU));
 
+    cc->get_migration_id = pc_cpu_get_migration_id;
     pcmc->get_hotplug_handler = mc->get_hotplug_handler;
     pcmc->pci_enabled = true;
     pcmc->has_acpi_build = true;
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index a07dc81..d834e31 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -452,10 +452,13 @@  DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
 static void pc_i440fx_2_6_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+    CPUClass *cc = CPU_CLASS(object_class_by_name(TYPE_CPU));
+
     pc_i440fx_2_7_machine_options(m);
     m->is_default = 0;
     m->alias = NULL;
     pcmc->legacy_cpu_hotplug = true;
+    cc->get_migration_id = NULL;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
 }
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index c0b9961..24a556a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -304,10 +304,13 @@  DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,
 static void pc_q35_2_6_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+    CPUClass *cc = CPU_CLASS(object_class_by_name(TYPE_CPU));
+
     pc_q35_2_7_machine_options(m);
     m->alias = NULL;
     pcmc->legacy_cpu_hotplug = true;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
+    cc->get_migration_id = NULL;
 }
 
 DEFINE_Q35_MACHINE(v2_6, "pc-q35-2.6", NULL,
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 32f3af3..664573b 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -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