From patchwork Wed Oct 28 14:08:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 314841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD72C56201 for ; Wed, 28 Oct 2020 22:28:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5A5920714 for ; Wed, 28 Oct 2020 22:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387449AbgJ1W2d (ORCPT ); Wed, 28 Oct 2020 18:28:33 -0400 Received: from foss.arm.com ([217.140.110.172]:40032 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733218AbgJ1W1P (ORCPT ); Wed, 28 Oct 2020 18:27:15 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0F0BB177F; Wed, 28 Oct 2020 07:09:20 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.12.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 133353F66E; Wed, 28 Oct 2020 07:09:16 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, vireshk@kernel.org, robh+dt@kernel.org Cc: sboyd@kernel.org, nm@ti.com, rafael@kernel.org, sudeep.holla@arm.com, daniel.lezcano@linaro.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com Subject: [PATCH 1/4] dt-bindings: opp: Introduce opp-sustainable bindings Date: Wed, 28 Oct 2020 14:08:44 +0000 Message-Id: <20201028140847.1018-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201028140847.1018-1-lukasz.luba@arm.com> References: <20201028140847.1018-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add opp-sustainable as an additional property in the OPP node to describe the sustainable performance level of the device. This will help to estimate the sustainable performance of the whole system. Signed-off-by: Lukasz Luba --- Documentation/devicetree/bindings/opp/opp.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/opp/opp.txt b/Documentation/devicetree/bindings/opp/opp.txt index 9847dfeeffcb..cd01028de305 100644 --- a/Documentation/devicetree/bindings/opp/opp.txt +++ b/Documentation/devicetree/bindings/opp/opp.txt @@ -154,6 +154,10 @@ Optional properties: - opp-suspend: Marks the OPP to be used during device suspend. If multiple OPPs in the table have this, the OPP with highest opp-hz will be used. +- opp-sustainable: Marks the OPP as sustainable. This property can be used for + estimating sustainable performance of the whole system. If multiple OPPs in + the table have this, the OPP with highest opp-hz will be used. + - opp-supported-hw: This property allows a platform to enable only a subset of the OPPs from the larger set present in the OPP table, based on the current version of the hardware (already known to the operating system). From patchwork Wed Oct 28 14:08:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 314822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30F2BC388F7 for ; Thu, 29 Oct 2020 00:32:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E24AF206BE for ; Thu, 29 Oct 2020 00:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733261AbgJ1W2p (ORCPT ); Wed, 28 Oct 2020 18:28:45 -0400 Received: from foss.arm.com ([217.140.110.172]:40034 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733185AbgJ1W10 (ORCPT ); Wed, 28 Oct 2020 18:27:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 21ABC19BF; Wed, 28 Oct 2020 07:09:23 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.12.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6FE6B3F66E; Wed, 28 Oct 2020 07:09:20 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, vireshk@kernel.org, robh+dt@kernel.org Cc: sboyd@kernel.org, nm@ti.com, rafael@kernel.org, sudeep.holla@arm.com, daniel.lezcano@linaro.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com Subject: [PATCH 2/4] OPP: Add support for parsing the 'opp-sustainable' property Date: Wed, 28 Oct 2020 14:08:45 +0000 Message-Id: <20201028140847.1018-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201028140847.1018-1-lukasz.luba@arm.com> References: <20201028140847.1018-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Now that the OPP bindings are updated to include an optional 'opp-sustainable' property, add support to parse it from device tree and store it as part of dev_pm_opp structure. Also add and export an helper 'dev_pm_opp_get_sustainable()' that can be used to get the sustainable OPP when present. Signed-off-by: Lukasz Luba --- drivers/opp/core.c | 26 ++++++++++++++++++++++++++ drivers/opp/of.c | 14 ++++++++++++++ drivers/opp/opp.h | 3 +++ include/linux/pm_opp.h | 6 ++++++ 4 files changed, 49 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 9915e8487f0b..bb1e68b96d0e 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -299,6 +299,32 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq); +/** + * dev_pm_opp_get_sustainable_opp_freq() - Get frequency of sustainable opp + * in Hz + * @dev: device for which we do this operation + * + * Return: This function returns the frequency of the OPP marked as + * sustainable_opp if one is available, else returns 0; + */ +unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev) +{ + struct opp_table *opp_table; + unsigned long freq = 0; + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return 0; + + if (opp_table->sustainable_opp && opp_table->sustainable_opp->available) + freq = dev_pm_opp_get_freq(opp_table->sustainable_opp); + + dev_pm_opp_put_opp_table(opp_table); + + return freq; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_sustainable_opp_freq); + int _get_opp_count(struct opp_table *opp_table) { struct dev_pm_opp *opp; diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 9faeb83e4b32..1f6b19bb1a95 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -815,6 +815,20 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, } } + if (of_property_read_bool(np, "opp-sustainable")) { + if (opp_table->sustainable_opp) { + /* Pick the OPP with higher rate as sustainable OPP */ + if (new_opp->rate > opp_table->sustainable_opp->rate) { + opp_table->sustainable_opp->sustainable = false; + new_opp->sustainable = true; + opp_table->sustainable_opp = new_opp; + } + } else { + new_opp->sustainable = true; + opp_table->sustainable_opp = new_opp; + } + } + if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index ebd930e0b3ca..45288ccbb295 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -56,6 +56,7 @@ extern struct list_head opp_tables; * @dynamic: not-created from static DT entries. * @turbo: true if turbo (boost) OPP * @suspend: true if suspend OPP + * @sustainable: true if sustainable OPP * @pstate: Device's power domain's performance state. * @rate: Frequency in hertz * @level: Performance level @@ -78,6 +79,7 @@ struct dev_pm_opp { bool dynamic; bool turbo; bool suspend; + bool sustainable; unsigned int pstate; unsigned long rate; unsigned int level; @@ -183,6 +185,7 @@ struct opp_table { unsigned int parsed_static_opps; enum opp_table_access shared_opp; struct dev_pm_opp *suspend_opp; + struct dev_pm_opp *sustainable_opp; struct mutex genpd_virt_dev_lock; struct device **genpd_virt_devs; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index dbb484524f82..363d5a2c1ef3 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -106,6 +106,7 @@ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); +unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev); struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, @@ -215,6 +216,11 @@ static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) return 0; } +static inline unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev) +{ + return 0; +} + static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available) { From patchwork Wed Oct 28 14:08:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 310812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BDAAC56201 for ; Wed, 28 Oct 2020 22:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 333E620725 for ; Wed, 28 Oct 2020 22:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733267AbgJ1W1Y (ORCPT ); Wed, 28 Oct 2020 18:27:24 -0400 Received: from foss.arm.com ([217.140.110.172]:40038 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733250AbgJ1W1X (ORCPT ); Wed, 28 Oct 2020 18:27:23 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C08E19F0; Wed, 28 Oct 2020 07:09:26 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.12.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7C95E3F66E; Wed, 28 Oct 2020 07:09:23 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, vireshk@kernel.org, robh+dt@kernel.org Cc: sboyd@kernel.org, nm@ti.com, rafael@kernel.org, sudeep.holla@arm.com, daniel.lezcano@linaro.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com Subject: [PATCH 3/4] OPP: Add dev_pm_opp_set_sustainable_opp_freq() Date: Wed, 28 Oct 2020 14:08:46 +0000 Message-Id: <20201028140847.1018-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201028140847.1018-1-lukasz.luba@arm.com> References: <20201028140847.1018-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add a new function allowing to set sustainable OPP from the drivers code. This is helpful when the device drivers populate the OPP table by themself. Signed-off-by: Lukasz Luba --- drivers/opp/core.c | 49 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 8 +++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index bb1e68b96d0e..753443f17327 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -325,6 +325,55 @@ unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_sustainable_opp_freq); +/** + * dev_pm_opp_set_sustainable_opp_freq() - Find and set the OPP sustainable + * based on given frequency + * @dev: device for which we do this operation + * @freq: frequency which OPP is going to be marked + * + * Mark the OPP of a given frequency @freq as sustainable_opp. If there is + * already sustainable OPP, choose the highest frequency one and set. + * + * Return: This function return 0 when the new OPP is marked as sustainable + * or error return value, which can be: + * EINVAL: for bad pointer or no match found for frequency search + * EEXIST: if existing sustainable OPP has higher rate + */ +int dev_pm_opp_set_sustainable_opp_freq(struct device *dev, unsigned long freq) +{ + struct opp_table *opp_table; + struct dev_pm_opp *opp; + int ret = 0; + + opp = dev_pm_opp_find_freq_exact(dev, freq, true); + if (IS_ERR_OR_NULL(opp)) + return -EINVAL; + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return -EINVAL; + + if (opp_table->sustainable_opp) { + /* Pick the OPP with higher rate as sustainable OPP */ + if (opp->rate > opp_table->sustainable_opp->rate) { + opp_table->sustainable_opp->sustainable = false; + opp->sustainable = true; + opp_table->sustainable_opp = opp; + } else { + ret = -EEXIST; + } + } else { + opp->sustainable = true; + opp_table->sustainable_opp = opp; + } + + dev_pm_opp_put(opp); + dev_pm_opp_put_opp_table(opp_table); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_sustainable_opp_freq); + int _get_opp_count(struct opp_table *opp_table) { struct dev_pm_opp *opp; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 363d5a2c1ef3..e634a6b00e65 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -107,6 +107,8 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *dev); +int dev_pm_opp_set_sustainable_opp_freq(struct device *dev, + unsigned long freq); struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, @@ -221,6 +223,12 @@ static inline unsigned long dev_pm_opp_get_sustainable_opp_freq(struct device *d return 0; } +static inline int dev_pm_opp_set_sustainable_freq(struct device *dev, + unsigned long freq) +{ + return -EOPNOTSUPP; +} + static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available) { From patchwork Wed Oct 28 14:08:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 314842 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06212C56202 for ; Wed, 28 Oct 2020 22:27:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBFBA20704 for ; Wed, 28 Oct 2020 22:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733226AbgJ1W1Q (ORCPT ); Wed, 28 Oct 2020 18:27:16 -0400 Received: from foss.arm.com ([217.140.110.172]:40028 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733219AbgJ1W1P (ORCPT ); Wed, 28 Oct 2020 18:27:15 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A81C519F6; Wed, 28 Oct 2020 07:09:29 -0700 (PDT) Received: from e123648.arm.com (unknown [10.57.12.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AC01E3F66E; Wed, 28 Oct 2020 07:09:26 -0700 (PDT) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, vireshk@kernel.org, robh+dt@kernel.org Cc: sboyd@kernel.org, nm@ti.com, rafael@kernel.org, sudeep.holla@arm.com, daniel.lezcano@linaro.org, Dietmar.Eggemann@arm.com, lukasz.luba@arm.com Subject: [PATCH 4/4] firmware: arm_scmi/perf: Mark sustainable OPP Date: Wed, 28 Oct 2020 14:08:47 +0000 Message-Id: <20201028140847.1018-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201028140847.1018-1-lukasz.luba@arm.com> References: <20201028140847.1018-1-lukasz.luba@arm.com> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Mark sustainable OPP frequency based on previously received value from the firmware. Signed-off-by: Lukasz Luba --- drivers/firmware/arm_scmi/perf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index 82fb3babff72..a8f3fa1d7f1e 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -669,6 +669,16 @@ static int scmi_dvfs_device_opps_add(const struct scmi_handle *handle, return ret; } } + + if (dom->sustained_freq_khz) { + /* The sustained frequency is always in kHz */ + freq = dom->sustained_freq_khz * 1000; + ret = dev_pm_opp_set_sustainable_opp_freq(dev, freq); + if (ret) + dev_warn(dev, "failed to add sustainable freq=%lu %d\n", + freq, ret); + } + return 0; }