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: 9603503 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 7FBDF60414 for ; Fri, 3 Mar 2017 20:43:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C28628555 for ; Fri, 3 Mar 2017 20:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FD0E2855A; Fri, 3 Mar 2017 20:43:59 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFCF628555 for ; Fri, 3 Mar 2017 20:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KsX961wBCATvPT0TVpym8nGb4B/3U0qLhb7qYcOt3Xc=; b=scFr4Sc2kvvI3R6nBfTjNg8eik Gmyup6/1XYHnpcsen5YVQmq/fA2C00cf7mXelkNyhbzI9WBW19jCRnlSjOVjcnadC1qZCTyVPUh5A xR4ui2JkiPLsv4kgnEAWe8Yrwob76eve+0mwh9bobh5yGHw5D4LnfAew2UPQ0khqbfcNd7nuSlhqB /XnQVQCw0GAc5L8O+AalTmApmy5jfXUZQw4wxn3V+ew0CsybxfX1WUXn7r6rR99dJGNOMoUJWSZma IgoMOgiZ7A8qzqhTOJa52JtfbK1ZcJE9OY5pxuQztXDfu336P6byduaEhvwJOu1jRRQ2c30Ox8Kyp eaYXuc8Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cju3S-0005pw-Jl; Fri, 03 Mar 2017 20:43:58 +0000 Received: from mail-pg0-x231.google.com ([2607:f8b0:400e:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cju1g-0004qh-PB for linux-arm-kernel@lists.infradead.org; Fri, 03 Mar 2017 20:42:10 +0000 Received: by mail-pg0-x231.google.com with SMTP id b129so47454993pgc.2 for ; Fri, 03 Mar 2017 12:41:47 -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=ZVdYk9GB7fzbIZu1IKGcdfM8z8HYgNQqF/gjZfdAr5YLlj+RniOajqCnb+qAW1xNwR Gg6Xv0Usfx3JH1Uoa18tkc4oNEHUmrGoc1C0aHEDXZJWeUluCG6KqWE/LbjM6nqWruQy YxMSFim03PdtIK4aIHSZE95HXS6Deo/ZiW8nMlGPuVPOHz8a0iunEPY9i1Wrb8zj9aEh K15gvr3b2nL8mjCUum447muepTPHcanLUXTgvFvJjBSx76qZsjKX1gWbnz6QHERBHxqL TGelbpJLMWWCBsZk4EE4GceapomzbrJLQxugMUfCeA9FGn9P4FiH47lW6g8K/mFaZIT2 ybWQ== X-Gm-Message-State: AMke39kSnVKMPmjAnt2l4rEWb1N1s8iWxdsC2I8E+RmnM7cSXLMGXj7cYNNg2GtyMrzko8Uu 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170303_124208_850006_C386F97B X-CRM114-Status: GOOD ( 12.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 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 --- 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) {