From patchwork Mon Aug 25 18:01:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shreyas B. Prabhu" X-Patchwork-Id: 4776021 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A31F99F38D for ; Mon, 25 Aug 2014 18:04:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FEB920166 for ; Mon, 25 Aug 2014 18:04:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DA8820145 for ; Mon, 25 Aug 2014 18:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933319AbaHYSBy (ORCPT ); Mon, 25 Aug 2014 14:01:54 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:42623 "EHLO e9.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933264AbaHYSBu (ORCPT ); Mon, 25 Aug 2014 14:01:50 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 25 Aug 2014 14:01:49 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e9.ny.us.ibm.com (192.168.1.109) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 25 Aug 2014 14:01:46 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 98ADF38C803D; Mon, 25 Aug 2014 14:01:46 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s7PI1ko51573138; Mon, 25 Aug 2014 18:01:46 GMT Received: from d01av04.pok.ibm.com (localhost [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s7PI1gi7009067; Mon, 25 Aug 2014 14:01:46 -0400 Received: from adminib-ovr2cdm.in.ibm.com ([9.79.195.178]) by d01av04.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s7PI1TtM007255; Mon, 25 Aug 2014 14:01:36 -0400 From: "Shreyas B. Prabhu" To: linux-kernel@vger.kernel.org Cc: "Srivatsa S. Bhat" , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "Shreyas B. Prabhu" , "Preeti U. Murthy" Subject: [PATCH 1/9] powerpc/powernv: Enable Offline CPUs to enter deep idle states Date: Mon, 25 Aug 2014 23:31:05 +0530 Message-Id: <1408989673-14137-2-git-send-email-shreyas@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1408989673-14137-1-git-send-email-shreyas@linux.vnet.ibm.com> References: <1408989673-14137-1-git-send-email-shreyas@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14082518-7182-0000-0000-00000047CF33 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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: "Srivatsa S. Bhat" The offline cpus should enter deep idle states so as to gain maximum powersavings when the entire core is offline. To do so the offline path must be made aware of the available deepest idle state. Hence probe the device tree for the possible idle states in powernv core code and expose the deepest idle state through flags. Since the device tree is probed by the cpuidle driver as well, move the parameters required to discover the idle states into an appropriate common place to both the driver and the powernv core code. Another point is that fastsleep idle state may require workarounds in the kernel to function properly. This workaround is introduced in the subsequent patches. However neither the cpuidle driver or the hotplug path need be bothered about this workaround. They will be taken care of by the core powernv code. Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Rafael J. Wysocki Cc: linux-pm@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Srivatsa S. Bhat Signed-off-by: Shreyas B. Prabhu [ Changelog modified by preeti@linux.vnet.ibm.com ] Signed-off-by: Preeti U. Murthy --- arch/powerpc/include/asm/opal.h | 4 +++ arch/powerpc/platforms/powernv/powernv.h | 7 +++++ arch/powerpc/platforms/powernv/setup.c | 51 ++++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/smp.c | 11 ++++++- drivers/cpuidle/cpuidle-powernv.c | 7 ++--- 5 files changed, 75 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index 86055e5..28b8342 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -772,6 +772,10 @@ extern struct kobject *opal_kobj; /* /ibm,opal */ extern struct device_node *opal_node; +/* Flags used for idle state discovery from the device tree */ +#define IDLE_INST_NAP 0x00010000 /* nap instruction can be used */ +#define IDLE_INST_SLEEP 0x00020000 /* sleep instruction can be used */ + /* API functions */ int64_t opal_invalid_call(void); int64_t opal_console_write(int64_t term_number, __be64 *length, diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h index 75501bf..31ece13 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -23,6 +23,13 @@ static inline int pnv_pci_dma_set_mask(struct pci_dev *pdev, u64 dma_mask) } #endif +/* Flags to indicate which of the CPU idle states are available for use */ + +#define IDLE_USE_NAP (1UL << 0) +#define IDLE_USE_SLEEP (1UL << 1) + +extern unsigned int pnv_get_supported_cpuidle_states(void); + extern void pnv_lpc_init(void); bool cpu_core_split_required(void); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 5a0e2dc..2dca1d8 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -282,6 +282,57 @@ static void __init pnv_setup_machdep_rtas(void) } #endif /* CONFIG_PPC_POWERNV_RTAS */ +static unsigned int supported_cpuidle_states; + +unsigned int pnv_get_supported_cpuidle_states(void) +{ + return supported_cpuidle_states; +} + +static int __init pnv_probe_idle_states(void) +{ + struct device_node *power_mgt; + struct property *prop; + int dt_idle_states; + u32 *flags; + int i; + + supported_cpuidle_states = 0; + + if (cpuidle_disable != IDLE_NO_OVERRIDE) + return 0; + + if (!firmware_has_feature(FW_FEATURE_OPALv3)) + return 0; + + power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); + if (!power_mgt) { + pr_warn("opal: PowerMgmt Node not found\n"); + return 0; + } + + prop = of_find_property(power_mgt, "ibm,cpu-idle-state-flags", NULL); + if (!prop) { + pr_warn("DT-PowerMgmt: missing ibm,cpu-idle-state-flags\n"); + return 0; + } + + dt_idle_states = prop->length / sizeof(u32); + flags = (u32 *) prop->value; + + for (i = 0; i < dt_idle_states; i++) { + if (flags[i] & IDLE_INST_NAP) + supported_cpuidle_states |= IDLE_USE_NAP; + + if (flags[i] & IDLE_INST_SLEEP) + supported_cpuidle_states |= IDLE_USE_SLEEP; + } + + return 0; +} + +subsys_initcall(pnv_probe_idle_states); + static int __init pnv_probe(void) { unsigned long root = of_get_flat_dt_root(); diff --git a/arch/powerpc/platforms/powernv/smp.c b/arch/powerpc/platforms/powernv/smp.c index 5fcfcf4..3ad31d2 100644 --- a/arch/powerpc/platforms/powernv/smp.c +++ b/arch/powerpc/platforms/powernv/smp.c @@ -149,6 +149,7 @@ static int pnv_smp_cpu_disable(void) static void pnv_smp_cpu_kill_self(void) { unsigned int cpu; + unsigned long idle_states; /* Standard hot unplug procedure */ local_irq_disable(); @@ -159,13 +160,21 @@ static void pnv_smp_cpu_kill_self(void) generic_set_cpu_dead(cpu); smp_wmb(); + idle_states = pnv_get_supported_cpuidle_states(); + /* We don't want to take decrementer interrupts while we are offline, * so clear LPCR:PECE1. We keep PECE2 enabled. */ mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1); while (!generic_check_cpu_restart(cpu)) { ppc64_runlatch_off(); - power7_nap(1); + + /* If sleep is supported, go to sleep, instead of nap */ + if (idle_states & IDLE_USE_SLEEP) + power7_sleep(); + else + power7_nap(1); + ppc64_runlatch_on(); /* Reenable IRQs briefly to clear the IPI that woke us */ diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index a64be57..23d2743 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c @@ -16,13 +16,12 @@ #include #include +#include #include /* Flags and constants used in PowerNV platform */ #define MAX_POWERNV_IDLE_STATES 8 -#define IDLE_USE_INST_NAP 0x00010000 /* Use nap instruction */ -#define IDLE_USE_INST_SLEEP 0x00020000 /* Use sleep instruction */ struct cpuidle_driver powernv_idle_driver = { .name = "powernv_idle", @@ -185,7 +184,7 @@ static int powernv_add_idle_states(void) for (i = 0; i < dt_idle_states; i++) { flags = be32_to_cpu(idle_state_flags[i]); - if (flags & IDLE_USE_INST_NAP) { + if (flags & IDLE_INST_NAP) { /* Add NAP state */ strcpy(powernv_states[nr_idle_states].name, "Nap"); strcpy(powernv_states[nr_idle_states].desc, "Nap"); @@ -196,7 +195,7 @@ static int powernv_add_idle_states(void) nr_idle_states++; } - if (flags & IDLE_USE_INST_SLEEP) { + if (flags & IDLE_INST_SLEEP) { /* Add FASTSLEEP state */ strcpy(powernv_states[nr_idle_states].name, "FastSleep"); strcpy(powernv_states[nr_idle_states].desc, "FastSleep");