From patchwork Tue May 10 15:46:42 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: 9059711 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 45DCEBF29F for ; Tue, 10 May 2016 15:47:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80F7520149 for ; Tue, 10 May 2016 15:47:43 +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 14D2620114 for ; Tue, 10 May 2016 15:47:42 +0000 (UTC) Received: from localhost ([::1]:47027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sq-0002GX-Ux for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 May 2016 11:47:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sX-00023R-7b for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b09sS-00004x-Nx for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:20 -0400 Received: from mail-lf0-x233.google.com ([2a00:1450:4010:c07::233]:34524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sS-0008WQ-61 for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:16 -0400 Received: by mail-lf0-x233.google.com with SMTP id m64so19680514lfd.1 for ; Tue, 10 May 2016 08:47:15 -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=Qr1onmuKuFVpk9WFtpSe9x9jK17d91dPkAZ7D0RqSKw=; b=K8nArbmQoymoA6whZwt1TktC8xf2l5iw36HeNUZANMm26UIOrZveYYqep3dukSLhO3 32W85fZuyE3w436bALZR4kE/8obiputoapIuuH3Wphp0yfc/JnpT0hX72/CkjnxqTeDe wn/fetf3s42II/YYaLRJzl/qj9FvfpcPJ/Y3Y= 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=Qr1onmuKuFVpk9WFtpSe9x9jK17d91dPkAZ7D0RqSKw=; b=h0fPNxIIHIXOShrtuXqTUJqxnQ6LAEEICnnM75JeKgRB7DWEfVqIVRXteG4iw5RWs/ SzwkoszpKqucJflt1YMTK0+Xz7KpqwtDYYL8L3qFwBC2wor2KyU+MGsoLvdm/xqR+rnm ol2H1yDDHnjY7uTMBBfFJLTnw35wlx0lGyEXbWTNSawJlX9zKrs+z6YXH9lnA22ymxZD wD0EQzFQePSvPAQtDgH+7oqAipr3qSDi8lDLsJ/hPAaAZ+/55357Cp8FatHbcy7ovjWT dobpdaDSFutbCr7grcjBUX8xb7UwdxenFAT82O9alvMwQRycB9qLK5uhFTmqnN0LMgn8 Eg4Q== X-Gm-Message-State: AOPr4FUTYt51NCxQhYRRYEzXGZ4JsAfzBb/lBG8cYbjF2D+nJVxSg5K1E01jLeFyebC1dSAD X-Received: by 10.112.204.99 with SMTP id kx3mr5441600lbc.31.1462895235377; Tue, 10 May 2016 08:47:15 -0700 (PDT) Received: from localhost.localdomain ([195.91.132.170]) by smtp.gmail.com with ESMTPSA id jn5sm495952lbc.24.2016.05.10.08.47.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 08:47:14 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Tue, 10 May 2016 18:46:42 +0300 Message-Id: <1462895205-8411-3-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462895205-8411-1-git-send-email-sergey.fedorov@linaro.org> References: <1462895205-8411-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 , Peter Crosthwaite , Paolo Bonzini , Sergey Fedorov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson 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 fb72f102742c..ad95ace38dd9 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 */