From patchwork Tue May 19 18:33:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 474036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DC576140D4D for ; Wed, 20 May 2015 04:52:31 +1000 (AEST) Received: from localhost ([::1]:48276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yumcw-00055t-4s for incoming@patchwork.ozlabs.org; Tue, 19 May 2015 14:52:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YumcI-0003xe-04 for qemu-devel@nongnu.org; Tue, 19 May 2015 14:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YumcG-0004vx-Sx for qemu-devel@nongnu.org; Tue, 19 May 2015 14:51:49 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YumcG-0004tS-MZ for qemu-devel@nongnu.org; Tue, 19 May 2015 14:51:48 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1YumKc-0001N5-Ot; Tue, 19 May 2015 19:33:34 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 19 May 2015 19:33:33 +0100 Message-Id: <1432060414-5195-14-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1432060414-5195-1-git-send-email-peter.maydell@linaro.org> References: <1432060414-5195-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Cc: edgar.iglesias@xilinx.com, serge.fdrv@gmail.com, alex.bennee@linaro.org, agraf@suse.de, patches@linaro.org Subject: [Qemu-devel] [PATCH 13/14] target-arm: Don't halt on WFI unless we don't have any work X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Just NOP the WFI instruction if we have work to do. This doesn't make much difference currently (though it does avoid jumping out to the top level loop and immediately restarting), but the distinction between "halt" and "don't halt" will become more important when the decision to halt requires us to trap to a higher exception level instead. Suggested-by: Edgar E. Iglesias Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias --- target-arm/op_helper.c | 7 +++++++ target-arm/translate-a64.c | 4 ++++ target-arm/translate.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 5963f3b..517dacc 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -252,6 +252,13 @@ void HELPER(wfi)(CPUARMState *env) { CPUState *cs = CPU(arm_env_get_cpu(env)); + if (cpu_has_work(cs)) { + /* Don't bother to go into our "low power state" if + * we would just wake up immediately. + */ + return; + } + cs->exception_index = EXCP_HLT; cs->halted = 1; cpu_loop_exit(cs); diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index 8d08ccd..ffa6cb8 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -11113,6 +11113,10 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, */ gen_a64_set_pc_im(dc->pc); gen_helper_wfi(cpu_env); + /* The helper doesn't necessarily throw an exception, but we + * must go back to the main loop to check for interrupts anyway. + */ + tcg_gen_exit_tb(0); break; } } diff --git a/target-arm/translate.c b/target-arm/translate.c index ed2c43d..6493b9a 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -11351,6 +11351,10 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, break; case DISAS_WFI: gen_helper_wfi(cpu_env); + /* The helper doesn't necessarily throw an exception, but we + * must go back to the main loop to check for interrupts anyway. + */ + tcg_gen_exit_tb(0); break; case DISAS_WFE: gen_helper_wfe(cpu_env);