From patchwork Tue May 10 15:46:43 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: 9059721 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 1AC06BF29F for ; Tue, 10 May 2016 15:47:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47228200E9 for ; Tue, 10 May 2016 15:47:50 +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 617B52014A for ; Tue, 10 May 2016 15:47:48 +0000 (UTC) Received: from localhost ([::1]:47028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sx-0002Xx-Bj for patchwork-qemu-devel@patchwork.kernel.org; Tue, 10 May 2016 11:47:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sb-0002CH-OR for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b09sV-00005O-5C for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:24 -0400 Received: from mail-lf0-x22c.google.com ([2a00:1450:4010:c07::22c]:35432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b09sU-00005D-JK for qemu-devel@nongnu.org; Tue, 10 May 2016 11:47:19 -0400 Received: by mail-lf0-x22c.google.com with SMTP id j8so19612317lfd.2 for ; Tue, 10 May 2016 08:47:18 -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=49CCCC9PwRdoVijxoonE3r1ZYVmLuvu3Zei2RrL2brY=; b=WUItmTMx9ms+G/gVSzBBTy9+DpdzraCPn+Y6ZxkfAdXyo9OQNTUoVjT0kZp0SqaEIf NxOpOsQXUokbSRn/ffELGmN+R14J237IhumVzFCCFakf921Z/Amz0B3cP+SQuZvkfT/z 3qCo7IR1XDyh8wX9VViKtvJHFA+caNvJALAQ4= 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=49CCCC9PwRdoVijxoonE3r1ZYVmLuvu3Zei2RrL2brY=; b=Iiy9jR8JQwYMvbgUkMDPKgnlTTe5QPWoasFcnXmfxpJftPd16okLLxzD3VRYDY3DGW yC6zkz0uHNslRri5bq9kRnz/K40nt28sFyI5hnwXggz0vWQm8Uq2rQM670sCf6UzxEjC NEgxCA+1wUy0Mr8uVyrqc6WyKPLCLEBteEF7AFT/sNprvyBnwwX4fu9ninDNEwlOLqLB 1B2HV1/ogxw3rvBH+LatD1vvWBwXHO7RZoUac0+NaKTQs48XHOy3mPAE6NUwfecOcMUp HoiSxTzH4G2EYHu/zLnsr9rKuo98t+6h3IzkCywtQY0oMzWu2I/PSuK2SCYOo0iUnI39 r+Hg== X-Gm-Message-State: AOPr4FUytKBPTAFYqFGXKkxODpQCY19fP12vbCQVuKGwmOc7wrsNl8dn6wgouUe7yVEUPDxa X-Received: by 10.112.160.163 with SMTP id xl3mr17656025lbb.19.1462895237682; Tue, 10 May 2016 08:47:17 -0700 (PDT) Received: from localhost.localdomain ([195.91.132.170]) by smtp.gmail.com with ESMTPSA id jn5sm495952lbc.24.2016.05.10.08.47.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 May 2016 08:47:16 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Tue, 10 May 2016 18:46:43 +0300 Message-Id: <1462895205-8411-4-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::22c Subject: [Qemu-devel] [PATCH 3/5] cpu-exec: Move interrupt 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 interrupt handling code outside of cpu_exec() into a new static inline function cpu_handle_interrupt(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Richard Henderson --- cpu-exec.c | 132 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 62 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index ad95ace38dd9..0760d5dc274d 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -438,6 +438,74 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) return false; } +static inline void cpu_handle_interrupt(CPUState *cpu, + TranslationBlock **last_tb) +{ + CPUClass *cc = CPU_GET_CLASS(cpu); + int interrupt_request = cpu->interrupt_request; + + if (unlikely(interrupt_request)) { + if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) { + /* Mask out external interrupts for this step. */ + interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; + } + if (interrupt_request & CPU_INTERRUPT_DEBUG) { + cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG; + cpu->exception_index = EXCP_DEBUG; + cpu_loop_exit(cpu); + } + if (replay_mode == REPLAY_MODE_PLAY && !replay_has_interrupt()) { + /* Do nothing */ + } else if (interrupt_request & CPU_INTERRUPT_HALT) { + replay_interrupt(); + cpu->interrupt_request &= ~CPU_INTERRUPT_HALT; + cpu->halted = 1; + cpu->exception_index = EXCP_HLT; + cpu_loop_exit(cpu); + } +#if defined(TARGET_I386) + else if (interrupt_request & CPU_INTERRUPT_INIT) { + X86CPU *x86_cpu = X86_CPU(cpu); + CPUArchState *env = &x86_cpu->env; + replay_interrupt(); + cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0); + do_cpu_init(x86_cpu); + cpu->exception_index = EXCP_HALTED; + cpu_loop_exit(cpu); + } +#else + else if (interrupt_request & CPU_INTERRUPT_RESET) { + replay_interrupt(); + cpu_reset(cpu); + cpu_loop_exit(cpu); + } +#endif + /* The target hook has 3 exit conditions: + False when the interrupt isn't processed, + True when it is, and we should restart on a new TB, + and via longjmp via cpu_loop_exit. */ + else { + replay_interrupt(); + if (cc->cpu_exec_interrupt(cpu, interrupt_request)) { + *last_tb = NULL; + } + } + /* Don't use the cached interrupt_request value, + do_interrupt may have updated the EXITTB flag. */ + if (cpu->interrupt_request & CPU_INTERRUPT_EXITTB) { + cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB; + /* ensure that no TB jump will be modified as + the program flow was changed */ + *last_tb = NULL; + } + } + if (unlikely(cpu->exit_request || replay_has_interrupt())) { + cpu->exit_request = 0; + cpu->exception_index = EXCP_INTERRUPT; + cpu_loop_exit(cpu); + } +} + /* main execution loop */ int cpu_exec(CPUState *cpu) @@ -447,7 +515,7 @@ int cpu_exec(CPUState *cpu) X86CPU *x86_cpu = X86_CPU(cpu); CPUArchState *env = &x86_cpu->env; #endif - int ret, interrupt_request; + int ret; TranslationBlock *tb, *last_tb; int tb_exit = 0; SyncClocks sc; @@ -486,67 +554,7 @@ int cpu_exec(CPUState *cpu) last_tb = NULL; /* forget the last executed TB after exception */ cpu->tb_flushed = false; /* reset before first TB lookup */ for(;;) { - interrupt_request = cpu->interrupt_request; - if (unlikely(interrupt_request)) { - if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) { - /* Mask out external interrupts for this step. */ - interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK; - } - if (interrupt_request & CPU_INTERRUPT_DEBUG) { - cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG; - cpu->exception_index = EXCP_DEBUG; - cpu_loop_exit(cpu); - } - if (replay_mode == REPLAY_MODE_PLAY - && !replay_has_interrupt()) { - /* Do nothing */ - } else if (interrupt_request & CPU_INTERRUPT_HALT) { - replay_interrupt(); - cpu->interrupt_request &= ~CPU_INTERRUPT_HALT; - cpu->halted = 1; - cpu->exception_index = EXCP_HLT; - cpu_loop_exit(cpu); - } -#if defined(TARGET_I386) - else if (interrupt_request & CPU_INTERRUPT_INIT) { - replay_interrupt(); - cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0); - do_cpu_init(x86_cpu); - cpu->exception_index = EXCP_HALTED; - cpu_loop_exit(cpu); - } -#else - else if (interrupt_request & CPU_INTERRUPT_RESET) { - replay_interrupt(); - cpu_reset(cpu); - cpu_loop_exit(cpu); - } -#endif - /* The target hook has 3 exit conditions: - False when the interrupt isn't processed, - True when it is, and we should restart on a new TB, - and via longjmp via cpu_loop_exit. */ - else { - replay_interrupt(); - if (cc->cpu_exec_interrupt(cpu, interrupt_request)) { - last_tb = NULL; - } - } - /* Don't use the cached interrupt_request value, - do_interrupt may have updated the EXITTB flag. */ - if (cpu->interrupt_request & CPU_INTERRUPT_EXITTB) { - cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB; - /* ensure that no TB jump will be modified as - the program flow was changed */ - last_tb = NULL; - } - } - if (unlikely(cpu->exit_request - || replay_has_interrupt())) { - cpu->exit_request = 0; - cpu->exception_index = EXCP_INTERRUPT; - cpu_loop_exit(cpu); - } + cpu_handle_interrupt(cpu, &last_tb); tb = tb_find_fast(cpu, &last_tb, tb_exit); if (likely(!cpu->exit_request)) { uintptr_t ret;