thermal: introduce .get_trend() callback
Subsystems (3)
Zhang Rui
reviewerRFC PATCH 4/12 thermal: introduce .get_trend() callback
tc1 and tc2 are ACPI platform specific concepts, introduce .get_trend() as a more general solution.
--- drivers/acpi/thermal.c | 32 ++++++++++++++++++++++++++++++++ drivers/thermal/thermal_sys.c | 19 +++++++++++++++++-- include/linux/thermal.h | 9 +++++++++ 3 files changed, 58 insertions(+), 2 deletions(-)
drivers/acpi/thermal.c +32 -0
@@ -706,6 +706,37 @@ static int thermal_get_crit_temp(structreturn -EINVAL ; } +static int thermal_get_trend (struct thermal_zone_device *thermal, +int trip,enum thermal_trend *trend) +{ +struct acpi_thermal *tz = thermal->devdata; +enum thermal_trip_type type; +unsigned long trip_temp; +int i; + +if (thermal_get_trip_type (thermal, trip, &type)) +return -EINVAL ; + +/* Only PASSIVE trip points need TREND */ +if (type !=THERMAL_TRIP_PASSIVE ) +return -EINVAL ; + +if (thermal_get_trip_temp (thermal, trip, &trip_temp)) +return -EINVAL ; + +/* +* tz->temperature has already been updated by generic thermal layer, +* before this callback being invoked +*/ + i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->trips.passive.tc2 * (tz->temperature - trip_temp)); + + *trend = i >0 ?THERMAL_TREND_RAISING : + (i <0 ?THERMAL_TREND_DROPPING :THERMAL_TREND_NONE ); +return 0 ; +} + +static int thermal_notify (struct thermal_zone_device *thermal,int trip,enum thermal_trip_type trip_type) {
@@ -835,6 +866,7 @@ static const struct thermal_zone_device_ .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, + .get_trend = thermal_get_trend, .notify = thermal_notify, };
drivers/thermal/thermal_sys.c +17 -2
@@ -657,6 +657,18 @@ thermal_remove_hwmon_sysfs(struct therma }#endif +static void thermal_get_trend (struct thermal_zone_device *tz, +int trip,enum thermal_trend *trend) +{ +if (tz->ops->get_trend) +if (!tz->ops->get_trend (tz, trip, trend)) +return ; + + *trend = tz->temperature >= tz->last_temperature ? +THERMAL_TREND_RAISING :THERMAL_TREND_DROPPING ; +return ; +} +static void thermal_zone_device_set_polling (struct thermal_zone_device *tz,int delay) {
@@ -691,6 +703,8 @@ static void thermal_zone_device_passive(if (temp >= trip_temp) { tz->passive = true; +thermal_get_trend (tz, trip, (enum thermal_trend *)&trend); + trend = (tz->tc1 * (temp - tz->last_temperature)) + (tz->tc2 * (temp - trip_temp));
@@ -1049,6 +1063,9 @@ void thermal_zone_device_update(struct t goto leave; } + tz->last_temperature = tz->temperature; + tz->temperature = temp; +for (count =0 ; count < tz->trips; count++) { tz->ops->get_trip_type (tz, count, &trip_type); tz->ops->get_trip_temp (tz, count, &trip_temp);
@@ -1108,8 +1125,6 @@ void thermal_zone_device_update(struct tthermal_zone_device_passive (tz, temp, tz->forced_passive,THERMAL_TRIPS_NONE ); - tz->last_temperature = temp; - leave:if (tz->passive)thermal_zone_device_set_polling (tz, tz->passive_delay);
include/linux/thermal.h +9 -0
@@ -44,6 +44,12 @@ enum thermal_trip_type { THERMAL_TRIP_CRITICAL, }; +enum thermal_trend { +THERMAL_TREND_NONE , +THERMAL_TREND_RAISING , +THERMAL_TREND_DROPPING , +}; +struct thermal_zone_device_ops {int (*bind) (struct thermal_zone_device *,struct thermal_cooling_device *);
@@ -59,6 +65,8 @@ struct thermal_zone_device_ops {int (*get_trip_temp) (struct thermal_zone_device *,int ,unsigned long *);int (*get_crit_temp) (struct thermal_zone_device *,unsigned long *); +int (*get_trend) (struct thermal_zone_device *,int , +enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); };
@@ -95,6 +103,7 @@ struct thermal_zone_device {int tc2;int passive_delay;int polling_delay; +int temperature;int last_temperature;bool passive;unsigned int forced_passive;
Hello Rui,
Quoted 118 lines · Zhang Rui
tc1 and tc2 are ACPI platform specific concepts, introduce .get_trend() as a more general solution.
Signed-off-by Zhang Rui <[email protected]>--- drivers/acpi/thermal.c | 32 ++++++++++++++++++++++++++++++++ drivers/thermal/thermal_sys.c | 19 +++++++++++++++++-- include/linux/thermal.h | 9 +++++++++ 3 files changed, 58 insertions(+), 2 deletions(-)Index:
rtd3/drivers/acpi/thermal.c
===================================================================drivers/acpi/thermal.c +32
-0@@ -706,6 +706,37 @@ static int thermal_get_crit_temp(structreturn -EINVAL ; } +static int thermal_get_trend (struct thermal_zone_device *thermal, +int trip,enum thermal_trend *trend) +{ +struct acpi_thermal *tz = thermal->devdata; +enum thermal_trip_type type; +unsigned long trip_temp; +int i; + +if (thermal_get_trip_type (thermal, trip, &type)) +return -EINVAL ; + +/* Only PASSIVE trip points need TREND */ +if (type !=THERMAL_TRIP_PASSIVE ) +return -EINVAL ; + +if (thermal_get_trip_temp (thermal, trip, &trip_temp)) +return -EINVAL ; + +/* +* tz->temperature has already been updated by generic thermal layer, +* before this callback being invoked +*/ + i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->trips.passive.tc2 * (tz->temperature - trip_temp)); + + *trend = i >0 ?THERMAL_TREND_RAISING : + (i <0 ?THERMAL_TREND_DROPPING :THERMAL_TREND_NONE ); +return 0 ; +} + +static int thermal_notify (struct thermal_zone_device *thermal,int trip,enum thermal_trip_type trip_type) {@@ -835,6 +866,7 @@ static const struct thermal_zone_device_ .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, + .get_trend = thermal_get_trend, .notify = thermal_notify, };Index:
rtd3/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +17
-2@@ -657,6 +657,18 @@ thermal_remove_hwmon_sysfs(struct therma }#endif +static void thermal_get_trend (struct thermal_zone_device *tz, +int trip,enum thermal_trend *trend) +{ +if (tz->ops->get_trend) +if (!tz->ops->get_trend (tz, trip, trend)) +return ; + + *trend = tz->temperature >= tz->last_temperature ? +THERMAL_TREND_RAISING :THERMAL_TREND_DROPPING ; +return ; +} +static void thermal_zone_device_set_polling (struct thermal_zone_device *tz,int delay) {@@ -691,6 +703,8 @@ static void thermal_zone_device_passive(if (temp >= trip_temp) { tz->passive = true; +thermal_get_trend (tz, trip, (enum thermal_trend *)&trend); + trend = (tz->tc1 * (temp - tz->last_temperature)) + (tz->tc2 * (temp - trip_temp));@@ -1049,6 +1063,9 @@ void thermal_zone_device_update(struct t goto leave; } + tz->last_temperature = tz->temperature; + tz->temperature = temp; +for (count =0 ; count < tz->trips; count++) { tz->ops->get_trip_type (tz, count, &trip_type); tz->ops->get_trip_temp (tz, count, &trip_temp);@@ -1108,8 +1125,6 @@ void thermal_zone_device_update(struct tthermal_zone_device_passive (tz, temp, tz->forced_passive,THERMAL_TRIPS_NONE ); - tz->last_temperature = temp; - leave:if (tz->passive)thermal_zone_device_set_polling (tz, tz->passive_delay);Index:
rtd3/include/linux/thermal.h
===================================================================
include/linux/thermal.h enum thermal_trip_type { · line 52
Quoted 9 lines
include/linux/thermal.h +6
-0@@ -44,6 +44,12 @@ enum thermal_trip_type { THERMAL_TRIP_CRITICAL, }; +enum thermal_trend { +THERMAL_TREND_NONE , +THERMAL_TREND_RAISING , +THERMAL_TREND_DROPPING , +}; +
Nip: Can you please add some doc for the expected definition for all enum entries above? Is TREND_NONE supposed to mean "Stable", for instance?
Quoted 22 lines
include/linux/thermal.h +3
-0struct thermal_zone_device_ops {int (*bind) (struct thermal_zone_device *,struct thermal_cooling_device *);@@ -59,6 +65,8 @@ struct thermal_zone_device_ops {int (*get_trip_temp) (struct thermal_zone_device *,int ,unsigned long *);int (*get_crit_temp) (struct thermal_zone_device *,unsigned long *); +int (*get_trend) (struct thermal_zone_device *,int , +enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); };@@ -95,6 +103,7 @@ struct thermal_zone_device {int tc2;int passive_delay;int polling_delay; +int temperature;int last_temperature;bool passive;unsigned int forced_passive;
Zhang Rui
reviewerQuoted 124 lines · Eduardo Valentin
Hello Rui,
Quoted 121 lines · Zhang Rui
tc1 and tc2 are ACPI platform specific concepts, introduce .get_trend() as a more general solution.
Signed-off-by Zhang Rui <[email protected]>--- drivers/acpi/thermal.c | 32 ++++++++++++++++++++++++++++++++ drivers/thermal/thermal_sys.c | 19 +++++++++++++++++-- include/linux/thermal.h | 9 +++++++++ 3 files changed, 58 insertions(+), 2 deletions(-)Index:
rtd3/drivers/acpi/thermal.c
===================================================================drivers/acpi/thermal.c +32
-0@@ -706,6 +706,37 @@ static int thermal_get_crit_temp(structreturn -EINVAL ; } +static int thermal_get_trend (struct thermal_zone_device *thermal, +int trip,enum thermal_trend *trend) +{ +struct acpi_thermal *tz = thermal->devdata; +enum thermal_trip_type type; +unsigned long trip_temp; +int i; + +if (thermal_get_trip_type (thermal, trip, &type)) +return -EINVAL ; + +/* Only PASSIVE trip points need TREND */ +if (type !=THERMAL_TRIP_PASSIVE ) +return -EINVAL ; + +if (thermal_get_trip_temp (thermal, trip, &trip_temp)) +return -EINVAL ; + +/* +* tz->temperature has already been updated by generic thermal layer, +* before this callback being invoked +*/ + i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->trips.passive.tc2 * (tz->temperature - trip_temp)); + + *trend = i >0 ?THERMAL_TREND_RAISING : + (i <0 ?THERMAL_TREND_DROPPING :THERMAL_TREND_NONE ); +return 0 ; +} + +static int thermal_notify (struct thermal_zone_device *thermal,int trip,enum thermal_trip_type trip_type) {@@ -835,6 +866,7 @@ static const struct thermal_zone_device_ .get_trip_type = thermal_get_trip_type, .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, + .get_trend = thermal_get_trend, .notify = thermal_notify, };Index:
rtd3/drivers/thermal/thermal_sys.c
===================================================================drivers/thermal/thermal_sys.c +17
-2@@ -657,6 +657,18 @@ thermal_remove_hwmon_sysfs(struct therma }#endif +static void thermal_get_trend (struct thermal_zone_device *tz, +int trip,enum thermal_trend *trend) +{ +if (tz->ops->get_trend) +if (!tz->ops->get_trend (tz, trip, trend)) +return ; + + *trend = tz->temperature >= tz->last_temperature ? +THERMAL_TREND_RAISING :THERMAL_TREND_DROPPING ; +return ; +} +static void thermal_zone_device_set_polling (struct thermal_zone_device *tz,int delay) {@@ -691,6 +703,8 @@ static void thermal_zone_device_passive(if (temp >= trip_temp) { tz->passive = true; +thermal_get_trend (tz, trip, (enum thermal_trend *)&trend); + trend = (tz->tc1 * (temp - tz->last_temperature)) + (tz->tc2 * (temp - trip_temp));@@ -1049,6 +1063,9 @@ void thermal_zone_device_update(struct t goto leave; } + tz->last_temperature = tz->temperature; + tz->temperature = temp; +for (count =0 ; count < tz->trips; count++) { tz->ops->get_trip_type (tz, count, &trip_type); tz->ops->get_trip_temp (tz, count, &trip_temp);@@ -1108,8 +1125,6 @@ void thermal_zone_device_update(struct tthermal_zone_device_passive (tz, temp, tz->forced_passive,THERMAL_TRIPS_NONE ); - tz->last_temperature = temp; - leave:if (tz->passive)thermal_zone_device_set_polling (tz, tz->passive_delay);Index:
rtd3/include/linux/thermal.h
===================================================================include/linux/thermal.h +0
-0@@ -44,6 +44,12 @@ enum thermal_trip_type { THERMAL_TRIP_CRITICAL, };
Quoted 10 lines
include/linux/thermal.h enum thermal_trip_type { · line 52
Quoted 6 lines
include/linux/thermal.h +6
-0+enum thermal_trend { +THERMAL_TREND_NONE , +THERMAL_TREND_RAISING , +THERMAL_TREND_DROPPING , +}; +Nip: Can you please add some doc for the expected definition for all enum entries above? Is
TREND_NONEsupposed to mean "Stable", for instance?
yep. TREND_STABLE sounds better. I'm not good at naming.
thanks,
rui
Quoted 14 lines
Quoted 14 lines
include/linux/thermal.h +2
-0struct thermal_zone_device_ops {int (*bind) (struct thermal_zone_device *,struct thermal_cooling_device *);@@ -59,6 +65,8 @@ struct thermal_zone_device_ops {int (*get_trip_temp) (struct thermal_zone_device *,int ,unsigned long *);int (*get_crit_temp) (struct thermal_zone_device *,unsigned long *); +int (*get_trend) (struct thermal_zone_device *,int , +enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); };@@ -95,6 +103,7 @@ struct thermal_zone_device {int tc2;
Quoted 8 lines
include/linux/thermal.h struct thermal_zone_device { · line 109
Quoted 8 lines
include/linux/thermal.h +1
-0int passive_delay;int polling_delay; +int temperature;int last_temperature;bool passive;unsigned int forced_passive;
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-pm