thermal: introduce active cooling algorithm
Subsystems (3)
Zhang Rui
reviewerRFC PATCH 6/12 thermal: introduce active cooling algorithm
Introduce thermal_zone_trip_update() to update the cooling state of all the cooling devices that are binded to an active trip point.
This will be used for passive cooling as well, in the future patches. as both active and passive cooling can share the same algorithm, which is
1. if the temperature is higher than a trip point,
a. if the trend is THERMAL_TREND_RAISING, use higher cooling
state for this trip point
b. if the trend is THERMAL_TREND_DROPPING, use lower cooling
state for this trip point
2. if the temperature is lower than a trip point, use lower cooling state for this trip point.
--- drivers/acpi/thermal.c | 7 ++- drivers/thermal/thermal_sys.c | 91 ++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 27 deletions(-)
drivers/thermal/thermal_sys.c +65 -26
@@ -1035,6 +1035,70 @@ void thermal_cooling_device_unregister(s }EXPORT_SYMBOL (thermal_cooling_device_unregister); +/* +* Cooling algorithm for active trip points +* +* 1. if the temperature is higher than a trip point, +* a. if the trend is THERMAL_TREND_RAISING, use higher cooling +* state for this trip point +* b. if the trend is THERMAL_TREND_DROPPING, use lower cooling +* state for this trip point +* +* 2. if the temperature is lower than a trip point, use lower +* cooling state for this trip point +* +* Note that this behaves the same as the previous passive cooling +* algorithm. +*/ + +static void thermal_zone_trip_update (struct thermal_zone_device *tz, +int trip,long temp) +{ +struct thermal_cooling_device_instance *instance; +struct thermal_cooling_device *cdev =NULL ; +unsigned long cur_state, max_state; +long trip_temp; +enum thermal_trend trend; + + tz->ops->get_trip_temp (tz, trip, &trip_temp); + +if (temp >= trip_temp) { +thermal_get_trend (tz, trip, &trend); + +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ; + + cdev = instance->cdev; + + cdev->ops->get_cur_state (cdev, &cur_state); + cdev->ops->get_max_state (cdev, &max_state); + +if (trend ==THERMAL_TREND_RAISING ) { + cur_state = cur_state < instance->upper ? + (cur_state +1 ) : instance->upper; + }else if (trend ==THERMAL_TREND_DROPPING ) { + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + } + cdev->ops->set_cur_state (cdev, cur_state); + } + }else {/* below trip */ +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ; + + cdev = instance->cdev; + cdev->ops->get_cur_state (cdev, &cur_state); + + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + cdev->ops->set_cur_state (cdev, cur_state); + } + } + +return ; +}/** * thermal_zone_device_update - force an update of a thermal zone's state * @ttz: the thermal zone to update
@@ -1045,9 +1109,6 @@ void thermal_zone_device_update(struct tint count, ret =0 ;long temp, trip_temp;enum thermal_trip_type trip_type; -struct thermal_cooling_device_instance *instance; -struct thermal_cooling_device *cdev; -unsigned long cur_state, max_state;mutex_lock (&tz->lock);
@@ -1083,29 +1144,7 @@ void thermal_zone_device_update(struct t tz->ops->notify (tz, count, trip_type);break ;case THERMAL_TRIP_ACTIVE : -list_for_each_entry (instance, &tz->cooling_devices, - node) { -if (instance->trip != count) -continue ; - - cdev = instance->cdev; - - cdev->ops->get_cur_state (cdev, &cur_state); - cdev->ops->get_max_state (cdev, &max_state); - -if (temp >= trip_temp) - cur_state = - cur_state < instance->upper ? - (cur_state +1 ) : - instance->upper; -else - cur_state = - cur_state > instance->lower ? - (cur_state -1 ) : - instance->lower; - - cdev->ops->set_cur_state (cdev, cur_state); - } +thermal_zone_trip_update (tz, count, temp);break ;case THERMAL_TRIP_PASSIVE :if (temp >= trip_temp || tz->passive)
drivers/acpi/thermal.c +6 -1
@@ -717,7 +717,12 @@ static int thermal_get_trend(struct therif (thermal_get_trip_type (thermal, trip, &type))return -EINVAL ; -/* Only PASSIVE trip points need TREND */ +if (type ==THERMAL_TRIP_ACTIVE ) { +/* aggressive active cooling */ + *trend =THERMAL_TREND_RAISING ; +return 0 ; + } +if (type !=THERMAL_TRIP_PASSIVE )return -EINVAL ;
Quoted 73 lines · Zhang Rui
Introduce
thermal_zone_trip_update()to update the cooling state of all the cooling devices that are binded to an active trip point.This will be used for passive cooling as well, in the future patches. as both active and passive cooling can share the same algorithm, which is
1. if the temperature is higher than a trip point, a. if the trend is
THERMAL_TREND_RAISING, use higher cooling state for this trip point
b. if the trend isTHERMAL_TREND_DROPPING, use lower cooling state for this trip point2. if the temperature is lower than a trip point, use lower cooling state for this trip point.
Signed-off-by Zhang Rui <[email protected]>---
drivers/acpi/thermal.c | 7 ++-drivers/thermal/thermal_sys.c| 91 ++++++++++++++++++++++++++++++------------2 files changed, 71 insertions(+), 27 deletions(-)Index:
rtd3/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +42
-0@@ -1035,6 +1035,70 @@ void thermal_cooling_device_unregister(s } EXPORT_SYMBOL(thermal_cooling_device_unregister); +/* +* Cooling algorithm for active trip points +* +* 1. if the temperature is higher than a trip point, +* a. if the trend is THERMAL_TREND_RAISING, use higher cooling +* state for this trip point +* b. if the trend is THERMAL_TREND_DROPPING, use lower cooling +* state for this trip point +* +* 2. if the temperature is lower than a trip point, use lower +* cooling state for this trip point +* +* Note that this behaves the same as the previous passive cooling +* algorithm. +*/ + +static void thermal_zone_trip_update (struct thermal_zone_device *tz, + int trip, long temp) +{ + struct thermal_cooling_device_instance *instance; + struct thermal_cooling_device *cdev = NULL; + unsigned long cur_state, max_state; + long trip_temp; + enum thermal_trend trend; + + tz->ops->get_trip_temp(tz, trip, &trip_temp); + + if (temp >= trip_temp) { + thermal_get_trend(tz, trip, &trend); + + list_for_each_entry(instance, &tz->cooling_devices, node) { + if (instance->trip != trip) + continue; + + cdev = instance->cdev; + + cdev->ops->get_cur_state(cdev, &cur_state); + cdev->ops->get_max_state(cdev, &max_state); + + if (trend == THERMAL_TREND_RAISING) { + cur_state = cur_state < instance->upper ? + (cur_state + 1) : instance->upper;
drivers/thermal/thermal_sys.c void thermal_cooling_device_unregister(s · line 1089
Quoted 10 lines
drivers/thermal/thermal_sys.c +10
-0+ } else if (trend == THERMAL_TREND_DROPPING) { + cur_state = cur_state > instance->lower ? + (cur_state - 1) : instance->lower; + } + cdev->ops->set_cur_state(cdev, cur_state); + } + } else { /* below trip */ + list_for_each_entry(instance, &tz->cooling_devices, node) { + if (instance->trip != trip) + continue;
Can we use the trend callback here even if the current temperature is less than the trip temperature. Basically according to trend it should deactivate the cooling devices as done for activating cooling devices.
Quoted 76 lines
drivers/thermal/thermal_sys.c +12
-3+ + cdev = instance->cdev; + cdev->ops->get_cur_state(cdev, &cur_state); + + cur_state = cur_state > instance->lower ? + (cur_state - 1) : instance->lower; + cdev->ops->set_cur_state(cdev, cur_state); + } + } + + return; +} /*** thermal_zone_device_update - force an update of a thermal zone's state * @ttz: the thermal zone to update @@ -1045,9 +1109,6 @@ void thermal_zone_device_update(struct t int count, ret = 0; long temp, trip_temp; enum thermal_trip_type trip_type; - struct thermal_cooling_device_instance *instance; - struct thermal_cooling_device *cdev; - unsigned long cur_state, max_state; mutex_lock(&tz->lock);@@ -1083,29 +1144,7 @@ void thermal_zone_device_update(struct t tz->ops->notify(tz, count, trip_type); break;case
THERMAL_TRIP_ACTIVE:
- list_for_each_entry(instance,&tz->cooling_devices,
- node) {
- if (instance->trip!= count)
- continue;drivers/thermal/thermal_sys.c +1
-19- - cdev = instance->cdev; - - cdev->ops->get_cur_state(cdev, &cur_state); - cdev->ops->get_max_state(cdev, &max_state); - - if (temp >= trip_temp) - cur_state = - cur_state < instance->upper ? - (cur_state + 1) : - instance->upper; - else - cur_state = - cur_state > instance->lower ? - (cur_state - 1) : - instance->lower; - - cdev->ops->set_cur_state(cdev, cur_state); - } + thermal_zone_trip_update(tz, count, temp);break;
caseTHERMAL_TRIP_PASSIVE:
if (temp >=trip_temp||tz->passive)
Index:rtd3/drivers/acpi/thermal.c
===================================================================drivers/acpi/thermal.c +6
-1@@ -717,7 +717,12 @@ static int thermal_get_trend(struct ther if (thermal_get_trip_type(thermal, trip, &type)) return -EINVAL; - /* Only PASSIVE trip points need TREND */ + if (type == THERMAL_TRIP_ACTIVE) { + /* aggressive active cooling */ + *trend = THERMAL_TREND_RAISING; + return 0; + } + if (type != THERMAL_TRIP_PASSIVE) return -EINVAL;
Zhang Rui
reviewerQuoted 79 lines · Amit Kachhap
Quoted 78 lines · Zhang Rui
Introduce
thermal_zone_trip_update()to update the cooling state of all the cooling devices that are binded to an active trip point.This will be used for passive cooling as well, in the future patches. as both active and passive cooling can share the same algorithm, which is
1. if the temperature is higher than a trip point, a. if the trend is
THERMAL_TREND_RAISING, use higher cooling state for this trip point
b. if the trend isTHERMAL_TREND_DROPPING, use lower cooling
state for this trip point2. if the temperature is lower than a trip point, use lower cooling state for this trip point.
Signed-off-by Zhang Rui <[email protected]>--- drivers/acpi/thermal.c | 7 ++- drivers/thermal/thermal_sys.c | 91 ++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 27 deletions(-)Index:
rtd3/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +47
-0@@ -1035,6 +1035,70 @@ void thermal_cooling_device_unregister(s }EXPORT_SYMBOL (thermal_cooling_device_unregister); +/* +* Cooling algorithm for active trip points +* +* 1. if the temperature is higher than a trip point, +* a. if the trend is THERMAL_TREND_RAISING, use higher cooling +* state for this trip point +* b. if the trend is THERMAL_TREND_DROPPING, use lower cooling +* state for this trip point +* +* 2. if the temperature is lower than a trip point, use lower +* cooling state for this trip point +* +* Note that this behaves the same as the previous passive cooling +* algorithm. +*/ + +static void thermal_zone_trip_update (struct thermal_zone_device *tz, +int trip,long temp) +{ +struct thermal_cooling_device_instance *instance; +struct thermal_cooling_device *cdev =NULL ; +unsigned long cur_state, max_state; +long trip_temp; +enum thermal_trend trend; + + tz->ops->get_trip_temp (tz, trip, &trip_temp); + +if (temp >= trip_temp) { +thermal_get_trend (tz, trip, &trend); + +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ; + + cdev = instance->cdev; + + cdev->ops->get_cur_state (cdev, &cur_state); + cdev->ops->get_max_state (cdev, &max_state); + +if (trend ==THERMAL_TREND_RAISING ) { + cur_state = cur_state < instance->upper ? + (cur_state +1 ) : instance->upper; + }else if (trend ==THERMAL_TREND_DROPPING ) { + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + } + cdev->ops->set_cur_state (cdev, cur_state);
Quoted 8 lines
drivers/thermal/thermal_sys.c void thermal_cooling_device_unregister(s · line 1089
Quoted 5 lines
drivers/thermal/thermal_sys.c +5
-0+ } + }else {/* below trip */ +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ;Can we use the trend callback here even if the current temperature is less than the trip temperature. Basically according to trend it should deactivate the cooling devices as done for activating cooling devices.
yes, this depends on the cooling algorithm we want to use. When the temperature is lower than the trip point, if we want to stop the fan immediately instead of spinning down step by step, we can do this.
Actually, what we are discussing right now should be some cooling governor stuff. which I'm not sure if we should introduce to the generic thermal manager or not, right now. :)
thanks,
rui
Quoted 64 lines
Quoted 64 lines
drivers/thermal/thermal_sys.c +13
-26+ + cdev = instance->cdev; + cdev->ops->get_cur_state (cdev, &cur_state); + + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + cdev->ops->set_cur_state (cdev, cur_state); + } + } + +return ; +}/** * thermal_zone_device_update - force an update of a thermal zone's state * @ttz: the thermal zone to update @@ -1045,9 +1109,6 @@ void thermal_zone_device_update(struct tint count, ret =0 ;long temp, trip_temp;enum thermal_trip_type trip_type; -struct thermal_cooling_device_instance *instance; -struct thermal_cooling_device *cdev; -unsigned long cur_state, max_state;mutex_lock (&tz->lock);@@ -1083,29 +1144,7 @@ void thermal_zone_device_update(struct t tz->ops->notify (tz, count, trip_type);break ;case THERMAL_TRIP_ACTIVE : -list_for_each_entry (instance, &tz->cooling_devices, - node) { -if (instance->trip != count) -continue ; - - cdev = instance->cdev; - - cdev->ops->get_cur_state (cdev, &cur_state); - cdev->ops->get_max_state (cdev, &max_state); - -if (temp >= trip_temp) - cur_state = - cur_state < instance->upper ? - (cur_state +1 ) : - instance->upper; -else - cur_state = - cur_state > instance->lower ? - (cur_state -1 ) : - instance->lower; - - cdev->ops->set_cur_state (cdev, cur_state); - } +thermal_zone_trip_update (tz, count, temp);break ;case THERMAL_TRIP_PASSIVE :if (temp >= trip_temp || tz->passive)Index:
rtd3/drivers/acpi/thermal.c
===================================================================drivers/acpi/thermal.c +0
-0@@ -717,7 +717,12 @@ static int thermal_get_trend(struct therif (thermal_get_trip_type (thermal, trip, &type))return -EINVAL ;
Quoted 12 lines
drivers/acpi/thermal.c static int thermal_get_trend(struct ther · line 728
Quoted 12 lines
drivers/acpi/thermal.c +6
-1-/* Only PASSIVE trip points need TREND */ +if (type ==THERMAL_TRIP_ACTIVE ) { +/* aggressive active cooling */ + *trend =THERMAL_TREND_RAISING ; +return 0 ; + } +if (type !=THERMAL_TRIP_PASSIVE )return -EINVAL ;
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm
Hello,
Quoted 89 lines · Zhang Rui
Quoted 79 lines · Amit Kachhap
Quoted 78 lines · Zhang Rui
Introduce
thermal_zone_trip_update()to update the cooling state of all the cooling devices that are binded to an active trip point.This will be used for passive cooling as well, in the future patches. as both active and passive cooling can share the same algorithm, which is
1. if the temperature is higher than a trip point, a. if the trend is
THERMAL_TREND_RAISING, use higher cooling state for this trip point
b. if the trend isTHERMAL_TREND_DROPPING, use lower cooling
state for this trip point2. if the temperature is lower than a trip point, use lower cooling state for this trip point.
Signed-off-by Zhang Rui <[email protected]>--- drivers/acpi/thermal.c | 7 ++- drivers/thermal/thermal_sys.c | 91 ++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 27 deletions(-)Index:
rtd3/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +47
-0@@ -1035,6 +1035,70 @@ void thermal_cooling_device_unregister(s }EXPORT_SYMBOL (thermal_cooling_device_unregister); +/* +* Cooling algorithm for active trip points +* +* 1. if the temperature is higher than a trip point, +* a. if the trend is THERMAL_TREND_RAISING, use higher cooling +* state for this trip point +* b. if the trend is THERMAL_TREND_DROPPING, use lower cooling +* state for this trip point +* +* 2. if the temperature is lower than a trip point, use lower +* cooling state for this trip point +* +* Note that this behaves the same as the previous passive cooling +* algorithm. +*/ + +static void thermal_zone_trip_update (struct thermal_zone_device *tz, +int trip,long temp) +{ +struct thermal_cooling_device_instance *instance; +struct thermal_cooling_device *cdev =NULL ; +unsigned long cur_state, max_state; +long trip_temp; +enum thermal_trend trend; + + tz->ops->get_trip_temp (tz, trip, &trip_temp); + +if (temp >= trip_temp) { +thermal_get_trend (tz, trip, &trend); + +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ; + + cdev = instance->cdev; + + cdev->ops->get_cur_state (cdev, &cur_state); + cdev->ops->get_max_state (cdev, &max_state); + +if (trend ==THERMAL_TREND_RAISING ) { + cur_state = cur_state < instance->upper ? + (cur_state +1 ) : instance->upper; + }else if (trend ==THERMAL_TREND_DROPPING ) { + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + } + cdev->ops->set_cur_state (cdev, cur_state);Quoted 8 lines
drivers/thermal/thermal_sys.c void thermal_cooling_device_unregister(s · line 1089
Quoted 5 lines
drivers/thermal/thermal_sys.c +5
-0+ } + }else {/* below trip */ +list_for_each_entry (instance, &tz->cooling_devices, node) { +if (instance->trip != trip) +continue ;Can we use the trend callback here even if the current temperature is less than the trip temperature. Basically according to trend it should deactivate the cooling devices as done for activating cooling devices.
Quoted 8 lines
yes, this depends on the cooling algorithm we want to use. When the temperature is lower than the trip point, if we want to stop the fan immediately instead of spinning down step by step, we can do this.
Actually, what we are discussing right now should be some cooling governor stuff. which I'm not sure if we should introduce to the generic thermal manager or not, right now. :)
Rui, this is an interesting point. Do you have plans to have governor like approach in the generic thermal fw? Or are you sticking to the zone/cooling binding?
Quoted 68 lines
thanks,
ruiQuoted 64 lines
Quoted 64 lines
drivers/thermal/thermal_sys.c +13
-26+ + cdev = instance->cdev; + cdev->ops->get_cur_state (cdev, &cur_state); + + cur_state = cur_state > instance->lower ? + (cur_state -1 ) : instance->lower; + cdev->ops->set_cur_state (cdev, cur_state); + } + } + +return ; +}/** * thermal_zone_device_update - force an update of a thermal zone's state * @ttz: the thermal zone to update @@ -1045,9 +1109,6 @@ void thermal_zone_device_update(struct tint count, ret =0 ;long temp, trip_temp;enum thermal_trip_type trip_type; -struct thermal_cooling_device_instance *instance; -struct thermal_cooling_device *cdev; -unsigned long cur_state, max_state;mutex_lock (&tz->lock);@@ -1083,29 +1144,7 @@ void thermal_zone_device_update(struct t tz->ops->notify (tz, count, trip_type);break ;case THERMAL_TRIP_ACTIVE : -list_for_each_entry (instance, &tz->cooling_devices, - node) { -if (instance->trip != count) -continue ; - - cdev = instance->cdev; - - cdev->ops->get_cur_state (cdev, &cur_state); - cdev->ops->get_max_state (cdev, &max_state); - -if (temp >= trip_temp) - cur_state = - cur_state < instance->upper ? - (cur_state +1 ) : - instance->upper; -else - cur_state = - cur_state > instance->lower ? - (cur_state -1 ) : - instance->lower; - - cdev->ops->set_cur_state (cdev, cur_state); - } +thermal_zone_trip_update (tz, count, temp);break ;case THERMAL_TRIP_PASSIVE :if (temp >= trip_temp || tz->passive)Index:
rtd3/drivers/acpi/thermal.c
===================================================================drivers/acpi/thermal.c +0
-0@@ -717,7 +717,12 @@ static int thermal_get_trend(struct therif (thermal_get_trip_type (thermal, trip, &type))return -EINVAL ;
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
drivers/acpi/thermal.c +3
-1-/* Only PASSIVE trip points need TREND */ +if (type ==THERMAL_TRIP_ACTIVE ) { +/* aggressive active cooling */ + *trend =THERMAL_TREND_RAISING ;Quoted 8 lines
drivers/acpi/thermal.c static int thermal_get_trend(struct ther · line 728
Quoted 8 lines
drivers/acpi/thermal.c +3
-0+return 0 ; + } +if (type !=THERMAL_TRIP_PASSIVE )return -EINVAL ;
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Eduardo,
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Can we use the trend callback here even if the current temperature is less than the trip temperature. Basically according to trend it should deactivate the cooling devices as done for activating cooling devices.
yes, this depends on the cooling algorithm we want to use. When the temperature is lower than the trip point, if we want to stop the fan immediately instead of spinning down step by step, we can do this.
Quoted 6 lines
Quoted 3 lines
Actually, what we are discussing right now should be some cooling governor stuff. which I'm not sure if we should introduce to the generic thermal manager or not, right now. :)
Rui, this is an interesting point. Do you have plans to have governor like approach in the generic thermal fw? Or are you sticking to the zone/cooling binding?
Yes We have. I am almost done.
Will submit patches by tomorrow.
Unfortunately, I cannot re-base my code now on top of Rui's patches. So, I will submit an RFC version and we can work to resolve the conflicts.
Thanks,
Durga