From patchwork Thu Oct 12 09:37:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 115596 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1729678qgn; Thu, 12 Oct 2017 02:37:58 -0700 (PDT) X-Received: by 10.159.249.4 with SMTP id bf4mr1679030plb.283.1507801077959; Thu, 12 Oct 2017 02:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507801077; cv=none; d=google.com; s=arc-20160816; b=0N820ki80NTJdO5YTbIjVcePu9/dRa1QUEX1G1fhqp/kCK4zT5TwzaQ3XzviR2YYd4 yPN73s3ohUOL55lC2yQIF5Q2tUkUngwjwBVTbGJB1T4OUR6F9lbjIGtmgXtzJWRiWF12 3SUHbWuVEi9zSfkJOY8TuR7UNoTIRVFyzvtxzVD3ZaME6wzJYjEAy6+8/zLg11ZXA4Dj 2FhouJykI3sjkAW/Ahq0TB3+2aqGacv0igtgIz9U9tBAtzpwgmjqlBqXfRPwHvdPdJOj pk1AoXRMTmC+qnAhgFNXTl3IXVlmF/Pe551QaglUYnmPHnB9NmG3siJhXvsbYzaxPnIQ 2eHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IEjkK6RnmxDEWznw/A+yATiSnYnsz4xJN1ULeUYmq6s=; b=bTw3S1nuAD26Skd/N4wyoIoU8NFwX/P1ImX9v/Fu1YEIt17RLt2ddqCcgRCXpynf/3 agIB9BDcwe95kbWj0kG3fUDwiCb+uMHN39vVfDugTPgZcy5Ehez21+kBOr5cxvjeOXhZ jaxdU+EzHTu7nM6aItJaGDUOhxjO0s1rokmAEcLWE9ZD/C65w68oR+gHoi37Jz84Ld5H HzgJ/eHDB3cdBw/nbynEFHXaBZAzi5ngO73arybILJCWxmcs9/lqHyWHMqNM64jFlze3 W2BMXrBA47c6WesU3UX8R+KrCc8JgtR8VhGJM3lcbgNf/W56RCMqKZv9YQmI5H2YNvt+ lwTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U+SWb+Lh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si378572plw.392.2017.10.12.02.37.57; Thu, 12 Oct 2017 02:37:57 -0700 (PDT) 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 header.s=google header.b=U+SWb+Lh; 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 S1756147AbdJLJh4 (ORCPT + 27 others); Thu, 12 Oct 2017 05:37:56 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:46211 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755835AbdJLJhy (ORCPT ); Thu, 12 Oct 2017 05:37:54 -0400 Received: by mail-pf0-f176.google.com with SMTP id p87so4074984pfj.3 for ; Thu, 12 Oct 2017 02:37:53 -0700 (PDT) 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=IEjkK6RnmxDEWznw/A+yATiSnYnsz4xJN1ULeUYmq6s=; b=U+SWb+Lhrb3TU8ru3AiQlWOGHzaQXPiOBF4E+ykTS1GOVCMiliVdV7ro3IAwCkiCij 09K/yvWjzcuwBwOY4yWClU15JL2tewPLly2iSP/80JvdVw10Fi799Q2IklsaNImlAGBA E970JE23FPCACbnxrC9Zl3qPo1IsPWkujH2Ps= 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=IEjkK6RnmxDEWznw/A+yATiSnYnsz4xJN1ULeUYmq6s=; b=NLvusBsWwpg4u1maB7Ct6QozAn48+IsGvu2RB0sjyTXDtBjupnl5zRZM3kdzdlp7cQ 1+d1m1hdI4oQ6r2JPQFCHkxHkZw1cLCtWTYTGW/ap2HD9YscFfVHJje2DoRY3Muj4B2c yhLqTZWUEzVOK3fr9p+7mntcDVidtny94RQs6I55aAszkScOn3Rf0/kun1t7izWyIbnX QHf2WeOFm1PJPwlLtaHa5ODuCT6ZcjXv1fXg7ZT6fWiLTCMVA1qDAu2SgEYG35j7xIgG ouNKS7xaQQnIhILjgBz2YWdxGCTwyipubL5XZ/ZTJwyzhqzja4MpOPaB/wi89pArqcrY lrdQ== X-Gm-Message-State: AMCzsaURmsItm1WVzpu6ZLzaOrR0/7lpjirJuj1pNEoDW9ciltursJt5 HFEXlrtiKEZETryAp5r248p7FA== X-Google-Smtp-Source: AOwi7QCstJG83k6vLWF9j1ydfZgn2uoyylO5qdg57UI+7Qlu41c9iA2ay7L4LMCj8sWlQKPxsqVsEA== X-Received: by 10.98.236.220 with SMTP id e89mr1692105pfm.219.1507801073369; Thu, 12 Oct 2017 02:37:53 -0700 (PDT) Received: from localhost ([122.172.169.205]) by smtp.gmail.com with ESMTPSA id m69sm28318435pfk.54.2017.10.12.02.37.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Oct 2017 02:37:52 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ulf.hansson@linaro.org, Kevin Hilman Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, sudeep.holla@arm.com, linux-kernel@vger.kernel.org, Len Brown , Pavel Machek , Andy Gross , David Brown Subject: [PATCH V13 1/7] PM / Domains: Add support to select performance-state of domains Date: Thu, 12 Oct 2017 15:07:23 +0530 Message-Id: <990605fb7b17b75abe63c542a4be2e176152b9f6.1507800860.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: <431a7a5803b4a552dfe2a71700e19b904c6d16dc.1507703370.git.viresh.kumar@linaro.org> References: <431a7a5803b4a552dfe2a71700e19b904c6d16dc.1507703370.git.viresh.kumar@linaro.org> 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 PM domains. This patch enhances the genpd core to support such platforms. The performance levels (within the genpd core) are identified by positive integer values, a lower value represents lower performance state. This patch adds a new genpd API, which is called by user drivers (like OPP framework): - int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); This updates the performance state constraint of the device on its PM domain. On success, the genpd will have its performance state set to a value which is >= "state" passed to this routine. The genpd core calls the genpd->set_performance_state() callback, if implemented, else -ENODEV is returned to the caller. The PM domain drivers need to implement the following callback if they want to support performance states. - int (*set_performance_state)(struct generic_pm_domain *genpd, unsigned int state); This is called internally by the genpd core on several occasions. The genpd core passes the genpd pointer and the aggregate of the performance states of the devices supported by that genpd to this callback. This callback must update the performance state of the genpd (in a platform dependent way). The power domains can avoid supplying above callback, if they don't support setting performance-states. Currently we aren't propagating performance state changes of a subdomain to its masters as we don't have hardware that needs it right now. Over that, the performance states of subdomain and its masters may not have one-to-one mapping and would require additional information. We can get back to this once we have hardware that needs it. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- V13: - Don't return directly from a locked section, drop the lock as well. - Update the performance_state field for the device even in the case state == genpd->performance_state. - Always call genpd->set_performance_state() from power-on. - Update device's performance state before traversing the list of devices to find highest state, otherwise we will take previous state of the device into account. - Check state again after traversing the list of devices to see if state changed. drivers/base/power/domain.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 12 ++++++ 2 files changed, 110 insertions(+) -- 2.15.0.rc1.236.g92ea95045093 Reviewed-by: Kevin Hilman diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a6e4c8d7d837..7e01ae364d78 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -237,6 +237,95 @@ static void genpd_update_accounting(struct generic_pm_domain *genpd) static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {} #endif +/** + * dev_pm_genpd_set_performance_state- Set performance state of device's power + * domain. + * + * @dev: Device for which the performance-state needs to be set. + * @state: Target performance state of the device. This can be set as 0 when the + * device doesn't have any performance state constraints left (And so + * the device wouldn't participate anymore to find the target + * performance state of the genpd). + * + * It is assumed that the users guarantee that the genpd wouldn't be detached + * while this routine is getting called. + * + * Returns 0 on success and negative error values on failures. + */ +int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) +{ + struct generic_pm_domain *genpd; + struct generic_pm_domain_data *gpd_data, *pd_data; + struct pm_domain_data *pdd; + unsigned int prev; + int ret = 0; + + genpd = dev_to_genpd(dev); + if (IS_ERR(genpd)) + return -ENODEV; + + if (unlikely(!genpd->set_performance_state)) + return -EINVAL; + + if (unlikely(!dev->power.subsys_data || + !dev->power.subsys_data->domain_data)) { + WARN_ON(1); + return -EINVAL; + } + + genpd_lock(genpd); + + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); + prev = gpd_data->performance_state; + gpd_data->performance_state = state; + + /* New requested state is same as Max requested state */ + if (state == genpd->performance_state) + goto unlock; + + /* New requested state is higher than Max requested state */ + if (state > genpd->performance_state) + goto update_state; + + /* 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; + } + + if (state == genpd->performance_state) + goto unlock; + + /* + * We aren't propagating performance state changes of a subdomain to its + * masters as we don't have hardware that needs it. Over that, the + * performance states of subdomain and its masters may not have + * one-to-one mapping and would require additional information. We can + * get back to this once we have hardware that needs it. For that + * reason, we don't have to consider performance state of the subdomains + * of genpd here. + */ + +update_state: + if (genpd_status_on(genpd)) { + ret = genpd->set_performance_state(genpd, state); + if (ret) { + gpd_data->performance_state = prev; + goto unlock; + } + } + + genpd->performance_state = state; + +unlock: + genpd_unlock(genpd); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_set_performance_state); + static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { unsigned int state_idx = genpd->state_idx; @@ -256,6 +345,15 @@ static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) return ret; elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); + + if (unlikely(genpd->set_performance_state)) { + ret = genpd->set_performance_state(genpd, genpd->performance_state); + if (ret) { + pr_warn("%s: Failed to set performance state %d (%d)\n", + genpd->name, genpd->performance_state, ret); + } + } + if (elapsed_ns <= genpd->states[state_idx].power_on_latency_ns) return ret; diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 84f423d5633e..9af0356bd69c 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -64,8 +64,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; /* Aggregated max 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 *genpd, + unsigned int state); struct gpd_dev_ops dev_ops; s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ bool max_off_time_changed; @@ -121,6 +124,7 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; + unsigned int performance_state; void *data; }; @@ -148,6 +152,8 @@ extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, extern int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); extern int pm_genpd_remove(struct generic_pm_domain *genpd); +extern int dev_pm_genpd_set_performance_state(struct device *dev, + unsigned int state); extern struct dev_power_governor simple_qos_governor; extern struct dev_power_governor pm_domain_always_on_gov; @@ -188,6 +194,12 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) return -ENOTSUPP; } +static inline int dev_pm_genpd_set_performance_state(struct device *dev, + unsigned int state) +{ + return -ENOTSUPP; +} + #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) #endif