From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YToiR-000818-Ay for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:38:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YToiL-0008Ez-GO for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:38:43 -0500 Received: from [59.151.112.132] (port=19679 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YToiL-0008Ec-2n for qemu-devel@nongnu.org; Fri, 06 Mar 2015 04:38:37 -0500 Message-ID: <54F973FF.3060501@cn.fujitsu.com> Date: Fri, 6 Mar 2015 17:31:43 +0800 From: Chen Fan MIME-Version: 1.0 References: <8dd683d6589f7bd52bd7250df87a547cf1932186.1423821709.git.zhugh.fnst@cn.fujitsu.com> <20150306095352.28200482@nial.brq.redhat.com> In-Reply-To: <20150306095352.28200482@nial.brq.redhat.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v4 05/10] qom/cpu: move register_vmstate to common CPUClass.realizefn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov , Zhu Guihua Cc: qemu-devel@nongnu.org, tangchen@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, guz.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, afaerber@suse.de On 03/06/2015 04:53 PM, Igor Mammedov wrote: > On Fri, 13 Feb 2015 18:25:28 +0800 > Zhu Guihua wrote: > >> From: Gu Zheng >> >> Move cpu vmstate register from cpu_exec_init into cpu_common_realizefn, >> and use cc->get_arch_id as the instance id that suggested by Igor to >> fix the migration issue. >> >> Signed-off-by: Gu Zheng >> Signed-off-by: Zhu Guihua >> --- >> exec.c | 25 ++++++++++++++++++------- >> include/qom/cpu.h | 2 ++ >> qom/cpu.c | 4 ++++ >> 3 files changed, 24 insertions(+), 7 deletions(-) >> >> diff --git a/exec.c b/exec.c >> index 6dff7bc..8361591 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -513,10 +513,26 @@ 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) + max_cpus; > Why do you add max_cpus here? Adding max_cpus is to avoid cpu_index equals comat_index which would cause migration fails, this reason is that find_se() always compares instance_id with se->instance_id or se->alias_id when do migration. Thanks, Chen > >> + int compat_index = cc->get_compat_arch_id(cpu); >> + >> + if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { >> + vmstate_register_with_alias_id(NULL, cpu_index, &vmstate_cpu_common, >> + cpu, compat_index, 3); >> + } >> + >> + if (cc->vmsd != NULL) { >> + vmstate_register_with_alias_id(NULL, cpu_index, cc->vmsd, >> + cpu, compat_index, 3); >> + } >> +} >> + >> void cpu_exec_init(CPUArchState *env) >> { >> CPUState *cpu = ENV_GET_CPU(env); >> - CPUClass *cc = CPU_GET_CLASS(cpu); >> CPUState *some_cpu; >> int cpu_index; >> >> @@ -539,18 +555,13 @@ 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) >> + CPUClass *cc = CPU_GET_CLASS(cpu); >> 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(CONFIG_USER_ONLY) >> diff --git a/include/qom/cpu.h b/include/qom/cpu.h >> index 2e68dd2..d0a50e2 100644 >> --- a/include/qom/cpu.h >> +++ b/include/qom/cpu.h >> @@ -565,6 +565,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 83d7766..8e37045 100644 >> --- a/qom/cpu.c >> +++ b/qom/cpu.c >> @@ -302,6 +302,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) >> { >> CPUState *cpu = CPU(dev); >> >> +#if !defined(CONFIG_USER_ONLY) >> + cpu_vmstate_register(cpu); >> +#endif >> + >> if (dev->hotplugged) { >> cpu_synchronize_post_init(cpu); >> cpu_resume(cpu); > . >