From patchwork Wed Jun 29 20:51:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9206201 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 9DBF860757 for ; Wed, 29 Jun 2016 20:56:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A4CE28590 for ; Wed, 29 Jun 2016 20:56:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AE2A28662; Wed, 29 Jun 2016 20:56:21 +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 B552C28590 for ; Wed, 29 Jun 2016 20:56:20 +0000 (UTC) Received: from localhost ([::1]:45744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMWx-00049S-GJ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 29 Jun 2016 16:56:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMSH-0000Lp-Hj for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:51:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bIMSB-0002Fy-EM for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:51:28 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48425 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIMSB-0002Fq-A3 for qemu-devel@nongnu.org; Wed, 29 Jun 2016 16:51:23 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5TKhSrw061164 for ; Wed, 29 Jun 2016 16:51:22 -0400 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 23utc9j27e-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 29 Jun 2016 16:51:22 -0400 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Jun 2016 14:51:22 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Jun 2016 14:51:18 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 600B43E40030; Wed, 29 Jun 2016 14:51:18 -0600 (MDT) Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5TKpI8645809904; Wed, 29 Jun 2016 13:51:18 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A3226A041; Wed, 29 Jun 2016 14:51:18 -0600 (MDT) Received: from bahia.lan (unknown [9.164.167.94]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 1F3FB6A03D; Wed, 29 Jun 2016 14:51:12 -0600 (MDT) From: Greg Kurz To: David Gibson Date: Wed, 29 Jun 2016 22:51:11 +0200 In-Reply-To: <146723340662.9665.6413150884317978000.stgit@bahia.lan> References: <146723340662.9665.6413150884317978000.stgit@bahia.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062920-0028-0000-0000-000005113758 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062920-0029-0000-0000-00002D1C36EA Message-Id: <146723347123.9665.9743107689258500061.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-29_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606290192 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH 5/8] exec: move cpu_index init and exit to their own function 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: Peter Crosthwaite , qemu-devel@nongnu.org, Alexander Graf , qemu-ppc@nongnu.org, Cedric Le Goater , bharata@linux.vnet.ibm.com, Scott Wood , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch splits the cpu_index bits from the rest of the cpu_exec init and exit code, so that they may be called separately. The goal is to be able to initialize cpu_index during cpu initialization and keep the rest for cpu realization. The cpu_exec_init() and cpu_exec_exit() functions are kept since most callers will stick to the current behaviour. Signed-off-by: Greg Kurz --- exec.c | 77 +++++++++++++++++++++++++++++++++++------------ include/exec/exec-all.h | 2 + include/qom/cpu.h | 2 + 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/exec.c b/exec.c index a528a1e6bbf6..a9b3b4c2ca45 100644 --- a/exec.c +++ b/exec.c @@ -635,26 +635,17 @@ static void cpu_release_index(CPUState *cpu) return; } #endif -void cpu_exec_exit(CPUState *cpu) +void cpu_exec_unrealize(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); #if defined(CONFIG_USER_ONLY) cpu_list_lock(); #endif - if (cpu->cpu_index == -1) { - /* cpu_index was never allocated by this @cpu or was already freed. */ -#if defined(CONFIG_USER_ONLY) - cpu_list_unlock(); -#endif - return; - } QTAILQ_REMOVE(&cpus, cpu, node); - cpu_release_index(cpu); - cpu->cpu_index = -1; #if defined(CONFIG_USER_ONLY) (void) cc; cpu_list_unlock(); #else @@ -666,13 +657,54 @@ void cpu_exec_exit(CPUState *cpu) } #endif } -void cpu_exec_init(CPUState *cpu, Error **errp) +void cpu_exec_exit_cpu_index(CPUState *cpu) +{ +#if defined(CONFIG_USER_ONLY) + cpu_list_lock(); +#endif + if (cpu->cpu_index == -1) { + /* cpu_index was never allocated by this @cpu or was already freed. */ +#if defined(CONFIG_USER_ONLY) + cpu_list_unlock(); +#endif + return; + } + + cpu_release_index(cpu); + cpu->cpu_index = -1; +#if defined(CONFIG_USER_ONLY) + cpu_list_unlock(); +#endif +} + +void cpu_exec_exit(CPUState *cpu) +{ + cpu_exec_unrealize(cpu); + cpu_exec_exit_cpu_index(cpu); +} + +void cpu_exec_init_cpu_index(CPUState *cpu, Error **errp) { - CPUClass *cc = CPU_GET_CLASS(cpu); Error *local_err = NULL; +#if defined(CONFIG_USER_ONLY) + cpu_list_lock(); +#endif + cpu->cpu_index = cpu_get_free_index(&local_err); +#if defined(CONFIG_USER_ONLY) + cpu_list_unlock(); +#endif + if (local_err) { + error_propagate(errp, local_err); + } +} + +void cpu_exec_realize(CPUState *cpu, Error **errp) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + cpu->as = NULL; cpu->num_ases = 0; #ifndef CONFIG_USER_ONLY @@ -695,16 +727,8 @@ void cpu_exec_init(CPUState *cpu, Error **errp) #if defined(CONFIG_USER_ONLY) cpu_list_lock(); #endif - cpu->cpu_index = cpu_get_free_index(&local_err); - if (local_err) { - error_propagate(errp, local_err); -#if defined(CONFIG_USER_ONLY) - cpu_list_unlock(); -#endif - return; - } QTAILQ_INSERT_TAIL(&cpus, cpu, node); #if defined(CONFIG_USER_ONLY) (void) cc; cpu_list_unlock(); @@ -717,8 +741,21 @@ void cpu_exec_init(CPUState *cpu, Error **errp) } #endif } +void cpu_exec_init(CPUState *cpu, Error **errp) +{ + Error *local_err = NULL; + + cpu_exec_init_cpu_index(cpu, &local_err); + if (local_err == NULL) { + cpu_exec_realize(cpu, &local_err); + } + if (local_err != NULL) { + error_propagate(errp, local_err); + } +} + #if defined(CONFIG_USER_ONLY) static void breakpoint_invalidate(CPUState *cpu, target_ulong pc) { tb_invalidate_phys_page_range(pc, pc + 1, 0); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index c1f59fa59d2c..0f4cdf368945 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -56,8 +56,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, uint32_t flags, int cflags); void cpu_exec_init(CPUState *cpu, Error **errp); +void cpu_exec_init_cpu_index(CPUState *cpu, Error **errp); +void cpu_exec_realize(CPUState *cpu, Error **errp); void QEMU_NORETURN cpu_loop_exit(CPUState *cpu); void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc); #if !defined(CONFIG_USER_ONLY) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 32f3af3e1c63..63e77607f644 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -854,8 +854,10 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx); void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) GCC_FMT_ATTR(2, 3); void cpu_exec_exit(CPUState *cpu); +bool cpu_exec_exit_cpu_index(CPUState *cpu); +void cpu_exec_unrealize(CPUState *cpu); #ifdef CONFIG_SOFTMMU extern const struct VMStateDescription vmstate_cpu_common; #else