From patchwork Thu Jul 27 12:08:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 9866711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BEBF860382 for ; Thu, 27 Jul 2017 12:08:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEC8922B39 for ; Thu, 27 Jul 2017 12:08:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A30E824151; Thu, 27 Jul 2017 12:08:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3CAE422B39 for ; Thu, 27 Jul 2017 12:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=r3qQeSQmuq8Phz8AOGxxX4R+hTOR1xwwURa4/fUTWoY=; b=Lyn MEvi4HiXK9A2wUVuNun+6s2LockykNUSzCm/b5bIBtHuwACD2gs75s6e4jRcEtN61v5TzPjw5DtQk dNeL4Rs3u0ZotEQt2jVHQ9rKZPWTJ+Fa10+t40SzZ38/7v10PbL0+6oUsCIRJeKqThL66yBaOJH6/ Vi9jqZXkriR34DbhEcLilnxbmfUX8xcGnwxGfmwzdj6rXR3GK+HQtC0iaOhwi+fI87iW5fumGsm87 GarLDd4jwfnOJkhUxs+AjZUmqJHY29D1UOIOgdWpWJ6zsqeIIKiglDoiiATJg7lihIWYe03oGd5Bw PdVXdIX3wHm6eNL38QzEUTy9uygqf9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dahaj-0001Yr-VE; Thu, 27 Jul 2017 12:08:33 +0000 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76] helo=wens.csie.org) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dahag-0001Sd-It for linux-arm-kernel@lists.infradead.org; Thu, 27 Jul 2017 12:08:32 +0000 Received: by wens.csie.org (Postfix, from userid 1000) id 5D5885FDEC; Thu, 27 Jul 2017 20:08:04 +0800 (CST) From: Chen-Yu Tsai To: Russell King Subject: [PATCH] ARM: Use WFI when possible when halting a core Date: Thu, 27 Jul 2017 20:08:03 +0800 Message-Id: <20170727120803.27848-1-wens@csie.org> X-Mailer: git-send-email 2.13.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170727_050830_760109_F4321F99 X-CRM114-Status: GOOD ( 11.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chen-Yu Tsai , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On ARM, the kernel busy loops after cleaning up when a core is to be halted. This may have the undesired effect of increasing the core temperature, at a time when no power or thermal management is available, such as a kernel panic or shutdown to halt. x86 uses the more efficient HLT (halt) instruction. The equivalent instruction on ARM is WFI (wait for interrupt). This patch makes the busy loops in the ARM halt/reboot/panic paths use WFI when available (as defined in arch/arm/include/asm/barrier.h). A touch test indicates that this lowers the surface temperature of the Allwinner H3 SoC, with all 4 cores brought up with SMP, from painfully hot to just warm to the touch after shutdown to halt. Signed-off-by: Chen-Yu Tsai --- I asked about this some time ago, and the answer was no one had done it. So here it is. It is somewhat similar to the patch "arm64: Improve parking of stopped CPUs", for arm64 obviously. --- arch/arm/kernel/reboot.c | 13 +++++++++++-- arch/arm/kernel/smp.c | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c index 3b2aa9a9fe26..068aef796de4 100644 --- a/arch/arm/kernel/reboot.c +++ b/arch/arm/kernel/reboot.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -107,7 +108,11 @@ void machine_halt(void) { local_irq_disable(); smp_send_stop(); - while (1); + while (1) { +#ifdef wfi + wfi(); +#endif + } } /* @@ -151,5 +156,9 @@ void machine_restart(char *cmd) /* Whoops - the platform was unable to reboot. Tell the user! */ printk("Reboot failed -- System halted\n"); - while (1); + while (1) { +#ifdef wfi + wfi(); +#endif + } } diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index c9a0a5299827..7666fb2ed481 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -567,8 +568,12 @@ static void ipi_cpu_stop(unsigned int cpu) local_fiq_disable(); local_irq_disable(); - while (1) + while (1) { cpu_relax(); +#ifdef wfi + wfi(); +#endif + } } static DEFINE_PER_CPU(struct completion *, cpu_completion);