From patchwork Fri Mar 3 20:41:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 94865 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp418925qgd; Fri, 3 Mar 2017 12:49:44 -0800 (PST) X-Received: by 10.99.116.10 with SMTP id p10mr5664570pgc.74.1488574184660; Fri, 03 Mar 2017 12:49:44 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si3038974pli.285.2017.03.03.12.49.44; Fri, 03 Mar 2017 12:49:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752037AbdCCUtm (ORCPT + 13 others); Fri, 3 Mar 2017 15:49:42 -0500 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34253 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752164AbdCCUtl (ORCPT ); Fri, 3 Mar 2017 15:49:41 -0500 Received: by mail-pg0-f42.google.com with SMTP id 77so3255564pgc.1 for ; Fri, 03 Mar 2017 12:49:27 -0800 (PST) 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=wa/AkZodlw/5x5kUfVBybMrR9/1CH75Z7UE6wJkpsgY=; b=B6b5bt3VedG3d92Ivz7mgvljALBKQZP9tvXkQg0CE/kxLeSmdFVYzbnmDOioT4bAYM mkcwVKSsgzstoSVEZ5/zvSCe9EZhJDF6JQbh9EP3IGvqQ+nFuwF/VTaWMvkOM0AKHgbm SJgKDkUvuVQ5UxPhzKxuNctB4wFuj5yk+N+9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wa/AkZodlw/5x5kUfVBybMrR9/1CH75Z7UE6wJkpsgY=; b=UYRegkH/fvpSCsfJOs2zIgc2SVovPQhVdMxQ5dvm3oCEJjteAowuhUHFW9fujyeum/ i9Esu4ic7oZnyTXanVVCoHng5BxmzMWP2stP2JQ8seJi0d5/CndGVv+Vz/8Bh+xIrTj+ vPjHBJVl846gTsxah0OnKss3OFOotYVX4fLpXHIB9ha8PwfovOmf3ti0wk3vXnpXyZT5 CCeyIZ+nXBuJNf7CEQcz8WnXdibuElzt4KbdBuy8jNA/z840JA6AIoL19vm+UU81z3pd TAwe0Xv5k6OegRgst5rV6cLX/6rdRvfK2rTFT/K6KiIA/rbw6oTFsHl2YAROBfqfG0I4 vsnQ== X-Gm-Message-State: AMke39m6UsRX8sfRfQU0lZ64CXiUJtuYPUrSLPAGhoyJCxvxmZar0jUt8wujHR9WXShWJd7y X-Received: by 10.84.202.194 with SMTP id q2mr7048921plh.108.1488573707532; Fri, 03 Mar 2017 12:41:47 -0800 (PST) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id o189sm25207003pga.12.2017.03.03.12.41.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 12:41:46 -0800 (PST) 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 Cc: andy.gross@linaro.org, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, brendan.jackman@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, Juri.Lelli@arm.com, Lina Iyer Subject: [PATCH V5 3/9] kernel/cpu_pm: Add runtime PM support for CPUs Date: Fri, 3 Mar 2017 12:41:29 -0800 Message-Id: <1488573695-106680-4-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488573695-106680-1-git-send-email-lina.iyer@linaro.org> References: <1488573695-106680-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- include/linux/cpuhotplug.h | 1 + kernel/cpu_pm.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) -- 2.7.4 diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 921acaa..448226a 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -79,6 +79,7 @@ enum cpuhp_state { CPUHP_AP_OFFLINE, CPUHP_AP_SCHED_STARTING, CPUHP_AP_RCUTREE_DYING, + CPUHP_AP_CPU_PM_STARTING, CPUHP_AP_IRQ_GIC_STARTING, CPUHP_AP_IRQ_HIP04_STARTING, CPUHP_AP_IRQ_ARMADA_XP_STARTING, diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c index 009cc9a..db95ef3 100644 --- a/kernel/cpu_pm.c +++ b/kernel/cpu_pm.c @@ -16,9 +16,12 @@ */ #include +#include +#include #include #include #include +#include #include #include @@ -99,6 +102,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 +114,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 +137,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 +213,40 @@ int cpu_cluster_pm_exit(void) } EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit); +#ifdef CONFIG_HOTPLUG_CPU +static int cpu_pm_cpu_dying(unsigned int cpu) +{ + struct device *dev = get_cpu_device(cpu); + + if (dev) + pm_runtime_put_sync_suspend(dev); + + return 0; +} + +static int cpu_pm_cpu_starting(unsigned int cpu) +{ + struct device *dev = get_cpu_device(cpu); + + if (dev) + pm_runtime_get_sync(dev); + + return 0; +} + +static int __init cpu_pm_hotplug_init(void) +{ + int ret; + + ret = cpuhp_setup_state(CPUHP_AP_CPU_PM_STARTING, + "AP_CPU_PM_STARTING", + cpu_pm_cpu_starting, cpu_pm_cpu_dying); + + return ret; +} +device_initcall(cpu_pm_hotplug_init); +#endif + #ifdef CONFIG_PM static int cpu_pm_suspend(void) {