From patchwork Thu Aug 25 19:51:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9299789 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 4FBF9608A7 for ; Thu, 25 Aug 2016 20:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3516D293AA for ; Thu, 25 Aug 2016 20:01:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29422292B1; Thu, 25 Aug 2016 20:01:28 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A7A14292B1 for ; Thu, 25 Aug 2016 20:01:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bd0ol-0001Q7-Uo; Thu, 25 Aug 2016 20:00:03 +0000 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bd0hX-0002ow-6F for linux-arm-kernel@lists.infradead.org; Thu, 25 Aug 2016 19:52:40 +0000 Received: by mail-pf0-x231.google.com with SMTP id p64so20704668pfb.1 for ; Thu, 25 Aug 2016 12:52:14 -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=nP2WZEnkovd6MyeNkqtBYHiNrUsPjiWq+Ghgyn8hWr8=; b=VFi3y+qW7ziO6iqaB9WNKHzlojdNrROJEy9TAgECRpKdnY08eJHzB6DfSsOMSMFsNG tOSKB5IizpDMReAwFsQcwG6UVhFEn4NC09VocYKHr6VEYTghfl6w4GJ+b5OYeQr9Wt+t 1oDFbUHqrvrMljal8KBaT2tqkI3l0dcQTeVdE= 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=nP2WZEnkovd6MyeNkqtBYHiNrUsPjiWq+Ghgyn8hWr8=; b=KlSiBdwTZwhfFPSasLwCC5nDAfk57ZUkVZf5vFdQFRfJJzOHuKrRTaoI/XGTCCynC7 m/Id7eJJiTa+YOy+j1vU53kty90VI7QnY25YadbJ/28cSiE3Ev9T9UQzVm9WYovFdAZs 40H7GlfeanxeBl1Q/4tIa4z1Ogkcyx+8mzeo2Y6eDNzcfGkJU9qCRsyydtrJZSe5xfG3 xmbWiuPwmrYm8+D5APQIkFSGOjqOnawC80DZXf1utFaGZpASkuOhWov3o+33+xjh0Vy6 6rBMerZFATM0Aw9xjp8Kjggezwbhbuf6q5qozxJ0yoGFYGHNaOdAj9RS1UMR2XX+ivwp BcBw== X-Gm-Message-State: AE9vXwMzfo5LyP6ntppDW500HOx8Q4BE8lMNTPywtAfy6lb/9ptN0kqnB8iafKHVxiXOqIjq X-Received: by 10.98.16.75 with SMTP id y72mr19559087pfi.50.1472154734378; Thu, 25 Aug 2016 12:52:14 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id i62sm22783375pfg.62.2016.08.25.12.52.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 12:52:13 -0700 (PDT) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 08/16] ARM: cpuidle: Add runtime PM support for CPUs Date: Thu, 25 Aug 2016 13:51:38 -0600 Message-Id: <1472154706-40119-9-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472154706-40119-1-git-send-email-lina.iyer@linaro.org> References: <1472154706-40119-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160825_125235_487297_458FA733 X-CRM114-Status: GOOD ( 16.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, Juri.Lelli@arm.com, linux-arm-msm@vger.kernel.org, Daniel Lezcano , sboyd@codeaurora.org, brendan.jackman@arm.com, sudeep.holla@arm.com, andy.gross@linaro.org, Lina Iyer 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 Notify runtime PM when the CPU is going to be powered off in the idle state. This allows for runtime PM suspend/resume of the CPU as well as its PM domain. We do not call into runtime PM for ARM WFI to keep the default state simple and faster. Cc: Daniel Lezcano Cc: Lorenzo Pieralisi Signed-off-by: Lina Iyer --- drivers/cpuidle/cpuidle-arm.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index e342565e..3abd145 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -11,12 +11,14 @@ #define pr_fmt(fmt) "CPUidle arm: " fmt +#include #include #include #include #include #include #include +#include #include #include @@ -37,6 +39,7 @@ static int arm_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; + struct device *cpu_dev = get_cpu_device(dev->cpu); if (!idx) { cpu_do_idle(); @@ -46,12 +49,20 @@ static int arm_enter_idle_state(struct cpuidle_device *dev, ret = cpu_pm_enter(); if (!ret) { /* + * Call runtime PM suspend on our device + * Notify RCU to pay attention to critical sections + * called from within runtime PM. + */ + RCU_NONIDLE(pm_runtime_put_sync_suspend(cpu_dev)); + + /* * Pass idle state index to cpu_suspend which in turn will * call the CPU ops suspend protocol with idle index as a * parameter. */ ret = arm_cpuidle_suspend(idx); + RCU_NONIDLE(pm_runtime_get_sync(cpu_dev)); cpu_pm_exit(); } @@ -84,6 +95,34 @@ static const struct of_device_id arm_idle_state_match[] __initconst = { { }, }; +#ifdef CONFIG_HOTPLUG_CPU +static int arm_idle_cpu_hotplug(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *cpu_dev = get_cpu_device(smp_processor_id()); + + /* Execute CPU runtime PM on that CPU */ + switch (action & ~CPU_TASKS_FROZEN) { + case CPU_DYING: + pm_runtime_put_sync_suspend(cpu_dev); + break; + case CPU_STARTING: + pm_runtime_get_sync(cpu_dev); + break; + default: + break; + } + + return NOTIFY_OK; +} +#else +static int arm_idle_cpu_hotplug(struct notifier_block *nb, + unsigned long action, void *data) +{ + return NOTIFY_OK; +} +#endif + /* * arm_idle_init * @@ -96,6 +135,7 @@ static int __init arm_idle_init(void) int cpu, ret; struct cpuidle_driver *drv = &arm_idle_driver; struct cpuidle_device *dev; + struct device *cpu_dev; /* * Initialize idle states data, starting at index 1. @@ -118,6 +158,16 @@ static int __init arm_idle_init(void) * idle states suspend back-end specific data */ for_each_possible_cpu(cpu) { + + /* Initialize Runtime PM for the CPU */ + cpu_dev = get_cpu_device(cpu); + pm_runtime_irq_safe(cpu_dev); + pm_runtime_enable(cpu_dev); + if (cpu_online(cpu)) { + pm_runtime_get_noresume(cpu_dev); + pm_runtime_set_active(cpu_dev); + } + ret = arm_cpuidle_init(cpu); /* @@ -148,10 +198,15 @@ static int __init arm_idle_init(void) } } + /* Register for hotplug notifications for runtime PM */ + hotcpu_notifier(arm_idle_cpu_hotplug, 0); + return 0; out_fail: while (--cpu >= 0) { dev = per_cpu(cpuidle_devices, cpu); + cpu_dev = get_cpu_device(cpu); + __pm_runtime_disable(cpu_dev, false); cpuidle_unregister_device(dev); kfree(dev); }