From: Quentin Perret <quentin.perret@arm.com>
To: linux-pm@vger.kernel.org
Cc: rjw@rjwysocki.net, vireshk@kernel.org, nm@ti.com,
sboyd@codeaurora.org, sudeep.holla@arm.com,
amit.kachhap@gmail.com, javi.merino@kernel.org,
rui.zhang@intel.com, edubezval@gmail.com, matthias.bgg@gmail.com,
dietmar.eggemann@arm.com, morten.rasmussen@arm.com,
patrick.bellasi@arm.com, ionela.voinescu@arm.com,
joelaf@google.com, tkjos@google.com,
Quentin Perret <quentin.perret@arm.com>
Subject: [PATCH v3 2/2] thermal: cpu_cooling: use power models from the OPP library
Date: Fri, 19 Jan 2018 09:45:49 +0000 [thread overview]
Message-ID: <20180119094549.5468-3-quentin.perret@arm.com> (raw)
In-Reply-To: <20180119094549.5468-1-quentin.perret@arm.com>
Now that the OPP library features a power estimator, the existing code
in IPA can be modified to rely only on dev_pm_opp_get_power() without
having to care about the dynamic-power-coefficient DT binding.
Signed-off-by: Quentin Perret <quentin.perret@arm.com>
---
drivers/thermal/cpu_cooling.c | 56 ++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index dfd23245f778..8eda2de2a20d 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -187,7 +187,8 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
/**
* update_freq_table() - Update the freq table with power numbers
* @cpufreq_cdev: the cpufreq cooling device in which to update the table
- * @capacitance: dynamic power coefficient for these cpus
+ * @found_power: boolean indicating if a power model was available for
+ * the cooling device
*
* Update the freq table with power numbers. This table will be used in
* cpu_power_to_freq() and cpu_freq_to_power() to convert between power and
@@ -198,7 +199,7 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
* or -ENOMEM if we run out of memory.
*/
static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev,
- u32 capacitance)
+ bool *found_power)
{
struct freq_table *freq_table = cpufreq_cdev->freq_table;
struct dev_pm_opp *opp;
@@ -225,11 +226,10 @@ static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev,
return -EINVAL;
}
+ *found_power = true;
+
for (i = 0; i <= cpufreq_cdev->max_level; i++) {
- unsigned long freq = freq_table[i].frequency * 1000;
- u32 freq_mhz = freq_table[i].frequency / 1000;
- u64 power;
- u32 voltage_mv;
+ unsigned long power, freq = freq_table[i].frequency * 1000;
/*
* Find ceil frequency as 'freq' may be slightly lower than OPP
@@ -242,18 +242,12 @@ static int update_freq_table(struct cpufreq_cooling_device *cpufreq_cdev,
return -EINVAL;
}
- voltage_mv = dev_pm_opp_get_voltage(opp) / 1000;
- dev_pm_opp_put(opp);
-
- /*
- * Do the multiplication with MHz and millivolt so as
- * to not overflow.
- */
- power = (u64)capacitance * freq_mhz * voltage_mv * voltage_mv;
- do_div(power, 1000000000);
-
/* power is stored in mW */
+ power = dev_pm_opp_get_power(opp) / 1000;
+ dev_pm_opp_put(opp);
freq_table[i].power = power;
+ if (!power)
+ *found_power = false;
}
return 0;
@@ -594,7 +588,6 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
* @np: a valid struct device_node to the cooling device device tree node
* @policy: cpufreq policy
* Normally this should be same as cpufreq policy->related_cpus.
- * @capacitance: dynamic power coefficient for these cpus
*
* This interface function registers the cpufreq cooling device with the name
* "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
@@ -606,7 +599,7 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
*/
static struct thermal_cooling_device *
__cpufreq_cooling_register(struct device_node *np,
- struct cpufreq_policy *policy, u32 capacitance)
+ struct cpufreq_policy *policy)
{
struct thermal_cooling_device *cdev;
struct cpufreq_cooling_device *cpufreq_cdev;
@@ -614,7 +607,7 @@ __cpufreq_cooling_register(struct device_node *np,
unsigned int freq, i, num_cpus;
int ret;
struct thermal_cooling_device_ops *cooling_ops;
- bool first;
+ bool first, found_power;
if (IS_ERR_OR_NULL(policy)) {
pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy);
@@ -675,18 +668,15 @@ __cpufreq_cooling_register(struct device_node *np,
pr_debug("%s: freq:%u KHz\n", __func__, freq);
}
- if (capacitance) {
- ret = update_freq_table(cpufreq_cdev, capacitance);
- if (ret) {
- cdev = ERR_PTR(ret);
- goto remove_ida;
- }
-
- cooling_ops = &cpufreq_power_cooling_ops;
- } else {
- cooling_ops = &cpufreq_cooling_ops;
+ ret = update_freq_table(cpufreq_cdev, &found_power);
+ if (ret) {
+ cdev = ERR_PTR(ret);
+ goto remove_ida;
}
+ cooling_ops = found_power ? &cpufreq_power_cooling_ops :
+ &cpufreq_cooling_ops;
+
cdev = thermal_of_cooling_device_register(np, dev_name, cpufreq_cdev,
cooling_ops);
if (IS_ERR(cdev))
@@ -732,7 +722,7 @@ __cpufreq_cooling_register(struct device_node *np,
struct thermal_cooling_device *
cpufreq_cooling_register(struct cpufreq_policy *policy)
{
- return __cpufreq_cooling_register(NULL, policy, 0);
+ return __cpufreq_cooling_register(NULL, policy);
}
EXPORT_SYMBOL_GPL(cpufreq_cooling_register);
@@ -760,7 +750,6 @@ of_cpufreq_cooling_register(struct cpufreq_policy *policy)
{
struct device_node *np = of_get_cpu_node(policy->cpu, NULL);
struct thermal_cooling_device *cdev = NULL;
- u32 capacitance = 0;
if (!np) {
pr_err("cpu_cooling: OF node not available for cpu%d\n",
@@ -769,10 +758,7 @@ of_cpufreq_cooling_register(struct cpufreq_policy *policy)
}
if (of_find_property(np, "#cooling-cells", NULL)) {
- of_property_read_u32(np, "dynamic-power-coefficient",
- &capacitance);
-
- cdev = __cpufreq_cooling_register(np, policy, capacitance);
+ cdev = __cpufreq_cooling_register(np, policy);
if (IS_ERR(cdev)) {
pr_err("cpu_cooling: cpu%d is not running as cooling device: %ld\n",
policy->cpu, PTR_ERR(cdev));
--
2.15.1
next prev parent reply other threads:[~2018-01-19 9:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-19 9:45 [PATCH v3 0/2] thermal, OPP: move the CPU power estimation to the OPP library Quentin Perret
2018-01-19 9:45 ` [PATCH v3 1/2] PM / OPP: introduce an OPP power estimation helper Quentin Perret
2018-01-19 23:36 ` Joel Fernandes
2018-01-22 5:12 ` Viresh Kumar
2018-01-22 10:00 ` Quentin Perret
2018-01-20 4:10 ` Joel Fernandes
2018-01-22 9:56 ` Quentin Perret
2018-01-22 21:33 ` Joel Fernandes
2018-01-19 9:45 ` Quentin Perret [this message]
2018-01-19 23:15 ` [PATCH v3 2/2] thermal: cpu_cooling: use power models from the OPP library Joel Fernandes
2018-01-22 5:11 ` Viresh Kumar
2018-01-22 21:30 ` Joel Fernandes
2018-01-23 2:47 ` Viresh Kumar
2018-01-22 11:03 ` Quentin Perret
2018-01-19 10:12 ` [PATCH v3 0/2] thermal, OPP: move the CPU power estimation to " Viresh Kumar
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=20180119094549.5468-3-quentin.perret@arm.com \
--to=quentin.perret@arm.com \
--cc=amit.kachhap@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=edubezval@gmail.com \
--cc=ionela.voinescu@arm.com \
--cc=javi.merino@kernel.org \
--cc=joelaf@google.com \
--cc=linux-pm@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=morten.rasmussen@arm.com \
--cc=nm@ti.com \
--cc=patrick.bellasi@arm.com \
--cc=rjw@rjwysocki.net \
--cc=rui.zhang@intel.com \
--cc=sboyd@codeaurora.org \
--cc=sudeep.holla@arm.com \
--cc=tkjos@google.com \
--cc=vireshk@kernel.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).