From patchwork Wed Jul 6 08:59:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 9215825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1C1D60572 for ; Wed, 6 Jul 2016 09:04:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87671287A8 for ; Wed, 6 Jul 2016 09:04:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B63D287AA; Wed, 6 Jul 2016 09:04:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D93CC287A8 for ; Wed, 6 Jul 2016 09:04:15 +0000 (UTC) Received: from localhost ([::1]:60323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKikg-00040O-Oa for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 05:04:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKigI-0007XW-SB for qemu-devel@nongnu.org; Wed, 06 Jul 2016 04:59:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKigE-00054h-NN for qemu-devel@nongnu.org; Wed, 06 Jul 2016 04:59:41 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKigE-00054W-FA for qemu-devel@nongnu.org; Wed, 06 Jul 2016 04:59:38 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u668wxvW077004 for ; Wed, 6 Jul 2016 04:59:37 -0400 Received: from e28smtp08.in.ibm.com (e28smtp08.in.ibm.com [125.16.236.8]) by mx0a-001b2d01.pphosted.com with ESMTP id 240ndwy94u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 06 Jul 2016 04:59:37 -0400 Received: from localhost by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jul 2016 14:29:34 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp08.in.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Jul 2016 14:29:33 +0530 X-IBM-Helo: d28dlp03.in.ibm.com X-IBM-MailFrom: bharata@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d28relay10.in.ibm.com (d28relay10.in.ibm.com [9.184.220.161]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 0D54F125805F; Wed, 6 Jul 2016 14:32:18 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay10.in.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u668xWdr7274556; Wed, 6 Jul 2016 14:29:32 +0530 Received: from d28av05.in.ibm.com (localhost [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u668xTE2002019; Wed, 6 Jul 2016 14:29:31 +0530 Received: from bharata.in.ibm.com ([9.79.190.110]) by d28av05.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u668xNcY001702; Wed, 6 Jul 2016 14:29:27 +0530 From: Bharata B Rao To: qemu-devel@nongnu.org Date: Wed, 6 Jul 2016 14:29:17 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467795561-1007-1-git-send-email-bharata@linux.vnet.ibm.com> References: <1467795561-1007-1-git-send-email-bharata@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16070608-0056-0000-0000-000002893CC0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16070608-0057-0000-0000-00000EA4D701 Message-Id: <1467795561-1007-2-git-send-email-bharata@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-07-06_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607060081 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [RFC PATCH v1 1/5] cpu, target-ppc: Move cpu_vmstate_[un]register calls to cpu_common_[un]realize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nikunj@linux.vnet.ibm.com, Bharata B Rao , groug@kaod.org, qemu-ppc@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Move vmstate_register() call to cpu_common_realize(). Introduce cpu_common_unrealize() and move vmstate_unregister() to it. Change those archs that implement their own CPU unrealize routine to mandatorily call CPUClass::unrealize(). Signed-off-by: Bharata B Rao Reviewed-by: David Gibson --- exec.c | 53 ++++++++++++++++++++++++++++----------------- include/qom/cpu.h | 2 ++ qom/cpu.c | 7 ++++++ target-ppc/cpu-qom.h | 2 ++ target-ppc/translate_init.c | 3 +++ 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/exec.c b/exec.c index 0122ef7..fb73910 100644 --- a/exec.c +++ b/exec.c @@ -594,9 +594,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx) /* Return the AddressSpace corresponding to the specified index */ return cpu->cpu_ases[asidx].as; } -#endif -#ifndef CONFIG_USER_ONLY static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS); static int cpu_get_free_index(Error **errp) @@ -617,6 +615,31 @@ static void cpu_release_index(CPUState *cpu) { bitmap_clear(cpu_index_map, cpu->cpu_index, 1); } + +void cpu_vmstate_register(CPUState *cpu) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + + if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { + vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); + } + if (cc->vmsd != NULL) { + vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); + } +} + +void cpu_vmstate_unregister(CPUState *cpu) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + + if (cc->vmsd != NULL) { + vmstate_unregister(NULL, cc->vmsd, cpu); + } + if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { + vmstate_unregister(NULL, &vmstate_cpu_common, cpu); + } +} + #else static int cpu_get_free_index(Error **errp) @@ -634,12 +657,18 @@ static void cpu_release_index(CPUState *cpu) { return; } + +void cpu_vmstate_register(CPUState *cpu) +{ +} + +void cpu_vmstate_unregister(CPUState *cpu) +{ +} #endif void cpu_exec_exit(CPUState *cpu) { - CPUClass *cc = CPU_GET_CLASS(cpu); - #if defined(CONFIG_USER_ONLY) cpu_list_lock(); #endif @@ -657,18 +686,10 @@ void cpu_exec_exit(CPUState *cpu) #if defined(CONFIG_USER_ONLY) cpu_list_unlock(); #endif - - if (cc->vmsd != NULL) { - vmstate_unregister(NULL, cc->vmsd, cpu); - } - if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { - vmstate_unregister(NULL, &vmstate_cpu_common, cpu); - } } void cpu_exec_init(CPUState *cpu, Error **errp) { - CPUClass *cc = CPU_GET_CLASS(cpu); Error *local_err = NULL; cpu->as = NULL; @@ -705,15 +726,7 @@ void cpu_exec_init(CPUState *cpu, Error **errp) } QTAILQ_INSERT_TAIL(&cpus, cpu, node); #if defined(CONFIG_USER_ONLY) - (void) cc; cpu_list_unlock(); -#else - if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); - } - if (cc->vmsd != NULL) { - vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); - } #endif } diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 32f3af3..29ccf5c 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -870,4 +870,6 @@ extern const struct VMStateDescription vmstate_cpu_common; .offset = 0, \ } +void cpu_vmstate_register(CPUState *cpu); +void cpu_vmstate_unregister(CPUState *cpu); #endif diff --git a/qom/cpu.c b/qom/cpu.c index 751e992..488ecc6 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -310,10 +310,16 @@ static void cpu_common_parse_features(CPUState *cpu, char *features, } } +static void cpu_common_unrealizefn(DeviceState *dev, Error **errp) +{ + cpu_vmstate_unregister(CPU(dev)); +} + 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); cpu_resume(cpu); @@ -367,6 +373,7 @@ static void cpu_class_init(ObjectClass *klass, void *data) k->cpu_exec_exit = cpu_common_noop; k->cpu_exec_interrupt = cpu_common_exec_interrupt; dc->realize = cpu_common_realizefn; + dc->unrealize = cpu_common_unrealizefn; /* * Reason: CPUs still need special care by board code: wiring up * IRQs, adding reset handlers, halting non-first CPUs, ... diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h index 2864105..6ec2fca 100644 --- a/target-ppc/cpu-qom.h +++ b/target-ppc/cpu-qom.h @@ -163,6 +163,7 @@ struct ppc_segment_page_sizes; /** * PowerPCCPUClass: * @parent_realize: The parent class' realize handler. + * @parent_unrealize: The parent class' unrealize handler. * @parent_reset: The parent class' reset handler. * * A PowerPC CPU model. @@ -173,6 +174,7 @@ typedef struct PowerPCCPUClass { /*< public >*/ DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; void (*parent_reset)(CPUState *cpu); uint32_t pvr; diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 8f257fb..efd6b88 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -9773,10 +9773,12 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) { PowerPCCPU *cpu = POWERPC_CPU(dev); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); CPUPPCState *env = &cpu->env; opc_handler_t **table; int i, j; + pcc->parent_unrealize(dev, errp); cpu_exec_exit(CPU(dev)); for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) { @@ -10364,6 +10366,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); pcc->parent_realize = dc->realize; + pcc->parent_unrealize = dc->unrealize; pcc->pvr_match = ppc_pvr_match_default; pcc->interrupts_big_endian = ppc_cpu_interrupts_big_endian_always; dc->realize = ppc_cpu_realizefn;