From patchwork Fri Aug 26 20:17:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9302017 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 9A3CC60757 for ; Fri, 26 Aug 2016 20:22:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B52129649 for ; Fri, 26 Aug 2016 20:22:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8014129652; Fri, 26 Aug 2016 20:22:29 +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 6742B29651 for ; Fri, 26 Aug 2016 20:22:28 +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 1bdNcb-0002ap-A5; Fri, 26 Aug 2016 20:21:01 +0000 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bdNaR-00007D-DB for linux-arm-kernel@lists.infradead.org; Fri, 26 Aug 2016 20:18:51 +0000 Received: by mail-pf0-x235.google.com with SMTP id h186so31631543pfg.3 for ; Fri, 26 Aug 2016 13:18:31 -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=IAppFQxW9BSRqPyQa/Rc/948FI7NE50hCpo278YvvNs=; b=aAQW4EaxFRVCLq3TCOFcApKJrbZqcebG6FtqBQNOwseuGopP+S2bRIxczIbUMf7Vgr wt5m2YZdd0t98zW/yYKyZWZo1rZo2E5hGAsNu60oyEtQ4iERmBTnPSgDeLvqm7x0Z1xb kgJOeNu8wy7Pv8BoiIUpAuRFzkIy9XeixeZh4= 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=IAppFQxW9BSRqPyQa/Rc/948FI7NE50hCpo278YvvNs=; b=Zg0dLIcohvQELjAlvv8PG2JzilHO9YBoxUIKEjfEYs2YdwstLeqdT6cgprC6iXBTOZ nzYTLaD6wppv5i5ahKpQ6L+dHzhTS0lxE+dgFx5STMZAfDD3gRLGvzvtrgvLmCY4TkZE OP4namw7yTnBxwl+T7eLY8zWgE4byIiCzB5ZKofX7KivBbLzUxfek5j6DOlS2BAIR7gL FZ4DDXBjRkjX+JooJFETjiesi0W7kv/Z18CgvmUy2/ubKKDjDK6LliK3ZyI4XN8a3bdW e8sC15A1EuRnIkq5/cQV2ChdX0GBIaRIuqJ82bFC6oMaPvqBMqIHbE+Q5yU1o5B4pRQN g44g== X-Gm-Message-State: AE9vXwMZH0VGMkb6wrHkG9r5ZlbT1ywkSnaoy3YDzQGUutn0Z6LzB5iyLJMARQcDChOrP3vc X-Received: by 10.98.14.72 with SMTP id w69mr9080520pfi.119.1472242711540; Fri, 26 Aug 2016 13:18:31 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id m128sm30761463pfm.42.2016.08.26.13.18.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 13:18:30 -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 v5 07/16] kernel/cpu_pm: Add runtime PM support for CPUs Date: Fri, 26 Aug 2016 14:17:49 -0600 Message-Id: <1472242678-33700-8-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472242678-33700-1-git-send-email-lina.iyer@linaro.org> References: <1472242678-33700-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160826_131847_796678_A407956D X-CRM114-Status: GOOD ( 12.23 ) 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, 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. Cc: Kevin Hilman Cc: Rafael J. Wysocki Signed-off-by: Lina Iyer --- kernel/cpu_pm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c index 009cc9a..657ce06 100644 --- a/kernel/cpu_pm.c +++ b/kernel/cpu_pm.c @@ -16,9 +16,11 @@ */ #include +#include #include #include #include +#include #include #include @@ -99,6 +101,7 @@ int cpu_pm_enter(void) { int nr_calls; int ret = 0; + struct device *dev = get_cpu_device(smp_processor_id()); read_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls); @@ -110,6 +113,10 @@ int cpu_pm_enter(void) cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL); read_unlock(&cpu_pm_notifier_lock); + /* Notify Runtime PM that we are suspending the CPU */ + if (!ret && dev) + RCU_NONIDLE(pm_runtime_put_sync_suspend(dev)); + return ret; } EXPORT_SYMBOL_GPL(cpu_pm_enter); @@ -129,6 +136,11 @@ EXPORT_SYMBOL_GPL(cpu_pm_enter); int cpu_pm_exit(void) { int ret; + struct device *dev = get_cpu_device(smp_processor_id()); + + /* Notify Runtime PM that we are resuming the CPU */ + if (dev) + RCU_NONIDLE(pm_runtime_get_sync(dev)); read_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_PM_EXIT, -1, NULL); @@ -200,6 +212,39 @@ int cpu_cluster_pm_exit(void) } EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit); +#ifdef CONFIG_HOTPLUG_CPU +static int cpu_pm_cpu_hotplug(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = get_cpu_device(smp_processor_id()); + + if (!dev) + return NOTIFY_OK; + + /* Execute CPU runtime PM on that CPU */ + switch (action & ~CPU_TASKS_FROZEN) { + case CPU_DYING: + pm_runtime_put_sync_suspend(dev); + break; + case CPU_STARTING: + pm_runtime_get_sync(dev); + break; + default: + break; + } + + return NOTIFY_OK; +} + +static int __init cpu_pm_hotplug_init(void) +{ + /* Register for hotplug notifications for runtime PM */ + hotcpu_notifier(cpu_pm_cpu_hotplug, 0); + return 0; +} +device_initcall(cpu_pm_hotplug_init); +#endif + #ifdef CONFIG_PM static int cpu_pm_suspend(void) {