qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC for-next 2/2] cpu: Move VMSTATE_CPU() into TYPE_CPU VM


From: Andreas Färber
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

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]