From patchwork Mon Jul 11 13:42:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 646942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rp5sV37Fwz9sBl for ; Mon, 11 Jul 2016 23:43:42 +1000 (AEST) Received: from localhost ([::1]:33766 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMbUq-00023s-66 for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2016 09:43:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMbTx-0000wM-26 for qemu-devel@nongnu.org; Mon, 11 Jul 2016 09:42:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMbTr-0003sA-Kx for qemu-devel@nongnu.org; Mon, 11 Jul 2016 09:42:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMbTr-0003s4-DK for qemu-devel@nongnu.org; Mon, 11 Jul 2016 09:42:39 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6BFC1555A; Mon, 11 Jul 2016 13:42:38 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6BDgZwR031757; Mon, 11 Jul 2016 09:42:37 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 11 Jul 2016 15:42:30 +0200 Message-Id: <1468244550-33910-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1468244550-33910-1-git-send-email-imammedo@redhat.com> References: <20160711033507.GN25522@in.ibm.com> <1468244550-33910-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 11 Jul 2016 13:42:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] VARIANT 2: use machine specific callback to pick CPU's migration instance_id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au, ehabkost@redhat.com, bharata@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Bharata B Rao --- 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