diff mbox

[v3,3/7] qom/cpu: move apic vmstate register into x86_cpu_apic_realize

Message ID 3fcc9ccc358fae6b33c25b8687873ce4f8e32a94.1421214155.git.zhugh.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhu Guihua Jan. 14, 2015, 7:27 a.m. UTC
From: Gu Zheng <guz.fnst@cn.fujitsu.com>

move apic vmstate register into x86_cpu_apic_realize, and use
cc->get_arch_id as the instance id to avoid using the auto-id which will
break the migration if we add device not in order.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
---
 hw/intc/apic_common.c           | 3 +--
 include/hw/i386/apic_internal.h | 3 +++
 target-i386/cpu.c               | 8 +++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

Comments

Igor Mammedov Jan. 29, 2015, 2:07 p.m. UTC | #1
On Wed, 14 Jan 2015 15:27:26 +0800
Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:

> From: Gu Zheng <guz.fnst@cn.fujitsu.com>
> 
> move apic vmstate register into x86_cpu_apic_realize, and use
> cc->get_arch_id as the instance id to avoid using the auto-id which will
> break the migration if we add device not in order.
the same migration issue as in previous patch,

but it's easier to workaround it with machine compat switch,
just do the old way for old machine types and new way for new machine type.

> 
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
> Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
> ---
>  hw/intc/apic_common.c           | 3 +--
>  include/hw/i386/apic_internal.h | 3 +++
>  target-i386/cpu.c               | 8 +++++++-
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
> index d9bb188..719f74d 100644
> --- a/hw/intc/apic_common.c
> +++ b/hw/intc/apic_common.c
> @@ -380,7 +380,7 @@ static const VMStateDescription vmstate_apic_common_sipi = {
>      }
>  };
>  
> -static const VMStateDescription vmstate_apic_common = {
> +const VMStateDescription vmstate_apic_common = {
>      .name = "apic",
>      .version_id = 3,
>      .minimum_version_id = 3,
> @@ -434,7 +434,6 @@ static void apic_common_class_init(ObjectClass *klass, void *data)
>      ICCDeviceClass *idc = ICC_DEVICE_CLASS(klass);
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
> -    dc->vmsd = &vmstate_apic_common;
>      dc->reset = apic_reset_common;
>      dc->props = apic_properties_common;
>      idc->realize = apic_common_realize;
> diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
> index dc7a89d..00d29e2 100644
> --- a/include/hw/i386/apic_internal.h
> +++ b/include/hw/i386/apic_internal.h
> @@ -23,6 +23,7 @@
>  #include "exec/memory.h"
>  #include "hw/cpu/icc_bus.h"
>  #include "qemu/timer.h"
> +#include "migration/vmstate.h"
>  
>  /* APIC Local Vector Table */
>  #define APIC_LVT_TIMER                  0
> @@ -138,6 +139,8 @@ typedef struct VAPICState {
>  
>  extern bool apic_report_tpr_access;
>  
> +extern const VMStateDescription vmstate_apic_common;
> +
>  void apic_report_irq_delivered(int delivered);
>  bool apic_next_timer(APICCommonState *s, int64_t current_time);
>  void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index b81ac5c..3406fe8 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2750,10 +2750,16 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
>  
>  static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
>  {
> -    if (cpu->apic_state == NULL) {
> +    DeviceState *apic_state = cpu->apic_state;
> +    CPUClass *cc = CPU_GET_CLASS(CPU(cpu));
> +
> +    if (apic_state == NULL) {
>          return;
>      }
>  
> +    vmstate_register(0, cc->get_arch_id(CPU(cpu)),
> +                     &vmstate_apic_common, apic_state);
> +
>      if (qdev_init(cpu->apic_state)) {
>          error_setg(errp, "APIC device '%s' could not be initialized",
>                     object_get_typename(OBJECT(cpu->apic_state)));
diff mbox

Patch

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index d9bb188..719f74d 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -380,7 +380,7 @@  static const VMStateDescription vmstate_apic_common_sipi = {
     }
 };
 
-static const VMStateDescription vmstate_apic_common = {
+const VMStateDescription vmstate_apic_common = {
     .name = "apic",
     .version_id = 3,
     .minimum_version_id = 3,
@@ -434,7 +434,6 @@  static void apic_common_class_init(ObjectClass *klass, void *data)
     ICCDeviceClass *idc = ICC_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    dc->vmsd = &vmstate_apic_common;
     dc->reset = apic_reset_common;
     dc->props = apic_properties_common;
     idc->realize = apic_common_realize;
diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h
index dc7a89d..00d29e2 100644
--- a/include/hw/i386/apic_internal.h
+++ b/include/hw/i386/apic_internal.h
@@ -23,6 +23,7 @@ 
 #include "exec/memory.h"
 #include "hw/cpu/icc_bus.h"
 #include "qemu/timer.h"
+#include "migration/vmstate.h"
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER                  0
@@ -138,6 +139,8 @@  typedef struct VAPICState {
 
 extern bool apic_report_tpr_access;
 
+extern const VMStateDescription vmstate_apic_common;
+
 void apic_report_irq_delivered(int delivered);
 bool apic_next_timer(APICCommonState *s, int64_t current_time);
 void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b81ac5c..3406fe8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2750,10 +2750,16 @@  static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 {
-    if (cpu->apic_state == NULL) {
+    DeviceState *apic_state = cpu->apic_state;
+    CPUClass *cc = CPU_GET_CLASS(CPU(cpu));
+
+    if (apic_state == NULL) {
         return;
     }
 
+    vmstate_register(0, cc->get_arch_id(CPU(cpu)),
+                     &vmstate_apic_common, apic_state);
+
     if (qdev_init(cpu->apic_state)) {
         error_setg(errp, "APIC device '%s' could not be initialized",
                    object_get_typename(OBJECT(cpu->apic_state)));