qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Jia Liu" <proljc@gmail.com>, "Andreas Färber" <afaerber@suse.de>,
	"Richard Henderson" <rth@twiddle.net>
Subject: [Qemu-devel] [RFC for-next 2/2] cpu: Move VMSTATE_CPU() into TYPE_CPU VMStateDescription
Date: Mon, 29 Jul 2013 04:03:58 +0200	[thread overview]
Message-ID: <1375063438-3149-3-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1375063438-3149-1-git-send-email-afaerber@suse.de>

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 <afaerber@suse.de>
---
 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()
     }
-- 
1.8.1.4

  parent reply	other threads:[~2013-07-29  2:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29  2:03 [Qemu-devel] [RFC for-next 0/2] QOM VMStateDescription remix Andreas Färber
2013-07-29  2:03 ` [Qemu-devel] [RFC for-next 1/2] qdev: Construct VMStateDescription from type hierarchy Andreas Färber
2013-07-29  2:03 ` Andreas Färber [this message]
2013-07-29  4:30   ` [Qemu-devel] [RFC for-next 2/2] cpu: Move VMSTATE_CPU() into TYPE_CPU VMStateDescription Jia Liu
2013-09-02 11:28 ` [Qemu-devel] [RFC for-next 0/2] QOM VMStateDescription remix Andreas Färber
2013-09-02 11:41 ` Michael S. Tsirkin
2014-02-07 21:28   ` Andreas Färber
2014-02-07 21:39     ` Peter Maydell

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=1375063438-3149-3-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=proljc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).