From patchwork Thu Jun 4 22:29:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 49482 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 64A7A20DDC for ; Wed, 3 Jun 2015 15:53:34 +0000 (UTC) Received: by lbcak1 with SMTP id ak1sf3829807lbc.2 for ; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=sHF02bRiKU6yI3g2SkchuuoM712nFJrmo1eiJtOPK6w=; b=Ubj+AvrZ4VQtYF44KsDnGT86WUjKe+0s33eWxxRYh8j125AOw+uTanqQZzJFLjOs8D XpcWHiI7JANsMsNywqgV+GABdTKMEBP8G2buUC3TUoqOpAl6U39aETMF3Bj1Ua5QTXCS GmQ7fRrTncKtoc3w/PlN9L1lPuWj3xTCC7NzeIXkoF4VzCrSeNh1yntqskelqqgC6JfS yQekICLrU0l5nbrfI4EDr/b67FCdwSku6HCjfkQU3fDXy/5A2Gnjz5yCvbqLLCVAtS4q va3yrjL4KEfU6mGCC4Vg1X79OhEl7ElHCQmRg8XYxoKJ19Btj/6xTVJIxnwkmZL1L54Y W6dg== X-Gm-Message-State: ALoCoQko/eAk2mtL0RfEWMWG92rFLEVbPCi9CnEKUWEy2H0Z1tfAtrAhZy9/NRifxm2bSQvOufOv X-Received: by 10.112.203.168 with SMTP id kr8mr31379095lbc.10.1433346813373; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.42 with SMTP id j10ls71920laf.27.gmail; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) X-Received: by 10.112.56.42 with SMTP id x10mr32893135lbp.123.1433346813213; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id h4si2380715lbm.158.2015.06.03.08.53.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jun 2015 08:53:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbcue7 with SMTP id ue7so10058817lbc.0 for ; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) X-Received: by 10.112.220.7 with SMTP id ps7mr32225965lbc.72.1433346813057; Wed, 03 Jun 2015 08:53:33 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3965610lbb; Wed, 3 Jun 2015 08:53:31 -0700 (PDT) X-Received: by 10.66.159.68 with SMTP id xa4mr61907109pab.105.1433346809914; Wed, 03 Jun 2015 08:53:29 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vb4si1563975pac.93.2015.06.03.08.53.29; Wed, 03 Jun 2015 08:53:29 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755289AbbFCPxZ (ORCPT + 11 others); Wed, 3 Jun 2015 11:53:25 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34957 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751950AbbFCPxY (ORCPT ); Wed, 3 Jun 2015 11:53:24 -0400 Received: by padjw17 with SMTP id jw17so9919431pad.2 for ; Wed, 03 Jun 2015 08:53:24 -0700 (PDT) X-Received: by 10.66.101.9 with SMTP id fc9mr59939859pab.37.1433346804459; Wed, 03 Jun 2015 08:53:24 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by mx.google.com with ESMTPSA id q3sm1216066pdr.10.2015.06.03.08.53.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Jun 2015 08:53:23 -0700 (PDT) From: Lina Iyer To: rjw@rjwysocki.net, ulf.hansson@linaro.org, khilman@linaro.org Cc: mathieu.poirier@linaro.org, galak@codeaurora.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, msivasub@codeaurora.org, agross@codeaurora.org, Lina Iyer Subject: [PATCH RFC 3/3] PM / Domains: Introduce generic PM domain for cpu domain Date: Thu, 4 Jun 2015 16:29:06 -0600 Message-Id: <1433456946-53296-4-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433456946-53296-1-git-send-email-lina.iyer@linaro.org> References: <1433456946-53296-1-git-send-email-lina.iyer@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lina.iyer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Generally cpus are grouped under a power domain in a SoC. When all cpus in the domain are in their power off state, the cpu domain can also be powered off. Genpd provides the framework for defining cpus as devices that are part of a cpu domain. Introduce support for defining and adding a generic power domain for the cpus based on the DT specification of power domain providers and consumers. SoC's that have the cpu domain defined in their DT, can setup a genpd with a name and the power_on/power_off callbacks. Calling pm_cpu_domain_init() will register the genpd and attach the cpus for this domain with the genpd. CPU_PM notifications for are used to pm_runtime_get_sync() and pm_runtime_put_sync() for each cpu. When all cpus are powered off, the last cpu going down would call the genpd->power_off(). Correspondingly, the first cpu up would call the genpd->power_on() callback before resuming from idle. Cc: Ulf Hansson Cc: Rafael J. Wysocki Cc: Kevin Hilman Signed-off-by: Lina Iyer --- drivers/base/power/Makefile | 1 + drivers/base/power/cpu_domain.c | 187 ++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 12 +++ kernel/power/Kconfig | 12 +++ 4 files changed, 212 insertions(+) create mode 100644 drivers/base/power/cpu_domain.c diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 1cb8544..debfc74 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile @@ -4,5 +4,6 @@ obj-$(CONFIG_PM_TRACE_RTC) += trace.o obj-$(CONFIG_PM_OPP) += opp.o obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o obj-$(CONFIG_HAVE_CLK) += clock_ops.o +obj-$(CONFIG_PM_CPU_DOMAIN) += cpu_domain.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG diff --git a/drivers/base/power/cpu_domain.c b/drivers/base/power/cpu_domain.c new file mode 100644 index 0000000..ee90094 --- /dev/null +++ b/drivers/base/power/cpu_domain.c @@ -0,0 +1,187 @@ +/* + * Generic CPU domain runtime power on/off support + * + * Copyright (C) 2015 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct cpumask cpus_handled; + +static void do_cpu(void *unused) +{ + int cpu = smp_processor_id(); + struct device *dev = get_cpu_device(cpu); + + pm_runtime_get_sync(dev); +} + +static int cpuidle_genpd_device_init(int cpu) +{ + struct device *dev = get_cpu_device(cpu); + + /* + * CPU device have to be irq safe for use with cpuidle, which runs + * with irqs disabled. + */ + pm_runtime_irq_safe(dev); + pm_runtime_enable(dev); + + genpd_dev_pm_attach(dev); + + /* + * Execute the below on 'that' cpu to ensure that the reference + * counting is correct. Its possible that while this code is + * executed, the cpu may be in idle but we may incorrectly + * increment the usage. By executing the do_cpu on 'that' cpu, + * we can ensure that the cpu and the usage count are matched. + */ + return smp_call_function_single(cpu, do_cpu, NULL, true); +} + +static int cpu_state_notifier(struct notifier_block *n, + unsigned long action, void *hcpu) +{ + int cpu = smp_processor_id(); + struct device *dev = get_cpu_device(cpu); + + if (!cpumask_test_cpu(cpu, &cpus_handled)) + return NOTIFY_DONE; + + switch (action) { + case CPU_PM_ENTER: + pm_runtime_put_sync(dev); + break; + + case CPU_PM_ENTER_FAILED: + case CPU_PM_EXIT: + pm_runtime_get_sync(dev); + break; + + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static int cpu_online_notifier(struct notifier_block *n, + unsigned long action, void *hcpu) +{ + int cpu = (unsigned long)hcpu; + struct device *dev = get_cpu_device(cpu); + + if (!cpumask_test_cpu(cpu, &cpus_handled)) + return NOTIFY_DONE; + + switch (action) { + case CPU_STARTING: + case CPU_STARTING_FROZEN: + /* + * Attach the cpu to its domain if the cpu is coming up + * for the first time. + * Called from the cpu that is coming up. + */ + if (!genpd_dev_pm_attach(dev)) + do_cpu(NULL); + break; + + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static struct notifier_block hotplug_notifier = { + .notifier_call = cpu_online_notifier, +}; + +static struct notifier_block cpu_pm_notifier = { + .notifier_call = cpu_state_notifier, +}; + +static struct generic_pm_domain *get_cpu_domain(int cpu) +{ + struct device *dev = get_cpu_device(cpu); + struct of_phandle_args pd_args; + int ret; + + /* Make sure we are a domain consumer */ + ret = of_parse_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells", 0, &pd_args); + if (ret) + return ERR_PTR(ret); + + /* Attach cpus only for this domain */ + return of_genpd_get_from_provider(&pd_args); +} + +int pm_cpu_domain_init(struct generic_pm_domain *genpd, struct device_node *dn) +{ + int cpu; + int ret; + cpumask_var_t tmpmask; + struct generic_pm_domain *cpupd; + + if (!genpd || !dn) + return -EINVAL; + + if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL)) + return -ENOMEM; + + /* CPU genpds have to operate in IRQ safe mode */ + genpd->flags |= GENPD_FLAG_IRQ_SAFE; + + pm_genpd_init(genpd, NULL, false); + ret = of_genpd_add_provider_simple(dn, genpd); + if (ret) + return ret; + + /* Only add those cpus to whom we are the domain provider */ + for_each_online_cpu(cpu) { + cpupd = get_cpu_domain(cpu); + + if (IS_ERR(cpupd)) + continue; + + if (genpd == cpupd) { + cpuidle_genpd_device_init(cpu); + cpumask_set_cpu(cpu, tmpmask); + } + } + + if (cpumask_empty(tmpmask)) + goto done; + + /* + * Not all cpus may be online at this point. Use the hotplug + * notifier to be notified of when the cpu comes online, then + * attach it to the domain. + * + * Register hotplug and cpu_pm notification once for all + * domains. + */ + if (cpumask_empty(&cpus_handled)) { + cpu_pm_register_notifier(&cpu_pm_notifier); + register_cpu_notifier(&hotplug_notifier); + } + + cpumask_copy(&cpus_handled, tmpmask); + +done: + free_cpumask_var(tmpmask); + return 0; +} +EXPORT_SYMBOL(pm_cpu_domain_init); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index dc7cb53..fc97ad8 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -280,6 +280,7 @@ struct generic_pm_domain *__of_genpd_xlate_onecell( void *data); int genpd_dev_pm_attach(struct device *dev); + #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate, void *data) @@ -325,4 +326,15 @@ static inline int dev_pm_domain_attach(struct device *dev, bool power_on) static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} #endif +#ifdef CONFIG_PM_CPU_DOMAIN +extern int pm_cpu_domain_init(struct generic_pm_domain *genpd, + struct device_node *dn); +#else +static inline int pm_cpu_domain_init(struct generic_pm_domain *genpd, + struct device_node *dn) +{ + return -ENODEV; +} +#endif + #endif /* _LINUX_PM_DOMAIN_H */ diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig index 7e01f78..55d49f6 100644 --- a/kernel/power/Kconfig +++ b/kernel/power/Kconfig @@ -301,3 +301,15 @@ config PM_GENERIC_DOMAINS_OF config CPU_PM bool + +config PM_CPU_DOMAIN + def_bool y + depends on PM_GENERIC_DOMAINS_OF && CPU_PM + help + When cpuidle powers of the cpus in a domain, the domain can also be + powered off. + This config option allow for cpus to be registered with the domain + provider specified in the DT and when the cpu is powered off, calls + the runtime PM methods to do the reference counting. The last cpu + going down powers the domain off as well. +