diff mbox

[02/35] vmstate: make all architectures export a way to migrate cpu's

Message ID 03886a52f402947d679b559c227acbede52e6c0d.1336128412.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela May 4, 2012, 10:54 a.m. UTC
This makes several changes:
- exports VMStateDescription vmstate_cpu non-static.
- makes sure that every cpu has a vmstate_cpu or cpu_save/load defined
- for the architecture that had nothing, it just register the cpu as unmigratable.
- Depending on CPU_SAVE_VERSION we register old/new migration style
- Add copyrights to the new files

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 exec.c                  |    2 ++
 target-alpha/machine.c  |   12 +-----------
 target-i386/machine.c   |    2 +-
 target-lm32/machine.c   |    2 +-
 target-m68k/machine.c   |   21 +++++++++++++++++++++
 target-s390x/machine.c  |   14 ++++++--------
 target-sh4/machine.c    |   21 +++++++++++++++++++++
 target-xtensa/machine.c |   14 ++++++--------
 vmstate.h               |    2 ++
 9 files changed, 61 insertions(+), 29 deletions(-)

Comments

Andreas Färber May 4, 2012, 4:16 p.m. UTC | #1
Am 04.05.2012 12:54, schrieb Juan Quintela:
> This makes several changes:
> - exports VMStateDescription vmstate_cpu non-static.
> - makes sure that every cpu has a vmstate_cpu or cpu_save/load defined
> - for the architecture that had nothing, it just register the cpu as unmigratable.
> - Depending on CPU_SAVE_VERSION we register old/new migration style
> - Add copyrights to the new files
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  exec.c                  |    2 ++
>  target-alpha/machine.c  |   12 +-----------
>  target-i386/machine.c   |    2 +-
>  target-lm32/machine.c   |    2 +-
>  target-m68k/machine.c   |   21 +++++++++++++++++++++
>  target-s390x/machine.c  |   14 ++++++--------
>  target-sh4/machine.c    |   21 +++++++++++++++++++++
>  target-xtensa/machine.c |   14 ++++++--------
>  vmstate.h               |    2 ++
>  9 files changed, 61 insertions(+), 29 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index cba333f..85f0d61 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -722,6 +722,8 @@ void cpu_exec_init(CPUArchState *env)
>  #if defined(CPU_SAVE_VERSION)
>      register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
>                      cpu_save, cpu_load, env);
> +#else
> +    vmstate_register(NULL, cpu_index, &vmstate_cpu, env);
>  #endif
>  #endif
>  }

We have QOM CPUState now, so please add a vmsd field to CPUClass instead
of exporting global vmstate_cpu variables. It then matches what we do
for former qdev devices and will in the future allow to compile this
code only twice.

Andreas
Andreas Färber May 7, 2012, 5:14 p.m. UTC | #2
Am 04.05.2012 18:16, schrieb Andreas Färber:
> Am 04.05.2012 12:54, schrieb Juan Quintela:
>> This makes several changes:
>> - exports VMStateDescription vmstate_cpu non-static.
>> - makes sure that every cpu has a vmstate_cpu or cpu_save/load defined
>> - for the architecture that had nothing, it just register the cpu as unmigratable.
>> - Depending on CPU_SAVE_VERSION we register old/new migration style
>> - Add copyrights to the new files
>>
>> Signed-off-by: Juan Quintela <quintela@redhat.com>
>> ---
>>  exec.c                  |    2 ++
>>  target-alpha/machine.c  |   12 +-----------
>>  target-i386/machine.c   |    2 +-
>>  target-lm32/machine.c   |    2 +-
>>  target-m68k/machine.c   |   21 +++++++++++++++++++++
>>  target-s390x/machine.c  |   14 ++++++--------
>>  target-sh4/machine.c    |   21 +++++++++++++++++++++
>>  target-xtensa/machine.c |   14 ++++++--------
>>  vmstate.h               |    2 ++
>>  9 files changed, 61 insertions(+), 29 deletions(-)
[...]
> We have QOM CPUState now, so please add a vmsd field to CPUClass instead
> of exporting global vmstate_cpu variables.

Thinking more about this, I see that we will need to assign it in
cpu.c:xxx_class_init() (translate_init.c for ppc) as opposed to machine.c.

The declaration still shouldn't go into vmstate.h so that it remains a
target-local decision how to model this (think CPU subclasses).

I'd hate to #include "machine.c" in cpu.c.
Having the declaration in cpu.h is the least intrusive solution I see.
Moving the code into cpu.c would match qdev but would bloat the files.

What do you think?

> It then matches what we do
> for former qdev devices and will in the future allow to compile this
> code only twice.

BTW the easiest way to address my comment on 01/35 would be to simply
squash the two commits. :)

Andreas
diff mbox

Patch

diff --git a/exec.c b/exec.c
index cba333f..85f0d61 100644
--- a/exec.c
+++ b/exec.c
@@ -722,6 +722,8 @@  void cpu_exec_init(CPUArchState *env)
 #if defined(CPU_SAVE_VERSION)
     register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
