From patchwork Fri May 13 00:13:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9087311 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 2A9CDBF29F for ; Fri, 13 May 2016 01:21:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F6A320219 for ; Fri, 13 May 2016 01:21:33 +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 554C3201CE for ; Fri, 13 May 2016 01:21:32 +0000 (UTC) Received: from localhost ([::1]:60437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10zg-0002WR-79 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 20:30:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lw-00035Z-Vk for qemu-devel@nongnu.org; Thu, 12 May 2016 20:16:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b10lu-00039B-Cw for qemu-devel@nongnu.org; Thu, 12 May 2016 20:16:03 -0400 Received: from mail-qg0-x241.google.com ([2607:f8b0:400d:c04::241]:35220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10lu-000391-8M for qemu-devel@nongnu.org; Thu, 12 May 2016 20:16:02 -0400 Received: by mail-qg0-x241.google.com with SMTP id b14so6076477qge.2 for ; Thu, 12 May 2016 17:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=i80qcbpMkopPVIqkLOcUaf+XGInZkOqsop1Ws9THxS8=; b=D2Ke2oJPG5zbWTQf27UycQZwExYKFKUID2+lWQXC3XnQmnUDepqzN72d/khLx+Zf7/ XIGlXxcr9hil64ZZ938IpXwHZ3qhRtGPUcT+MQQyzET08wYHthGsSXn0gbiQkJsQW3gf JFbhrW/RilNHEmTaLFSEGsD9Wmx9Z0fXqqm3X7DQOimz0zDQbQUhs6V5LWERvPjuX8Ol IAa7+JIVGcipoJLI8LJe3zdMYPy6kPti1nmkNdU6g3lHmAoliXI0ar9vgrrk8m17HHbo 9Vgb0cyL2jw6G3OKvkc1oac201Ij0ydN8WPoKPthRSnrNxSKWrA3H7NcYQBwceUS0vCp 1EPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=i80qcbpMkopPVIqkLOcUaf+XGInZkOqsop1Ws9THxS8=; b=jHq4m+E82m0ZH3XJbe7qxwAkCjvzXgx6VPTRCaybgGEPyWkOfbe+FIDNDMRzEz+n6W PO6RVu5IAotviOV73cF9jwp1SB3nLQ8VVt71rTqmJ0J5eRj1fGjQ2VJDw0gvOsNK96HR BcsrjQNVrVA0ZvLxZsPhlX0IQQkYPaIJEHkdP47e8TqbA2M8pVi7sKlHFS+/g+SjcPqz n9sL/I6krF4JlrQoo/jMTiD0xMxsvWNF8nQM7aP/Hy9s9q9p9iDc6PWp0q7WJw6w2Ztj hOWMPlCYkoZTaIX3Of5q7AziG70Upzc4EoVFwv5GGBTVVlbIqIJmJl6lAdiq3nzaa7IM LNpQ== X-Gm-Message-State: AOPr4FUQ0wtJJg2YzbCPbKS1QEWjLopQS4AC4qF0BJM7bifV3IpVJhoAM0cN2Jscfv14fg== X-Received: by 10.141.45.5 with SMTP id w5mr13361325qhe.1.1463098562016; Thu, 12 May 2016 17:16:02 -0700 (PDT) Received: from bigtime.com ([172.56.44.137]) by smtp.gmail.com with ESMTPSA id w16sm7171321qka.35.2016.05.12.17.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 17:16:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 14:13:37 -1000 Message-Id: <1463098420-29113-37-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1463098420-29113-1-git-send-email-rth@twiddle.net> References: <1463098420-29113-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::241 Subject: [Qemu-devel] [PULL 36/39] 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: peter.maydell@linaro.org, Sergey Fedorov , Sergey Fedorov 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=unavailable 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 Message-Id: <1462962111-32237-4-git-send-email-sergey.fedorov@linaro.org> Signed-off-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 36df395..c83b354 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -437,6 +437,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) @@ -446,7 +514,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; @@ -485,67 +553,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;