Devfreq cooling device
Subsystems (3)
v3 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 v2:
- Use the opp library to enable/disable opps instead of exporting
devfreq_set_{max,min} - Use idr API to get a unique name for each devfreq cooling device registered.
Changes since v1:
- Rename devfreq_qos_set_[max|min] to devfreq_set_[max|min] as suggested by MyungJoo Ham
- Calculate devfreq load in the tracepoint so that it only happens when the trace is enabled. Thanks Steven Rostedt.
Javi Merino (2):
PM / devfreq: cache the last call to get_dev_status()
devfreq_cooling: add trace information
Ørjan Eide (1):
thermal: Add devfreq cooling
drivers/devfreq/devfreq.c | 5 + drivers/devfreq/governor_simpleondemand.c | 33 ++- drivers/thermal/Kconfig | 10 + drivers/thermal/Makefile | 3 + drivers/thermal/devfreq_cooling.c | 472 ++++++++++++++++++++++++++++++ include/linux/devfreq.h | 8 + include/linux/devfreq_cooling.h | 93 ++++++ include/trace/events/thermal.h | 53 ++++ 8 files changed, 662 insertions(+), 15 deletions(-) create mode 100644 drivers/thermal/devfreq_cooling.c create mode 100644 include/linux/devfreq_cooling.h
Signature · 1 line
1.9.1
PATCH v3 1/3 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.
---
This patch tries to let multiple components use the infromation from get_dev_status(). To summarize the discussion in v1[1] I can think of three alternatives:
1) Change get_dev_status() to return absolute values for busy_time and total_time
2) Make core devfreq call get_dev_status() periodically (for example, before calling the governor) and all the entities that want access can do so via a pointer in devfreq
3) Cache the periodic call that the simple ondemand governor does periodically and cache it, forcing all the other entities to rely on that governor being active
This patch implements option 3)
[1] http://thread.gmane.org/gmane.linux.power-management.general/61936/focus=61993
drivers/devfreq/devfreq.c | 5 +++++ drivers/devfreq/governor_simpleondemand.c | 33 +++++++++++++++++-------------- include/linux/devfreq.h | 8 ++++++++ 3 files changed, 31 insertions(+), 15 deletions(-)
drivers/devfreq/devfreq.c +5 -0
@@ -768,6 +768,11 @@ err_out: }EXPORT_SYMBOL (devfreq_remove_governor); +int devfreq_update_stats (struct devfreq *df) +{ +return df->profile->get_dev_status (df->dev.parent, &df->last_status); +} +static ssize_t governor_show (struct device *dev,struct device_attribute *attr,char *buf) {
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 +8 -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,8 @@ extern int devm_devfreq_register_opp_notifier(struct device *dev,extern void devm_devfreq_unregister_opp_notifier (struct device *dev,struct devfreq *devfreq); +int devfreq_update_stats (struct devfreq *df); +#if IS_ENABLED (CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND )/** * struct devfreq_simple_ondemand_data - void *data fed to struct devfreq
@@ -289,6 +292,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 v3 2/3 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.
---
Changes since v2:
- Use the opp library to enable/disable opps instead of exporting
devfreq_set_{max,min}- Use idr API to get a unique name for each devfreq cooling device registered.
drivers/thermal/Kconfig | 10 + drivers/thermal/Makefile | 3 + drivers/thermal/devfreq_cooling.c | 466 ++++++++++++++++++++++++++++++++++++++ include/linux/devfreq_cooling.h | 93 ++++++++ 4 files changed, 572 insertions(+) create mode 100644 drivers/thermal/devfreq_cooling.c create mode 100644 include/linux/devfreq_cooling.h
drivers/thermal/Kconfig +10 -0
@@ -147,6 +147,16 @@ 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 + 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. + 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 +466 -0
466 lines not on this page · raw message
include/linux/devfreq_cooling.h new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 3/3 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
@@ -21,6 +21,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);
@@ -210,6 +212,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 ;
@@ -263,6 +268,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