From patchwork Wed May 11 10:21:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 9067541 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 571999F1C1 for ; Wed, 11 May 2016 10:22:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C1B3201BC for ; Wed, 11 May 2016 10:22:27 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id ADB0920114 for ; Wed, 11 May 2016 10:22:26 +0000 (UTC) Received: from localhost ([::1]:51464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RHd-0002Ve-LE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 06:22:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RHP-0002PT-KG for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0RHN-0000am-5z for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:10 -0400 Received: from mail-lf0-x233.google.com ([2a00:1450:4010:c07::233]:35433) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RHM-0000ae-Pr for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:09 -0400 Received: by mail-lf0-x233.google.com with SMTP id j8so44073000lfd.2 for ; Wed, 11 May 2016 03:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nq3CBqzfqhzB3I1JhCz8oPeAaQuQU9iUbscsdSPp9ok=; b=X/lMa2fgVa74l5P3EsD+Jw7SG/hhG+/sA/YL+5pAUelGUu+IMAk66yfzAr425SHeAF 9LDfs/A8vZhCJuEnh3+usXIdyDXP64AIsJlZx+j0LuCtrWXalwCAyZjLOOrHc+eDm3S/ 4j5+QnaT/wG4Im6AlrcyzNbv7NlrHBJDCAObc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Nq3CBqzfqhzB3I1JhCz8oPeAaQuQU9iUbscsdSPp9ok=; b=SshSIT4mHRkGns2/OEtIG7J/VtOHqFhS8INDJjPxL1YK0Mooz4caKc3+eF+V6+YeKk 4oHB4Mj/0jxXWqGmxK723pW/nvQbuWDxbA/sDk/SLDXgT/rU6c1se8B88x/T3CxoDf2P 44kUVg8ji5twFVOwlUxToF3G/r0sySBH5CpUujUHyHb32f50ueVcU8SN4YfIchNT3xuY eem2hD09gRId7PO4uh3X9bxbrcASQLPz4ljMAKfKva/DllhxtHEk7TJRRz3AgVfplLNM eaQrhbUpj7hae0wPcUo+1IOeJMD61uZL1V9P2zjJ5xTsj8yHR3Dy+drTvGes7hABy5Db f3Fg== X-Gm-Message-State: AOPr4FUu7eMDQ77fX89osyZ90e/TayYgytl2eomDjmgiPh9AQO1Spz82JUaVTIr0jwwcZrws X-Received: by 10.25.160.77 with SMTP id j74mr1003636lfe.72.1462962128017; Wed, 11 May 2016 03:22:08 -0700 (PDT) Received: from sergey-laptop.Dlink (broadband-46-188-121-115.2com.net. [46.188.121.115]) by smtp.gmail.com with ESMTPSA id m1sm1196398lfb.45.2016.05.11.03.22.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 03:22:07 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 13:21:48 +0300 Message-Id: <1462962111-32237-3-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462962111-32237-1-git-send-email-sergey.fedorov@linaro.org> References: <1462962111-32237-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::233 Subject: [Qemu-devel] [PATCH 2/5] cpu-exec: Move exception handling out of cpu_exec() 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: Sergey Fedorov , Richard Henderson , Peter Crosthwaite , Sergey Fedorov , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov Simplify cpu_exec() by extracting exception handling code out of cpu_exec() into a new static inline function cpu_handle_exception(). Also make cpu_handle_debug_exception() inline as it is used only once. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Richard Henderson --- cpu-exec.c | 93 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 1fcdc3fabb39..f7e175e9ae1c 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -375,7 +375,7 @@ static inline bool cpu_handle_halt(CPUState *cpu) return false; } -static void cpu_handle_debug_exception(CPUState *cpu) +static inline void cpu_handle_debug_exception(CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); CPUWatchpoint *wp; @@ -389,6 +389,55 @@ static void cpu_handle_debug_exception(CPUState *cpu) cc->debug_excp_handler(cpu); } +static inline bool cpu_handle_exception(CPUState *cpu, int *ret) +{ + if (cpu->exception_index >= 0) { + if (cpu->exception_index >= EXCP_INTERRUPT) { + /* exit request from the cpu execution loop */ + *ret = cpu->exception_index; + if (*ret == EXCP_DEBUG) { + cpu_handle_debug_exception(cpu); + } + cpu->exception_index = -1; + return true; + } else { +#if defined(CONFIG_USER_ONLY) + /* if user mode only, we simulate a fake exception + which will be handled outside the cpu execution + loop */ +#if defined(TARGET_I386) + CPUClass *cc = CPU_GET_CLASS(cpu); + cc->do_interrupt(cpu); +#endif + *ret = cpu->exception_index; + cpu->exception_index = -1; + return true; +#else + if (replay_exception()) { + CPUClass *cc = CPU_GET_CLASS(cpu); + cc->do_interrupt(cpu); + cpu->exception_index = -1; + } else if (!replay_has_interrupt()) { + /* give a chance to iothread in replay mode */ + *ret = EXCP_INTERRUPT; + return true; + } +#endif + } +#ifndef CONFIG_USER_ONLY + } else if (replay_has_exception() + && cpu->icount_decr.u16.low + cpu->icount_extra == 0) { + /* try to cause an exception pending in the log */ + TranslationBlock *last_tb = NULL; /* Avoid chaining TBs */ + cpu_exec_nocache(cpu, 1, tb_find_fast(cpu, &last_tb, 0), true); + *ret = -1; + return true; +#endif + } + + return false; +} + /* main execution loop */ int cpu_exec(CPUState *cpu) @@ -426,50 +475,12 @@ int cpu_exec(CPUState *cpu) */ init_delay_params(&sc, cpu); - /* prepare setjmp context for exception handling */ for(;;) { + /* prepare setjmp context for exception handling */ if (sigsetjmp(cpu->jmp_env, 0) == 0) { /* if an exception is pending, we execute it here */ - if (cpu->exception_index >= 0) { - if (cpu->exception_index >= EXCP_INTERRUPT) { - /* exit request from the cpu execution loop */ - ret = cpu->exception_index; - if (ret == EXCP_DEBUG) { - cpu_handle_debug_exception(cpu); - } - cpu->exception_index = -1; - break; - } else { -#if defined(CONFIG_USER_ONLY) - /* if user mode only, we simulate a fake exception - which will be handled outside the cpu execution - loop */ -#if defined(TARGET_I386) - cc->do_interrupt(cpu); -#endif - ret = cpu->exception_index; - cpu->exception_index = -1; - break; -#else - if (replay_exception()) { - cc->do_interrupt(cpu); - cpu->exception_index = -1; - } else if (!replay_has_interrupt()) { - /* give a chance to iothread in replay mode */ - ret = EXCP_INTERRUPT; - break; - } -#endif - } -#ifndef CONFIG_USER_ONLY - } else if (replay_has_exception() - && cpu->icount_decr.u16.low + cpu->icount_extra == 0) { - /* try to cause an exception pending in the log */ - last_tb = NULL; /* Avoid chaining TBs */ - cpu_exec_nocache(cpu, 1, tb_find_fast(cpu, &last_tb, 0), true); - ret = -1; + if (cpu_handle_exception(cpu, &ret)) { break; -#endif } last_tb = NULL; /* forget the last executed TB after exception */