From patchwork Wed May 11 10:21:49 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: 9067631 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 31ED6BF29F for ; Wed, 11 May 2016 10:25:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57F69201EF for ; Wed, 11 May 2016 10:25: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 0101320172 for ; Wed, 11 May 2016 10:25:26 +0000 (UTC) Received: from localhost ([::1]:51488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RKV-0008EX-6c for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 May 2016 06:25:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RHV-0002ZP-Se for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0RHO-0000bX-R9 for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:16 -0400 Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:33064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0RHO-0000bJ-Fg for qemu-devel@nongnu.org; Wed, 11 May 2016 06:22:10 -0400 Received: by mail-lf0-x22d.google.com with SMTP id y84so44412909lfc.0 for ; Wed, 11 May 2016 03:22:10 -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=RX1XxWtVBbPiW1/5jPVI9ZLjeV95adDiJQ5E/nN+zyM=; b=OVTbiyNjAyoAsoeqqFxqFHgH4Rh9jYFak8V7JPsDpVErIQ1qelIuWaD6wOXlb43YWF LEM5pAkFWxiJj8k3+DltH+Swrbpus4x/+/Ct22HGX9vPQs9mYYK0derAYON2nGTHlojq t7C6T7xWdW5CvhME3SWN05joOVjYeRI9pvFcY= 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=RX1XxWtVBbPiW1/5jPVI9ZLjeV95adDiJQ5E/nN+zyM=; b=bujvll5p2slCZjAFT4otbfYWAxBqBksmaMuopetFwbvh50U8W14xvReXNtxEWb7tR6 HH+/qcMKH/D8rq+LVlXyFK9zAfp0X1/SDmwCz9/JKxbj5zYclmptsoblquEPOqhaxUE8 eMJjOosax+abrcO8BbFJ58HmCXfmOg9AJ4cILtOrFx1vDd64iMmjPMoAgka3/x8gIEC3 LcQgbOTzzxPV67mHT/IjLIXoNA9AiiC+mMcnoJWgOG2vMRY0q/JaykJrNUT6MnJ1tA0P UAKc82W8U5A+86VReNdJySKYXNAd9Vm2oXW0JVouD4yhgc6nKLSKJYp9mNFcPA70W8A8 1Z4Q== X-Gm-Message-State: AOPr4FV3mfoM5fdk/63fD2iEtZk1xLrrpNcC96GFgI+x425/ojXyXnz9oY3faQte6RCxdIc5 X-Received: by 10.112.167.97 with SMTP id zn1mr1097543lbb.41.1462962129843; Wed, 11 May 2016 03:22:09 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 03:22:09 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Wed, 11 May 2016 13:21:49 +0300 Message-Id: <1462962111-32237-4-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::22d 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 , 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 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 f7e175e9ae1c..a053b5e73af1 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;