From patchwork Mon Jul 29 02:03:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 262642 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8F5962C00F6 for ; Mon, 29 Jul 2013 12:06:33 +1000 (EST) Received: from localhost ([::1]:47921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3cr1-0005PF-K4 for incoming@patchwork.ozlabs.org; Sun, 28 Jul 2013 22:06:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3cou-0003hz-Jd for qemu-devel@nongnu.org; Sun, 28 Jul 2013 22:04:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3con-0005pS-WE for qemu-devel@nongnu.org; Sun, 28 Jul 2013 22:04:20 -0400 Received: from cantor2.suse.de ([195.135.220.15]:46326 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3con-0005p4-ND for qemu-devel@nongnu.org; Sun, 28 Jul 2013 22:04:13 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 172FAA52D7; Mon, 29 Jul 2013 04:04:13 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Mon, 29 Jul 2013 04:03:58 +0200 Message-Id: <1375063438-3149-3-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1375063438-3149-1-git-send-email-afaerber@suse.de> References: <1375063438-3149-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Jia Liu , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson Subject: [Qemu-devel] [RFC for-next 2/2] cpu: Move VMSTATE_CPU() into TYPE_CPU VMStateDescription X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Assign DeviceClass::vmsd for common CPUState and drop VMSTATE_CPU() from AlphaCPU and OpenRISCCPU. Since we have two types of CPUs, those that register their state through CPUClass::vmsd or CPU_SAVE_VERSION and those that register it through DeviceClass::vmsd, we must keep device code from registering VMState when only the base CPU class has DeviceClass::vmsd set. Signed-off-by: Andreas Färber Tested-by: Jia Liu --- hw/core/qdev.c | 5 +++++ include/qom/cpu.h | 4 ---- qom/cpu.c | 10 ++++++++++ stubs/vmstate.c | 1 + target-alpha/machine.c | 1 - target-openrisc/machine.c | 1 - 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 0430fba..6035f64 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -685,6 +685,11 @@ static void device_register_vmstate(DeviceState *dev, Error **errp) oc = object_get_class(OBJECT(dev)); do { dc = DEVICE_CLASS(oc); + if (oc == object_class_by_name("cpu") && + fields == 0 && subsections == 0) { + /* Old-style CPU with common state as separate VMSD */ + break; + } if (dc->vmsd != NULL) { if (vmsd == NULL) { vmsd = dc->vmsd; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 0d6e95c..e0ad8b6 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -507,11 +507,7 @@ void qemu_init_vcpu(CPUState *cpu); */ void cpu_single_step(CPUState *cpu, int enabled); -#ifdef CONFIG_SOFTMMU extern const struct VMStateDescription vmstate_cpu_common; -#else -#define vmstate_cpu_common vmstate_dummy -#endif #define VMSTATE_CPU() { \ .name = "parent_obj", \ diff --git a/qom/cpu.c b/qom/cpu.c index dbc9fb6..a3e47cb 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -24,6 +24,7 @@ #include "qemu/notify.h" #include "qemu/log.h" #include "sysemu/sysemu.h" +#include "migration/vmstate.h" typedef struct CPUExistsArgs { int64_t id; @@ -250,6 +251,14 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) return cpu->cpu_index; } +static const VMStateDescription vmstate_cpu_device = { + .name = "CPU", + .fields = (VMStateField[]) { + VMSTATE_CPU(), + VMSTATE_END_OF_LIST() + }, +}; + static void cpu_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -268,6 +277,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->gdb_write_register = cpu_common_gdb_write_register; dc->realize = cpu_common_realizefn; dc->no_user = 1; + dc->vmsd = &vmstate_cpu_device; } static const TypeInfo cpu_type_info = { diff --git a/stubs/vmstate.c b/stubs/vmstate.c index 778bc3f..22e2bd4 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -2,6 +2,7 @@ #include "migration/vmstate.h" const VMStateDescription vmstate_dummy = {}; +const VMStateDescription vmstate_cpu_common = {}; int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, diff --git a/target-alpha/machine.c b/target-alpha/machine.c index 889f2fc..e3e75fb 100644 --- a/target-alpha/machine.c +++ b/target-alpha/machine.c @@ -77,7 +77,6 @@ static const VMStateDescription vmstate_env = { }; static VMStateField vmstate_cpu_fields[] = { - VMSTATE_CPU(), VMSTATE_STRUCT(env, AlphaCPU, 1, vmstate_env, CPUAlphaState), VMSTATE_END_OF_LIST() }; diff --git a/target-openrisc/machine.c b/target-openrisc/machine.c index 6f864fe..372b261 100644 --- a/target-openrisc/machine.c +++ b/target-openrisc/machine.c @@ -45,7 +45,6 @@ const VMStateDescription vmstate_openrisc_cpu = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField[]) { - VMSTATE_CPU(), VMSTATE_STRUCT(env, OpenRISCCPU, 1, vmstate_env, CPUOpenRISCState), VMSTATE_END_OF_LIST() }