[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 02/10] qom/cpu: move register_vmstate to common
From: |
Gu Zheng |
Subject: |
[Qemu-devel] [RFC PATCH 02/10] qom/cpu: move register_vmstate to common CPUClass.realizefn |
Date: |
Thu, 7 Aug 2014 12:54:00 +0800 |
Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn,
apic vmstate register into x86_cpu_apic_realize. And use the
cc->get_arch_id as the instance id that suggested by Igor to
fix the migration issue.
Signed-off-by: Gu Zheng <address@hidden>
---
exec.c | 32 +++++++++++++++++++-------------
hw/intc/apic_common.c | 3 +--
include/hw/i386/apic_internal.h | 2 ++
include/qom/cpu.h | 2 ++
qom/cpu.c | 2 ++
target-i386/cpu.c | 10 ++++++++--
6 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/exec.c b/exec.c
index 765bd94..3c88630 100644
--- a/exec.c
+++ b/exec.c
@@ -473,10 +473,28 @@ void tcg_cpu_address_space_init(CPUState *cpu,
AddressSpace *as)
}
#endif
+void cpu_vmstate_register(CPUState *cpu)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ int cpu_index = cc->get_arch_id(cpu);
+
+ if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
+ vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
+ }
+#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
+ register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
+ cpu_save, cpu_load, cpu->env_ptr);
+ assert(cc->vmsd == NULL);
+ assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
+#endif
+ if (cc->vmsd != NULL) {
+ vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
+ }
+}
+
void cpu_exec_init(CPUArchState *env)
{
CPUState *cpu = ENV_GET_CPU(env);
- CPUClass *cc = CPU_GET_CLASS(cpu);
CPUState *some_cpu;
int cpu_index;
@@ -499,18 +517,6 @@ void cpu_exec_init(CPUArchState *env)
#if defined(CONFIG_USER_ONLY)
cpu_list_unlock();
#endif
- if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
- vmstate_register(NULL, cpu_index, &vmstate_cpu_common, cpu);
- }
-#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
- register_savevm(NULL, "cpu", cpu_index, CPU_SAVE_VERSION,
- cpu_save, cpu_load, env);
- assert(cc->vmsd == NULL);
- assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-#endif
- if (cc->vmsd != NULL) {
- vmstate_register(NULL, cpu_index, cc->vmsd, cpu);
- }
}
#if defined(TARGET_HAS_ICE)
diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ce3d903..029f67d 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -345,7 +345,7 @@ static int apic_dispatch_post_load(void *opaque, int
version_id)
return 0;
}
-static const VMStateDescription vmstate_apic_common = {
+const VMStateDescription vmstate_apic_common = {
.name = "apic",
.version_id = 3,
.minimum_version_id = 3,
@@ -391,7 +391,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 83e2a42..2c91609 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
@@ -136,6 +137,7 @@ typedef struct VAPICState {
} QEMU_PACKED 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);
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 1aafbf5..bc32c9a 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -549,6 +549,8 @@ void cpu_interrupt(CPUState *cpu, int mask);
#endif /* USER_ONLY */
+void cpu_vmstate_register(CPUState *cpu);
+
#ifdef CONFIG_SOFTMMU
static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
bool is_write, bool is_exec,
diff --git a/qom/cpu.c b/qom/cpu.c
index b32dd0a..bf16590 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -301,6 +301,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error
**errp)
{
CPUState *cpu = CPU(dev);
+ cpu_vmstate_register(cpu);
+
if (dev->hotplugged) {
cpu_synchronize_post_init(cpu);
notifier_list_notify(&cpu_added_notifiers, dev);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6d008ab..d381644 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2662,11 +2662,17 @@ 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;
}
- if (qdev_init(cpu->apic_state)) {
+ vmstate_register(0, cc->get_arch_id(CPU(cpu)),
+ &vmstate_apic_common, apic_state);
+
+ if (qdev_init(apic_state)) {
error_setg(errp, "APIC device '%s' could not be initialized",
object_get_typename(OBJECT(cpu->apic_state)));
return;
--
1.7.7
- [Qemu-devel] [RFC PATCH 00/10] cpu: add device_add foo-x86_64-cpu and i386 cpu hot remove support, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 01/10] cpu: introduce CpuTopoInfo structure for argument simplification, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 02/10] qom/cpu: move register_vmstate to common CPUClass.realizefn,
Gu Zheng <=
- [Qemu-devel] [RFC PATCH 03/10] cpu: add device_add foo-x86_64-cpu support, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 04/10] x86: add x86_cpu_unrealizefn() for cpu apic remove, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 05/10] i386: add cpu device_del support, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 06/10] qom cpu: rename variable 'cpu_added_notifier' to 'cpu_hotplug_notifier', Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 07/10] qom cpu: add UNPLUG cpu notify support, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 08/10] i386: implement pc interface cpu_common_unrealizefn() in qom/cpu.c, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 09/10] cpu hotplug: implement function cpu_status_write() for vcpu ejection, Gu Zheng, 2014/08/07
- [Qemu-devel] [RFC PATCH 10/10] cpus: reclaim allocated vCPU objects, Gu Zheng, 2014/08/07