From patchwork Thu Feb 9 03:41:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93671 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp72876qgi; Wed, 8 Feb 2017 20:17:19 -0800 (PST) X-Received: by 10.98.152.218 with SMTP id d87mr1338827pfk.17.1486613839142; Wed, 08 Feb 2017 20:17:19 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p80si8978210pfk.56.2017.02.08.20.17.18; Wed, 08 Feb 2017 20:17:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751739AbdBIERE (ORCPT + 25 others); Wed, 8 Feb 2017 23:17:04 -0500 Received: from mail-pg0-f44.google.com ([74.125.83.44]:36138 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbdBIERC (ORCPT ); Wed, 8 Feb 2017 23:17:02 -0500 Received: by mail-pg0-f44.google.com with SMTP id v184so53942066pgv.3 for ; Wed, 08 Feb 2017 20:15:24 -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 :in-reply-to:references; bh=boF/CQjUTqiTrmqWV7Kcq4Y71ecH+N6IfNRG9Q9iUqQ=; b=VgGw7AMb4+LOk2WGsOnpsVGcf2T1NFdUtCyBxKh3+lKGfqTTTNffXKJU0J62xK944P 3eCEMeUq4yMDNEr10tGEsztoLjzRicr9AGo+oGieSEuX7xZzQcKifXS3HSSI/rrjqT7V 1uILExm0zrU2nQ9NALmEb/nrtNG2xM4UvL4N0= 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:in-reply-to:references; bh=boF/CQjUTqiTrmqWV7Kcq4Y71ecH+N6IfNRG9Q9iUqQ=; b=oI5Sd0HyApQ/Aqk+26BceGy5nt8oVWfHHSYkL6gYYDac/H2EaFevHhCt44l5Uu8MYa wsAcvaIzDIJ4hc6mcZltXX+rwuuqj/6BhDsyrpQifE2lQnJAnoIPmEDAaRagJDcbWAnx ZwpeOe5DyYgJtyub4KaBmUip1mDRoe7sW/KcJyxHNibJEOo+zewU7fZE0vZ5GSBtyy1j pbV14vkzrHBwhcci1oETGR39qB5imMkmlQyIgXienEI+LEqM8tjgwQD0r/kMhQtjsk9H A07q1rMlHP8/+NnvJ/t0I5/34vGsB1IocQVQbD6TmnqljuYyWMaPNa6KifAeQzPs0e8O /E9Q== X-Gm-Message-State: AMke39leH1LWXlft157+PXCwqRvpIGfWhys71hqU+70wN5btCzXo3NR9G4VBIoCWeP/gBcn8 X-Received: by 10.98.131.136 with SMTP id h130mr1268832pfe.4.1486611736333; Wed, 08 Feb 2017 19:42:16 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id t185sm23885898pgb.32.2017.02.08.19.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 19:42:15 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , khilman@baylibre.com, ulf.hansson@linaro.org, Kevin Hilman , Len Brown , Pavel Machek Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , sboyd@codeaurora.org, nm@ti.com, robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, Viresh Kumar Subject: [PATCH V2 4/6] PM / domain: Register for PM QOS performance notifier Date: Thu, 9 Feb 2017 09:11:50 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some platforms have the capability to configure the performance state of their Power Domains. The performance levels are represented by positive integer values, a lower value represents lower performance state. This patch registers the power domain framework for PM QOS performance notifier in order to manage performance state of power domains. This also allows the power domain drivers to implement a ->set_performance_state() callback, which will be called by the power domain core from the notifier routine. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 98 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 5 +++ 2 files changed, 101 insertions(+), 2 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a73d79670a64..1158a07f92de 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -367,6 +367,88 @@ static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +static void update_domain_performance_state(struct generic_pm_domain *genpd, + int depth) +{ + struct generic_pm_domain_data *pd_data; + struct generic_pm_domain *subdomain; + struct pm_domain_data *pdd; + unsigned int state = 0; + struct gpd_link *link; + + /* Traverse all devices within the domain */ + list_for_each_entry(pdd, &genpd->dev_list, list_node) { + pd_data = to_gpd_data(pdd); + + if (pd_data->performance_state > state) + state = pd_data->performance_state; + } + + /* Traverse all subdomains within the domain */ + list_for_each_entry(link, &genpd->master_links, master_node) { + subdomain = link->slave; + + if (subdomain->performance_state > state) + state = subdomain->performance_state; + } + + if (genpd->performance_state == state) + return; + + genpd->performance_state = state; + + if (genpd->set_performance_state) { + genpd->set_performance_state(genpd, state); + return; + } + + /* Propagate only if this domain has a single parent */ + if (list_is_singular(&genpd->slave_links)) { + /* Performance levels are managed by parent power domain */ + + struct generic_pm_domain *master; + + link = list_first_entry(&genpd->slave_links, struct gpd_link, slave_node); + master = link->master; + + genpd_lock_nested(master, depth + 1); + update_domain_performance_state(master, depth + 1); + genpd_unlock(master); + } +} + +static int genpd_dev_pm_qos_perf_notifier(struct notifier_block *nb, + unsigned long val, void *ptr) +{ + struct generic_pm_domain_data *gpd_data; + struct generic_pm_domain *genpd = ERR_PTR(-ENODATA); + struct pm_domain_data *pdd; + struct device *dev; + + gpd_data = container_of(nb, struct generic_pm_domain_data, perf_nb); + dev = gpd_data->base.dev; + + spin_lock_irq(&dev->power.lock); + + pdd = dev->power.subsys_data ? + dev->power.subsys_data->domain_data : NULL; + + if (pdd && pdd->dev) + genpd = dev_to_genpd(dev); + + spin_unlock_irq(&dev->power.lock); + + if (IS_ERR(genpd)) + return NOTIFY_DONE; + + genpd_lock(genpd); + gpd_data->performance_state = val; + update_domain_performance_state(genpd, 0); + genpd_unlock(genpd); + + return NOTIFY_DONE; +} + /** * genpd_power_off - Remove power from a given PM domain. * @genpd: PM domain to power down. @@ -1137,6 +1219,9 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, gpd_data->td.constraint_changed = true; gpd_data->td.effective_constraint_ns = -1; gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; + gpd_data->performance_state = 0; + + gpd_data->perf_nb.notifier_call = genpd_dev_pm_qos_perf_notifier; spin_lock_irq(&dev->power.lock); @@ -1210,12 +1295,16 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, out: genpd_unlock(genpd); - if (ret) + if (ret) { genpd_free_dev_data(dev, gpd_data); - else + } else { dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); + dev_pm_qos_add_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); + } + return ret; } @@ -1249,6 +1338,8 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, pdd = dev->power.subsys_data->domain_data; gpd_data = to_gpd_data(pdd); + dev_pm_qos_remove_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); dev_pm_qos_remove_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); @@ -1277,6 +1368,9 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd_unlock(genpd); dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); + dev_pm_qos_add_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); + return ret; } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 81ece61075df..d994ad5ba1c0 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -62,8 +62,11 @@ struct generic_pm_domain { unsigned int device_count; /* Number of devices */ unsigned int suspended_count; /* System suspend device counter */ unsigned int prepared_count; /* Suspend counter of prepared devices */ + unsigned int performance_state; /* Max requested performance state */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); + int (*set_performance_state)(struct generic_pm_domain *domain, + unsigned int state); struct gpd_dev_ops dev_ops; s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ bool max_off_time_changed; @@ -117,6 +120,8 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; + struct notifier_block perf_nb; + unsigned int performance_state; }; #ifdef CONFIG_PM_GENERIC_DOMAINS