qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: bharata@linux.vnet.ibm.com, david@gibson.dropbear.id.au,
	ehabkost@redhat.com, marcel@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH] VARIANT 2: use machine specific callback to pick CPU's migration instance_id
Date: Mon, 11 Jul 2016 15:42:30 +0200	[thread overview]
Message-ID: <1468244550-33910-2-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1468244550-33910-1-git-send-email-imammedo@redhat.com>

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 --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
-- 
1.8.3.1

  reply	other threads:[~2016-07-11 13:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-07 14:50 [Qemu-devel] [RFC PATCH v2 0/5] sPAPR: Fix migration when CPUs are removed in random order Bharata B Rao
2016-07-07 14:50 ` [Qemu-devel] [RFC PATCH v2 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize Bharata B Rao
2016-07-07 14:50 ` [Qemu-devel] [RFC PATCH v2 2/5] cpu: Introduce CPUState::stable_cpu_id Bharata B Rao
2016-07-07 17:52   ` Greg Kurz
2016-07-08  5:21     ` David Gibson
2016-07-08  5:19   ` David Gibson
2016-07-08 11:11     ` Igor Mammedov
2016-07-11  3:22       ` David Gibson
2016-07-11  3:35         ` Bharata B Rao
2016-07-11  7:42           ` Igor Mammedov
2016-07-11 13:42           ` [Qemu-devel] [PATCH] VARIANT 1: reuse device compat logic to pick preffered CPU's migration instance_id Igor Mammedov
2016-07-11 13:42             ` Igor Mammedov [this message]
2016-07-11 14:15             ` Paolo Bonzini
2016-07-12  5:07             ` David Gibson
2016-07-12  8:11               ` Igor Mammedov
2016-07-13  1:39                 ` David Gibson
2016-07-12  7:06             ` Bharata B Rao
2016-07-12  8:21               ` Igor Mammedov
2016-07-12 11:08               ` [Qemu-devel] [PATCH v2 1/2] cpu: add migration_id to allow board to provide " Igor Mammedov
2016-07-12 11:08                 ` [Qemu-devel] [PATCH v2 2/2] pc: fix migration failure after cpu hot-unplung Igor Mammedov
2016-07-11  7:58         ` [Qemu-devel] [RFC PATCH v2 2/5] cpu: Introduce CPUState::stable_cpu_id Igor Mammedov
2016-07-12  5:09           ` David Gibson
2016-07-07 14:50 ` [Qemu-devel] [RFC PATCH v2 3/5] spapr: Set stable_cpu_id for threads of CPU cores Bharata B Rao
2016-07-07 16:11   ` Greg Kurz
2016-07-08  5:25     ` David Gibson
2016-07-08  7:46       ` Greg Kurz
2016-07-08  7:59         ` David Gibson
2016-07-08 15:24           ` Greg Kurz
2016-07-11  3:23             ` David Gibson
2016-07-08  5:24   ` David Gibson
2016-07-08  6:41     ` Bharata B Rao
2016-07-08  7:39       ` David Gibson
2016-07-08 10:59         ` Igor Mammedov
2016-07-11  3:12           ` Bharata B Rao
2016-07-11  3:26           ` David Gibson
2016-07-11  8:15             ` Igor Mammedov
2016-07-12  4:41               ` David Gibson
2016-07-07 14:50 ` [Qemu-devel] [RFC PATCH v2 4/5] xics: Use stable_cpu_id instead of cpu_index in XICS code Bharata B Rao
2016-07-08  5:32   ` David Gibson
2016-07-07 14:50 ` [Qemu-devel] [RFC PATCH v2 5/5] spapr: Enable the use of stable_cpu_id from pseries-2.7 onwards Bharata B Rao
2016-07-07 16:04 ` [Qemu-devel] [RFC PATCH v2 0/5] sPAPR: Fix migration when CPUs are removed in random order Greg Kurz
2016-07-08  5:34   ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468244550-33910-2-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=ehabkost@redhat.com \
    --cc=marcel@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).