From: Lukasz Luba <lukasz.luba@arm.com>
To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org,
linux-mediatek@lists.infradead.org,
linux-arm-msm@vger.kernel.org, linux-imx@nxp.com
Cc: nm@ti.com, juri.lelli@redhat.com, peterz@infradead.org,
viresh.kumar@linaro.org, liviu.dudau@arm.com,
bjorn.andersson@linaro.org, bsegall@google.com,
Morten.Rasmussen@arm.com, amit.kucheria@verdurent.com,
lorenzo.pieralisi@arm.com, vincent.guittot@linaro.org,
khilman@kernel.org, daniel.lezcano@linaro.org,
steven.price@arm.com, cw00.choi@samsung.com, mingo@redhat.com,
mgorman@suse.de, rui.zhang@intel.com,
alyssa.rosenzweig@collabora.com, orjan.eide@arm.com,
b.zolnierkie@samsung.com, s.hauer@pengutronix.de,
rostedt@goodmis.org, matthias.bgg@gmail.com,
Dietmar.Eggemann@arm.com, airlied@linux.ie, javi.merino@arm.com,
tomeu.vizoso@collabora.com, qperret@google.com, sboyd@kernel.org,
mka@chromium.org, rdunlap@infradead.org, rjw@rjwysocki.net,
agross@kernel.org, kernel@pengutronix.de, sudeep.holla@arm.com,
patrick.bellasi@matbug.net, shawnguo@kernel.org,
lukasz.luba@arm.com
Subject: [PATCH v5 3/5] thermal: devfreq_cooling: Use PM QoS to set frequency limits
Date: Wed, 18 Mar 2020 11:45:46 +0000 [thread overview]
Message-ID: <20200318114548.19916-4-lukasz.luba@arm.com> (raw)
In-Reply-To: <20200318114548.19916-1-lukasz.luba@arm.com>
From: Matthias Kaehlcke <mka@chromium.org>
Now that devfreq supports limiting the frequency range of a device
through PM QoS make use of it instead of disabling OPPs that should
not be used.
The switch from disabling OPPs to PM QoS introduces a subtle behavioral
change in case of conflicting requests (min > max): PM QoS gives
precedence to the MIN_FREQUENCY request, while higher OPPs disabled
with dev_pm_opp_disable() would override MIN_FREQUENCY.
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
---
Added missing Chanwoo's Reviewed-by in posted patch v3.
drivers/thermal/devfreq_cooling.c | 70 ++++++++++---------------------
1 file changed, 23 insertions(+), 47 deletions(-)
diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index a87d4fa031c8..f7f32e98331b 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -24,11 +24,13 @@
#include <linux/idr.h>
#include <linux/slab.h>
#include <linux/pm_opp.h>
+#include <linux/pm_qos.h>
#include <linux/thermal.h>
#include <trace/events/thermal.h>
-#define SCALE_ERROR_MITIGATION 100
+#define HZ_PER_KHZ 1000
+#define SCALE_ERROR_MITIGATION 100
static DEFINE_IDA(devfreq_ida);
@@ -54,6 +56,8 @@ static DEFINE_IDA(devfreq_ida);
* The 'res_util' range is from 100 to (power_table[state] * 100)
* for the corresponding 'state'.
* @capped_state: index to cooling state with in dynamic power budget
+ * @req_max_freq: PM QoS request for limiting the maximum frequency
+ * of the devfreq device.
*/
struct devfreq_cooling_device {
int id;
@@ -66,49 +70,9 @@ struct devfreq_cooling_device {
struct devfreq_cooling_power *power_ops;
u32 res_util;
int capped_state;
+ struct dev_pm_qos_request req_max_freq;
};
-/**
- * partition_enable_opps() - disable all opps above a given state
- * @dfc: Pointer to devfreq we are operating on
- * @cdev_state: cooling device state we're setting
- *
- * Go through the OPPs of the device, enabling all OPPs until
- * @cdev_state and disabling those frequencies above it.
- */
-static int partition_enable_opps(struct devfreq_cooling_device *dfc,
- unsigned long cdev_state)
-{
- int i;
- struct device *dev = dfc->devfreq->dev.parent;
-
- for (i = 0; i < dfc->freq_table_size; i++) {
- struct dev_pm_opp *opp;
- int ret = 0;
- unsigned int freq = dfc->freq_table[i];
- bool want_enable = i >= cdev_state ? true : false;
-
- opp = dev_pm_opp_find_freq_exact(dev, freq, !want_enable);
-
- if (PTR_ERR(opp) == -ERANGE)
- continue;
- else if (IS_ERR(opp))
- return PTR_ERR(opp);
-
- dev_pm_opp_put(opp);
-
- if (want_enable)
- ret = dev_pm_opp_enable(dev, freq);
- else
- ret = dev_pm_opp_disable(dev, freq);
-
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
@@ -135,7 +99,7 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
struct devfreq_cooling_device *dfc = cdev->devdata;
struct devfreq *df = dfc->devfreq;
struct device *dev = df->dev.parent;
- int ret;
+ unsigned long freq;
if (state == dfc->cooling_state)
return 0;
@@ -145,9 +109,10 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
if (state >= dfc->freq_table_size)
return -EINVAL;
- ret = partition_enable_opps(dfc, state);
- if (ret)
- return ret;
+ freq = dfc->freq_table[state];
+
+ dev_pm_qos_update_request(&dfc->req_max_freq,
+ DIV_ROUND_UP(freq, HZ_PER_KHZ));
dfc->cooling_state = state;
@@ -530,9 +495,15 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
if (err)
goto free_dfc;
- err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL);
+ err = dev_pm_qos_add_request(df->dev.parent, &dfc->req_max_freq,
+ DEV_PM_QOS_MAX_FREQUENCY,
+ PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
if (err < 0)
goto free_tables;
+
+ err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL);
+ if (err < 0)
+ goto remove_qos_req;
dfc->id = err;
snprintf(dev_name, sizeof(dev_name), "thermal-devfreq-%d", dfc->id);
@@ -553,6 +524,10 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
release_ida:
ida_simple_remove(&devfreq_ida, dfc->id);
+
+remove_qos_req:
+ dev_pm_qos_remove_request(&dfc->req_max_freq);
+
free_tables:
kfree(dfc->power_table);
kfree(dfc->freq_table);
@@ -601,6 +576,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
thermal_cooling_device_unregister(dfc->cdev);
ida_simple_remove(&devfreq_ida, dfc->id);
+ dev_pm_qos_remove_request(&dfc->req_max_freq);
kfree(dfc->power_table);
kfree(dfc->freq_table);
--
2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-03-19 8:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-18 11:45 [PATCH v5 0/5] Add support for devices in the Energy Model Lukasz Luba
2020-03-18 11:45 ` [PATCH v5 1/5] PM / EM: add devices to " Lukasz Luba
2020-04-03 16:05 ` Daniel Lezcano
2020-04-06 13:29 ` Lukasz Luba
2020-04-06 14:58 ` Daniel Lezcano
2020-04-06 16:07 ` Lukasz Luba
2020-04-06 21:17 ` Daniel Lezcano
2020-04-07 9:32 ` Lukasz Luba
2020-03-18 11:45 ` [PATCH v5 2/5] OPP: refactor dev_pm_opp_of_register_em() and update related drivers Lukasz Luba
2020-04-01 7:19 ` Lukasz Luba
2020-04-03 16:21 ` Daniel Lezcano
2020-04-06 14:05 ` Lukasz Luba
2020-03-18 11:45 ` Lukasz Luba [this message]
2020-04-03 16:43 ` [PATCH v5 3/5] thermal: devfreq_cooling: Use PM QoS to set frequency limits Daniel Lezcano
2020-04-03 17:18 ` Matthias Kaehlcke
2020-04-03 17:19 ` Daniel Lezcano
2020-03-18 11:45 ` [PATCH v5 4/5] thermal: devfreq_cooling: Refactor code and switch to use Energy Model Lukasz Luba
2020-04-01 10:49 ` Lukasz Luba
2020-04-03 17:44 ` Daniel Lezcano
2020-04-06 13:35 ` Lukasz Luba
2020-03-18 11:45 ` [PATCH v5 5/5] drm/panfrost: Register devfreq cooling and attempt to add " Lukasz Luba
2020-03-18 13:11 ` Alyssa Rosenzweig
2020-03-23 13:50 ` Lukasz Luba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200318114548.19916-4-lukasz.luba@arm.com \
--to=lukasz.luba@arm.com \
--cc=Dietmar.Eggemann@arm.com \
--cc=Morten.Rasmussen@arm.com \
--cc=agross@kernel.org \
--cc=airlied@linux.ie \
--cc=alyssa.rosenzweig@collabora.com \
--cc=amit.kucheria@verdurent.com \
--cc=b.zolnierkie@samsung.com \
--cc=bjorn.andersson@linaro.org \
--cc=bsegall@google.com \
--cc=cw00.choi@samsung.com \
--cc=daniel.lezcano@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=javi.merino@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kernel@pengutronix.de \
--cc=khilman@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=lorenzo.pieralisi@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mka@chromium.org \
--cc=nm@ti.com \
--cc=orjan.eide@arm.com \
--cc=patrick.bellasi@matbug.net \
--cc=peterz@infradead.org \
--cc=qperret@google.com \
--cc=rdunlap@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=rostedt@goodmis.org \
--cc=rui.zhang@intel.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
--cc=steven.price@arm.com \
--cc=sudeep.holla@arm.com \
--cc=tomeu.vizoso@collabora.com \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).