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: 9603529 X-Patchwork-Delegate: agross@codeaurora.org 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 8F23260414 for ; Fri, 3 Mar 2017 20:49:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DB1F28584 for ; Fri, 3 Mar 2017 20:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72AE928589; Fri, 3 Mar 2017 20:49:58 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D845028584 for ; Fri, 3 Mar 2017 20:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752220AbdCCUt4 (ORCPT ); Fri, 3 Mar 2017 15:49:56 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36623 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751722AbdCCUt4 (ORCPT ); Fri, 3 Mar 2017 15:49:56 -0500 Received: by mail-pf0-f170.google.com with SMTP id x66so36686652pfb.3 for ; Fri, 03 Mar 2017 12:49:55 -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=WgVFiiBQqsvPDoQj7WBpPWuTPdY6E+BZDAWznpVc6M1bkKRkGX1JIodTGgtgLhdafY x4bAAKHoLTKKy1KU90VbFmvBg0Ad76CiUHlmIzmSqg4SpW4SitkgSr6RulypLq2Dc/li /DnEgRXjspt3C4gHPFyW3KOGYziuuIDkuC4NMoelQIciQpU0ysSZOn94PLDb07QXdQEw +WFBTrZJ4Fh43oGzq0hrt+W0FrLIrOHqYqs432SrGeDDWxbJw+Rq028yLYnvcNf4R2ag PdoE8qCvIuS+peqDm9ekECUzh535cA92eJ0VKNShhPeMDEj+8DsYSlWO1gT2rIIaI987 +vYQ== X-Gm-Message-State: AMke39nPNYk+P6q0u87KPDoXZ3f4Lc/8nzGHvsN/LbQMlOeDTcKekegLk+kYF5bYDJ9OlQ2g 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-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.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 --- include/linux/cpuhotplug.h | 1 + kernel/cpu_pm.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) 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) {