Devfreq cooling device
Subsystems (7)
v6 cover Devfreq cooling device
This series introduces a devfreq cooling device in the thermal framework. Devfreq is used for DVFS for devices other than the CPUs. With a devfreq cooling device, the thermal framework can throttle them to control temperature. The cooling device has the power extensions, so it can be used by all governors in the thermal framework, including the power allocator governor.
Changes since v5:
- s/enable_disable_opps()/partition_enable_opps()
- Check the state in devfreq_cooling_state2power()
- Make the printing of the dynamic power table a dev_dbg printk
- Remove the warning of simple ondemand devfreq governor from the code and document it in the Kconfig entry.
- Change the name of the cooling device to thermal-devfreq-X
- s/EXPORT_SYMBOL/EXPORT_SYMBOL_GPL/
- Use a simple dynamic power model if no dynamic power model is supplied.
Changes since v4:
- Don't introduce a new function in the OPP library and instead fix dev_pm_opp_get_voltage() as suggested by Viresh Kumar
- Don't allocate memory under RCU
- Don't call dev_pm_opp_enable/disable under RCU
- Generate the frequency table even if the power extensions were not provided
Changes since v3:
- Made devfreq_update_stats() a static inline function
- Add dev_pm_get_voltage_always() to get the voltage even for disabled OPPs
- Don't rely on freq_table from the devfreq->profile being present and create our own
- Don't use devm_k* to allocate memory
- Move struct devfreq_cooling_register to devfreq_cooling.c
Javi Merino (4):
PM / devfreq: cache the last call to get_dev_status() PM / OPP: get the voltage for all OPPs
devfreq_cooling: add trace information
PM / devfreq: drop comment about thermal setting max_freq
Ørjan Eide (1):
thermal: Add devfreq cooling
drivers/base/power/opp.c | 4 +- drivers/devfreq/devfreq.c | 6 +- drivers/devfreq/governor_simpleondemand.c | 33 +- drivers/thermal/Kconfig | 14 + drivers/thermal/Makefile | 3 + drivers/thermal/devfreq_cooling.c | 569 ++++++++++++++++++++++++++++++ include/linux/devfreq.h | 15 + include/linux/devfreq_cooling.h | 81 +++++ include/trace/events/thermal.h | 53 +++ 9 files changed, 758 insertions(+), 20 deletions(-) create mode 100644 drivers/thermal/devfreq_cooling.c create mode 100644 include/linux/devfreq_cooling.h
Signature · 1 line
1.9.1
PATCH v6 1/5 PM / devfreq: cache the last call to get_dev_status()
The return value of get_dev_status() can be reused. Cache it so that other parts of the kernel can reuse it instead of having to call the same function again.
---
Hi MyungJoo,
The patches in this series haven't changed from what you have in your tree. I'm only including them because they're not yet in mainline.
drivers/devfreq/governor_simpleondemand.c | 33 +++++++++++++++++-------------- include/linux/devfreq.h | 15 ++++++++++++++ 2 files changed, 33 insertions(+), 15 deletions(-)
drivers/devfreq/governor_simpleondemand.c +18 -15
@@ -21,17 +21,20 @@static int devfreq_simple_ondemand_func (struct devfreq *df,unsigned long *freq) { -struct devfreq_dev_status stat; -int err = df->profile->get_dev_status (df->dev.parent, &stat); +int err; +struct devfreq_dev_status *stat;unsigned long long a, b;unsigned int dfso_upthreshold =DFSO_UPTHRESHOLD ;unsigned int dfso_downdifferential =DFSO_DOWNDIFFERENCTIAL ;struct devfreq_simple_ondemand_data *data = df->data;unsigned long max = (df->max_freq) ? df->max_freq :UINT_MAX ; + err =devfreq_update_stats (df);if (err)return err; + stat = &df->last_status; +if (data) {if (data->upthreshold) dfso_upthreshold = data->upthreshold;
@@ -43,41 +46,41 @@ static int devfreq_simple_ondemand_func(struct devfreq *df,return -EINVAL ;/* Assume MAX if it is going to be divided by zero */ -if (stat.total_time ==0 ) { +if (stat->total_time ==0 ) { *freq = max;return 0 ; }/* Prevent overflow */ -if (stat.busy_time >= (1 <<24 ) || stat.total_time >= (1 <<24 )) { - stat.busy_time >>=7 ; - stat.total_time >>=7 ; +if (stat->busy_time >= (1 <<24 ) || stat->total_time >= (1 <<24 )) { + stat->busy_time >>=7 ; + stat->total_time >>=7 ; }/* Set MAX if it's busy enough */ -if (stat.busy_time *100 > - stat.total_time * dfso_upthreshold) { +if (stat->busy_time *100 > + stat->total_time * dfso_upthreshold) { *freq = max;return 0 ; }/* Set MAX if we do not know the initial frequency */ -if (stat.current_frequency ==0 ) { +if (stat->current_frequency ==0 ) { *freq = max;return 0 ; }/* Keep the current frequency */ -if (stat.busy_time *100 > - stat.total_time * (dfso_upthreshold - dfso_downdifferential)) { - *freq = stat.current_frequency; +if (stat->busy_time *100 > + stat->total_time * (dfso_upthreshold - dfso_downdifferential)) { + *freq = stat->current_frequency;return 0 ; }/* Set the desired frequency based on the load */ - a = stat.busy_time; - a *= stat.current_frequency; - b =div_u64 (a, stat.total_time); + a = stat->busy_time; + a *= stat->current_frequency; + b =div_u64 (a, stat->total_time); b *=100 ; b =div_u64 (b, (dfso_upthreshold - dfso_downdifferential /2 )); *freq = (unsigned long ) b;
include/linux/devfreq.h +15 -0
@@ -161,6 +161,7 @@ struct devfreq {struct delayed_work work;unsigned long previous_freq; +struct devfreq_dev_status last_status;void *data;/* private data for governors */
@@ -204,6 +205,15 @@ extern int devm_devfreq_register_opp_notifier(struct device *dev,extern void devm_devfreq_unregister_opp_notifier (struct device *dev,struct devfreq *devfreq); +/** +* devfreq_update_stats() - update the last_status pointer in struct devfreq +* @df: the devfreq instance whose status needs updating +*/ +static inline int devfreq_update_stats (struct devfreq *df) +{ +return df->profile->get_dev_status (df->dev.parent, &df->last_status); +} +#if IS_ENABLED (CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND )/** * struct devfreq_simple_ondemand_data - void *data fed to struct devfreq
@@ -289,6 +299,11 @@ static inline void devm_devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) { } + +static inline int devfreq_update_stats (struct devfreq *df) +{ +return -EINVAL ; +}#endif /* CONFIG_PM_DEVFREQ */ #endif /* __LINUX_DEVFREQ_H__ */
Signature · 1 line
1.9.1
PATCH v6 2/5 PM / OPP: get the voltage for all OPPs
In reply to Javi MerinoThe OPP library is now used for power models to calculate the power that a device would consume at a specific OPP. To do that, we use a simple power model which takes frequency and voltage as inputs. We get the voltage and frequency from the OPP library.
The devfreq cooling device for the thermal framework controls temperature by disabling OPPs. The power model needs to calculate the power that would be consumed if we reenabled the OPP. Therefore, let dev_pm_opp_get_voltage() work for disabled OPPs.
--- drivers/base/power/opp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/power/opp.c +2 -2
@@ -217,7 +217,7 @@ static struct device_opp *_find_device_opp(struct device *dev) }/** -* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an available opp +* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp * @opp: opp for which voltage has to be returned for * * Return: voltage in micro volt corresponding to the opp, else
@@ -239,7 +239,7 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)opp_rcu_lockdep_assert (); tmp_opp =rcu_dereference (opp); -if (IS_ERR_OR_NULL (tmp_opp) || !tmp_opp->available) +if (IS_ERR_OR_NULL (tmp_opp))pr_err ("%s: Invalid parameters\n" , __func__);else v = tmp_opp->u_volt;
Signature · 1 line
1.9.1
PATCH v6 3/5 thermal: Add devfreq cooling
In reply to Javi MerinoFrom: Ørjan Eide <[email protected]>
Add a generic thermal cooling device for devfreq, that is similar to cpu_cooling.
The device must use devfreq. In order to use the power extension of the cooling device, it must have registered its OPPs using the OPP library.
--- drivers/thermal/Kconfig | 14 + drivers/thermal/Makefile | 3 + drivers/thermal/devfreq_cooling.c | 563 ++++++++++++++++++++++++++++++++++++++ include/linux/devfreq_cooling.h | 81 ++++++ 4 files changed, 661 insertions(+) create mode 100644 drivers/thermal/devfreq_cooling.c create mode 100644 include/linux/devfreq_cooling.h
drivers/thermal/Kconfig +14 -0
@@ -147,6 +147,20 @@ config CLOCK_THERMAL device that is configured to use this cooling mechanism will be controlled to reduce clock frequency whenever temperature is high. +config DEVFREQ_THERMAL + bool "Generic device cooling support" + depends on PM_DEVFREQ + depends on PM_OPP + help + This implements the generic devfreq cooling mechanism through + frequency reduction for devices using devfreq. + + This will throttle the device by limiting the maximum allowed DVFS + frequency corresponding to the cooling level. + + In order to use the power extensions of the cooling device, + devfreq should use the simple_ondemand governor. + If you want this support, you should say Y here. config THERMAL_EMULATION
drivers/thermal/Makefile +3 -0
@@ -22,6 +22,9 @@ thermal_sys-$(CONFIG_CPU_THERMAL) += cpu_cooling.o # clock cooling thermal_sys-$(CONFIG_CLOCK_THERMAL) += clock_cooling.o +# devfreq cooling +thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o + # platform thermal drivers obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
drivers/thermal/devfreq_cooling.c new file +563 -0
563 lines not on this page · raw message
include/linux/devfreq_cooling.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 4/5 devfreq_cooling: add trace information
In reply to Javi MerinoTracing is useful for debugging and performance tuning. Add similar traces to what's present in the cpu cooling device.
--- drivers/thermal/devfreq_cooling.c | 6 +++++ include/trace/events/thermal.h | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
drivers/thermal/devfreq_cooling.c +6 -0
@@ -25,6 +25,8 @@#include <linux/pm_opp.h> #include <linux/thermal.h> +#include <trace/events/thermal.h> +static DEFINE_MUTEX (devfreq_lock);static DEFINE_IDR (devfreq_idr);
@@ -293,6 +295,9 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd/* Get static power */ static_power =get_static_power (dfc, freq); +trace_thermal_power_devfreq_get_power (cdev, status, freq, dyn_power, + static_power); + *power = dyn_power + static_power;return 0 ;
@@ -348,6 +353,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,break ; *state = i; +trace_thermal_power_devfreq_limit (cdev, freq, *state, power);return 0 ; }
include/trace/events/thermal.h +53 -0
65 lines not on this page · raw message
Signature · 1 line
1.9.1
Steven Rostedt
maintainerRe: [PATCH v6 4/5] devfreq_cooling: add trace information
Quoted 37 lines · On Thu, 10 Sep 2015 18:09:31 +0100 Javi Merino <[email protected]> wrote:
Tracing is useful for debugging and performance tuning. Add similar traces to what's present in the cpu cooling device.
Cc Zhang Rui <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>Signed-off-by Javi Merino <[email protected]>--- drivers/thermal/devfreq_cooling.c | 6 +++++ include/trace/events/thermal.h | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)drivers/thermal/devfreq_cooling.c +5
-0@@ -25,6 +25,8 @@#include <linux/pm_opp.h> #include <linux/thermal.h> +#include <trace/events/thermal.h> +static DEFINE_MUTEX (devfreq_lock);static DEFINE_IDR (devfreq_idr);@@ -293,6 +295,9 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd/* Get static power */ static_power =get_static_power (dfc, freq); +trace_thermal_power_devfreq_get_power (cdev, status, freq, dyn_power, + static_power); + *power = dyn_power + static_power;return 0 ;
drivers/thermal/devfreq_cooling.c static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · line 356
Quoted 4 lines
drivers/thermal/devfreq_cooling.c +1
-0@@ -348,6 +353,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,break ; *state = i; +trace_thermal_power_devfreq_limit (cdev, freq, *state, power);
I'm curious, does changing the above to:
trace_thermal_power_devfreq_limit(cdev, freq, i, power);
make the compiled code better?
A tracepoint does some whacky things, and gcc may not optimize this.
The rest looks fine to me.
-- Steve
drivers/thermal/devfreq_cooling.c static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · line 358
Quoted 2 lines
drivers/thermal/devfreq_cooling.c +0
-0return 0 ; }
\
Re: [PATCH v6 4/5] devfreq_cooling: add trace information
Hi Steve,
Quoted 47 lines · Steven Rostedt
Quoted 37 lines · On Thu, 10 Sep 2015 18:09:31 +0100 Javi Merino <[email protected]> wrote:
Tracing is useful for debugging and performance tuning. Add similar traces to what's present in the cpu cooling device.
Cc Zhang Rui <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>Signed-off-by Javi Merino <[email protected]>--- drivers/thermal/devfreq_cooling.c | 6 +++++ include/trace/events/thermal.h | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)drivers/thermal/devfreq_cooling.c +5
-0@@ -25,6 +25,8 @@#include <linux/pm_opp.h> #include <linux/thermal.h> +#include <trace/events/thermal.h> +static DEFINE_MUTEX (devfreq_lock);static DEFINE_IDR (devfreq_idr);@@ -293,6 +295,9 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd/* Get static power */ static_power =get_static_power (dfc, freq); +trace_thermal_power_devfreq_get_power (cdev, status, freq, dyn_power, + static_power); + *power = dyn_power + static_power;return 0 ;drivers/thermal/devfreq_cooling.c static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · line 356
Quoted 4 lines
drivers/thermal/devfreq_cooling.c +1
-0@@ -348,6 +353,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,break ; *state = i; +trace_thermal_power_devfreq_limit (cdev, freq, *state, power);I'm curious, does changing the above to:
Quoted 5 lines
trace_thermal_power_devfreq_limit(cdev, freq, i, power);make the compiled code better?
A tracepoint does some whacky things, and gcc may not optimize this.
I've compared the generated assembly on arm, arm64 and x86_64 and both options generate exactly the same code.
Cheers,
Javi
Steven Rostedt
maintainerRe: [PATCH v6 4/5] devfreq_cooling: add trace information
Quoted 4 lines · On Fri, 18 Sep 2015 14:55:51 +0100 Javi Merino <[email protected]> wrote:
Quoted 1 line
A tracepoint does some whacky things, and gcc may not optimize this.
I've compared the generated assembly on arm, arm64 and
x86_64and both options generate exactly the same code.
Thanks for checking. I was just curious, and I'm wary about trusting gcc to optimize correctly ;-)
-- Steve
Re: [PATCH v6 4/5] devfreq_cooling: add trace information
In reply to Steven RostedtHi Steve,
Quoted 47 lines · Steven Rostedt
Quoted 37 lines · On Thu, 10 Sep 2015 18:09:31 +0100 Javi Merino <[email protected]> wrote:
Tracing is useful for debugging and performance tuning. Add similar traces to what's present in the cpu cooling device.
Cc Zhang Rui <[email protected]>Cc Eduardo Valentin <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>Signed-off-by Javi Merino <[email protected]>--- drivers/thermal/devfreq_cooling.c | 6 +++++ include/trace/events/thermal.h | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)drivers/thermal/devfreq_cooling.c +5
-0@@ -25,6 +25,8 @@#include <linux/pm_opp.h> #include <linux/thermal.h> +#include <trace/events/thermal.h> +static DEFINE_MUTEX (devfreq_lock);static DEFINE_IDR (devfreq_idr);@@ -293,6 +295,9 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd/* Get static power */ static_power =get_static_power (dfc, freq); +trace_thermal_power_devfreq_get_power (cdev, status, freq, dyn_power, + static_power); + *power = dyn_power + static_power;return 0 ;drivers/thermal/devfreq_cooling.c static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · line 356
Quoted 4 lines
drivers/thermal/devfreq_cooling.c +1
-0@@ -348,6 +353,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,break ; *state = i; +trace_thermal_power_devfreq_limit (cdev, freq, *state, power);I'm curious, does changing the above to:
Quoted 7 lines
trace_thermal_power_devfreq_limit(cdev, freq, i, power);make the compiled code better?
A tracepoint does some whacky things, and gcc may not optimize this.
The rest looks fine to me.
Can I treat that last statement as an Acked-by?
Steven Rostedt
maintainerRe: [PATCH v6 4/5] devfreq_cooling: add trace information
Quoted 3 lines · On Wed, 14 Oct 2015 12:53:30 +0100 Javi Merino <[email protected]> wrote:
Quoted 1 line
The rest looks fine to me.
Can I treat that last statement as an Acked-by?
Sure, why not ;-)
-- Steve
PATCH v6 5/5 PM / devfreq: drop comment about thermal setting max_freq
In reply to Javi MerinoThe thermal infrastructure should use the devfreq cooling device, which uses the OPP library to disable OPPs as necessary.
Fix a couple of typos in the same comment while we are at it.
---
Hi MyungJoo,
The patches in this series haven't changed from what you have in your tree. I'm only including them because they're not yet in mainline.
drivers/devfreq/devfreq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/devfreq/devfreq.c +3 -3
@@ -177,10 +177,10 @@ int update_devfreq(struct devfreq *devfreq)return err;/* -* Adjust the freuqency with user freq and QoS. +* Adjust the frequency with user freq and QoS. * -* List from the highest proiority -* max_freq (probably called by thermal when it's too hot) +* List from the highest priority +* max_freq * min_freq */
Signature · 1 line
1.9.1