+#else
+    vmstate_register(NULL, cpu_index, &vmstate_cpu, env);
 #endif
 #endif
 }
diff --git a/target-alpha/machine.c b/target-alpha/machine.c
index 1c9edd1..8b3b42e 100644
--- a/target-alpha/machine.c
+++ b/target-alpha/machine.c
@@ -68,20 +68,10 @@  static VMStateField vmstate_cpu_fields[] = {
     VMSTATE_END_OF_LIST()
 };

-static const VMStateDescription vmstate_cpu = {
+const VMStateDescription vmstate_cpu = {
     .name = "cpu",
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
     .fields = vmstate_cpu_fields,
 };
-
-void cpu_save(QEMUFile *f, void *opaque)
-{
-    vmstate_save_state(f, &vmstate_cpu, opaque);
-}
-
-int cpu_load(QEMUFile *f, void *opaque, int version_id)
-{
-    return vmstate_load_state(f, &vmstate_cpu, opaque, version_id);
-}
diff --git a/target-i386/machine.c b/target-i386/machine.c
index a8be058..fc37738 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -346,7 +346,7 @@  static const VMStateDescription vmstate_msr_ia32_misc_enable = {
     }
 };

-static const VMStateDescription vmstate_cpu = {
+const VMStateDescription vmstate_cpu = {
     .name = "cpu",
     .version_id = CPU_SAVE_VERSION,
     .minimum_version_id = 3,
diff --git a/target-lm32/machine.c b/target-lm32/machine.c
index 6802e81..ed71bc4 100644
--- a/target-lm32/machine.c
+++ b/target-lm32/machine.c
@@ -1,7 +1,7 @@ 
 #include "hw/hw.h"
 #include "hw/boards.h"

-static const VMStateDescription vmstate_cpu = {
+const VMStateDescription vmstate_cpu = {
     .name = "cpu",
     .version_id = CPU_SAVE_VERSION,
     .minimum_version_id = 1,
diff --git a/target-m68k/machine.c b/target-m68k/machine.c
index e69de29..7c89d4f 100644
--- a/target-m68k/machine.c
+++ b/target-m68k/machine.c
@@ -0,0 +1,21 @@ 
+/*
+ * Migration support for m68k cpus
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * Author(s):
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#include "hw/hw.h"
+
+/* To make this architecture migratable, we need to define cpu state
+   here.  Other things need to be done elsewhere */
+
+const VMStateDescription vmstate_cpu = {
+    .name = "cpu",
+    .unmigratable = 1,
+};
diff --git a/target-s390x/machine.c b/target-s390x/machine.c
index 3e79be6..5a7b219 100644
--- a/target-s390x/machine.c
+++ b/target-s390x/machine.c
@@ -18,13 +18,11 @@ 
  */

 #include "hw/hw.h"
-#include "hw/boards.h"

-void cpu_save(QEMUFile *f, void *opaque)
-{
-}
+/* To make this architecture migratable, we need to define cpu state
+   here.  Other things need to be done elsewhere */

-int cpu_load(QEMUFile *f, void *opaque, int version_id)
-{
-    return 0;
-}
+const VMStateDescription vmstate_cpu = {
+    .name = "cpu",
+    .unmigratable = 1,
+};
diff --git a/target-sh4/machine.c b/target-sh4/machine.c
index e69de29..b97355d 100644
--- a/target-sh4/machine.c
+++ b/target-sh4/machine.c
@@ -0,0 +1,21 @@ 
+/*
+ * Migration support for sh4 cpus
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * Author(s):
+ *  Juan Quintela <quintela@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ */
+
+#include "hw/hw.h"
+
+/* To make this architecture migratable, we need to define cpu state
+   here.  Other things need to be done elsewhere */
+
+const VMStateDescription vmstate_cpu = {
+    .name = "cpu",
+    .unmigratable = 1,
+};
diff --git a/target-xtensa/machine.c b/target-xtensa/machine.c
index ddeffb2..3f98330 100644
--- a/target-xtensa/machine.c
+++ b/target-xtensa/machine.c
@@ -26,13 +26,11 @@ 
  */

 #include "hw/hw.h"
-#include "hw/boards.h"

-void cpu_save(QEMUFile *f, void *opaque)
-{
-}
+/* To make this architecture migratable, we need to define cpu state
+   here.  Other things need to be done elsewhere */

-int cpu_load(QEMUFile *f, void *opaque, int version_id)
-{
-    return 0;
-}
+const VMStateDescription vmstate_cpu = {
+    .name = "cpu",
+    .unmigratable = 1,
+};
diff --git a/vmstate.h b/vmstate.h
index 82d97ae..1a4a60b 100644
--- a/vmstate.h
+++ b/vmstate.h
@@ -134,6 +134,8 @@  extern const VMStateInfo vmstate_info_timer;
 extern const VMStateInfo vmstate_info_buffer;
 extern const VMStateInfo vmstate_info_unused_buffer;

+extern const VMStateDescription vmstate_cpu;
+
 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)