thermal/core: Emit a warning if the thermal zone is updated without ops
Subsystems (4)
PATCH 1/5 thermal/core: Emit a warning if the thermal zone is updated without ops
The actual code is silently ignoring a thermal zone update when a driver is requesting it without a get_temp ops set.
That looks not correct, as the caller should not have called this function if the thermal zone is unable to read the temperature.
That makes the code less robust as the check won't detect the driver is inconsistently using the thermal API and that does not help to improve the framework as these circumvolutions hide the problem at the source.
In order to detect the situation when it happens, let's add a warning when the update is requested without the get_temp() ops set.
Any warning emitted will have to be fixed at the source of the
problem: the caller must not call thermal_zone_device_update if there is not get_temp callback set.
--- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +2 -1
@@ -548,7 +548,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,if (atomic_read (&in_suspend))return ; -if (!tz->ops->get_temp) +if (WARN_ONCE (!tz->ops->get_temp,"'%s' must not be called without " +"'get_temp' ops set\n" , __func__))return ;update_temperature (tz);
Signature · 1 line
2.17.1
PATCH 2/5 thermal/core: Add critical and hot ops
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling thermal_zone_device_update assuming all the trip points are defined.
A sensor may want to do something special if a trip point is hot or critical.
This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones.
--- drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++ 2 files changed, 30 insertions(+), 16 deletions(-)
drivers/thermal/thermal_core.c +27 -16
@@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical (struct thermal_zone_device *tz) +{ +dev_emerg (&tz->device,"%s: critical temperature reached, " +"shutting down\n" , tz->type); + +mutex_lock (&poweroff_lock); +if (!power_off_triggered) { +/* +* Queue a backup emergency shutdown in the event of +* orderly_poweroff failure +*/ +thermal_emergency_poweroff (); +orderly_poweroff (true); + power_off_triggered = true; + } +mutex_unlock (&poweroff_lock); +} +EXPORT_SYMBOL (thermal_zone_device_critical); +static void handle_critical_trips (struct thermal_zone_device *tz,int trip,enum thermal_trip_type trip_type) {
@@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,if (tz->ops->notify) tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_CRITICAL ) { -dev_emerg (&tz->device, -"critical temperature reached (%d C), shutting down\n" , - tz->temperature /1000 ); -mutex_lock (&poweroff_lock); -if (!power_off_triggered) { -/* -* Queue a backup emergency shutdown in the event of -* orderly_poweroff failure -*/ -thermal_emergency_poweroff (); -orderly_poweroff (true); - power_off_triggered = true; - } -mutex_unlock (&poweroff_lock); - } +if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot (tz); +else if (trip_type ==THERMAL_TRIP_CRITICAL ) + tz->ops->critical (tz); }static void handle_thermal_trip (struct thermal_zone_device *tz,int trip)
@@ -1331,6 +1338,10 @@ thermal_zone_device_register(const char *type, int trips, int mask, tz->id = id;strlcpy (tz->type, type,sizeof (tz->type)); + +if (!ops->critical) + ops->critical = thermal_zone_device_critical; + tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class;
include/linux/thermal.h +3 -0
@@ -79,6 +79,8 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +void (*hot)(struct thermal_zone_device *); +void (*critical)(struct thermal_zone_device *); };struct thermal_cooling_device_ops {
@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);void thermal_notify_framework (struct thermal_zone_device *,int );int thermal_zone_device_enable (struct thermal_zone_device *tz);int thermal_zone_device_disable (struct thermal_zone_device *tz); +void thermal_zone_device_critical (struct thermal_zone_device *tz);#else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,
Signature · 1 line
2.17.1
Lukasz Luba
reviewerRe: [PATCH 2/5] thermal/core: Add critical and hot ops
Quoted 62 lines · Daniel Lezcano
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling
thermal_zone_device_updateassuming all the trip points are defined.A sensor may want to do something special if a trip point is hot or critical.
This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones.
Tested-by Kai-Heng Feng <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>--- drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++ 2 files changed, 30 insertions(+), 16 deletions(-)drivers/thermal/thermal_core.c +19
-10@@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical (struct thermal_zone_device *tz) +{ +dev_emerg (&tz->device,"%s: critical temperature reached, " +"shutting down\n" , tz->type); + +mutex_lock (&poweroff_lock); +if (!power_off_triggered) { +/* +* Queue a backup emergency shutdown in the event of +* orderly_poweroff failure +*/ +thermal_emergency_poweroff (); +orderly_poweroff (true); + power_off_triggered = true; + } +mutex_unlock (&poweroff_lock); +} +EXPORT_SYMBOL (thermal_zone_device_critical); +static void handle_critical_trips (struct thermal_zone_device *tz,int trip,enum thermal_trip_type trip_type) {@@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,if (tz->ops->notify) tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_CRITICAL ) { -dev_emerg (&tz->device, -"critical temperature reached (%d C), shutting down\n" , - tz->temperature /1000 ); -mutex_lock (&poweroff_lock); -if (!power_off_triggered) { -/* -* Queue a backup emergency shutdown in the event of -* orderly_poweroff failure -*/
drivers/thermal/thermal_core.c static void handle_critical_trips(struct thermal_zone_device *tz, · line 416
Quoted 10 lines
drivers/thermal/thermal_core.c +4
-6-thermal_emergency_poweroff (); -orderly_poweroff (true); - power_off_triggered = true; - } -mutex_unlock (&poweroff_lock); - } +if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot (tz); +else if (trip_type ==THERMAL_TRIP_CRITICAL ) + tz->ops->critical (tz);
I can see that in the patch 3/5 there driver .critical() callback calls framework thermal_zone_device_critical() at the end. I wonder if we could always call this framework function.
Something like a helper function always called:
void _handle_critical( *tz)
{
if (tz->ops->critical)
tz->ops->critical(tz);
thermal_zone_device_critical(tz);
}and then called:
else if (trip_type == THERMAL_TRIP_CRITICAL) _handle_critical(tz);
drivers/thermal/thermal_core.c thermal_zone_device_register(const char *type, int trips, int mask, · line 1343
Quoted 10 lines
drivers/thermal/thermal_core.c +3
-0}static void handle_thermal_trip (struct thermal_zone_device *tz,int trip)@@ -1331,6 +1338,10 @@ thermal_zone_device_register(const char *type, int trips, int mask, tz->id = id;strlcpy (tz->type, type,sizeof (tz->type)); + +if (!ops->critical) + ops->critical = thermal_zone_device_critical;
Then we could drop this default assignment.
Quoted 19 lines
drivers/thermal/thermal_core.c +1
-0+ tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class;include/linux/thermal.h +2
-0@@ -79,6 +79,8 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +void (*hot)(struct thermal_zone_device *); +void (*critical)(struct thermal_zone_device *); };struct thermal_cooling_device_ops {
include/linux/thermal.h void thermal_cdev_update(struct thermal_cooling_device *); · line 407
Quoted 7 lines
include/linux/thermal.h +1
-0@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);void thermal_notify_framework (struct thermal_zone_device *,int );int thermal_zone_device_enable (struct thermal_zone_device *tz);int thermal_zone_device_disable (struct thermal_zone_device *tz); +void thermal_zone_device_critical (struct thermal_zone_device *tz);#else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,
I am just concerned about drivers which provide own .critical() callback but forgot to call thermal_zone_device_critical() at the end and framework could skip it.
Or we can make sure during the review that it's not an issue (and ignore out of tree drivers)?
Regards,
Lukasz
Re: [PATCH 2/5] thermal/core: Add critical and hot ops
Quoted 71 lines · Lukasz Luba
Quoted 68 lines · Daniel Lezcano
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling
thermal_zone_device_updateassuming all the trip points are defined.A sensor may want to do something special if a trip point is hot or critical.
This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones.
Tested-by Kai-Heng Feng <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>---
drivers/thermal/thermal_core.c| 43 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++2 files changed, 30 insertions(+), 16 deletions(-)drivers/thermal/thermal_core.c +18
-15@@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical(struct thermal_zone_device *tz) +{ + dev_emerg(&tz->device, "%s: critical temperature reached, " + "shutting down\n", tz->type); + + mutex_lock(&poweroff_lock); + if (!power_off_triggered) { + /* + * Queue a backup emergency shutdown in the event of + * orderly_poweroff failure + */ + thermal_emergency_poweroff(); + orderly_poweroff(true); + power_off_triggered = true; + } + mutex_unlock(&poweroff_lock); +} +EXPORT_SYMBOL (thermal_zone_device_critical); + static void handle_critical_trips(struct thermal_zone_device *tz, int trip, enum thermal_trip_type trip_type) {@@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz, if (tz->ops->notify) tz->ops->notify(tz, trip, trip_type); - if (trip_type == THERMAL_TRIP_CRITICAL) { - dev_emerg(&tz->device, - "critical temperature reached (%d C), shutting down\n", - tz->temperature / 1000); - mutex_lock(&poweroff_lock); - if (!power_off_triggered) { - /* - * Queue a backup emergency shutdown in the event of - * orderly_poweroff failure - */ - thermal_emergency_poweroff(); - orderly_poweroff(true); - power_off_triggered = true; - } - mutex_unlock(&poweroff_lock); - }
Quoted 8 lines
drivers/thermal/thermal_core.c static void handle_critical_trips(struct thermal_zone_device *tz, · line 416
Quoted 4 lines
drivers/thermal/thermal_core.c +4
-0+ if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot(tz); + else if (trip_type == THERMAL_TRIP_CRITICAL) + tz->ops->critical(tz);I can see that in the patch 3/5 there driver .critical() callback calls framework
thermal_zone_device_critical()at the end. I wonder if we could always call this framework function.
It is actually done on purpose, we want to let the driver to handle the critical routine which may not end up with an emergency shutdown.
[ ... ]
Quoted 11 lines
Quoted 4 lines
drivers/thermal/thermal_core.c +0
-0#elsestatic inline struct
thermal_zone_device*thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,I am just concerned about drivers which provide own .critical() callback but forgot to call
thermal_zone_device_critical()at the end and framework could skip it.Or we can make sure during the review that it's not an issue (and ignore out of tree drivers)?
Yes, the framework guarantees if the critical trip point is crossed we call the emergency shutdown by default. If the driver choose to override it, it takes responsibility of the change.
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH 2/5] thermal/core: Add critical and hot ops
Quoted 81 lines · Daniel Lezcano
Quoted 71 lines · Lukasz Luba
Quoted 68 lines · Daniel Lezcano
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling
thermal_zone_device_updateassuming all the trip points are defined.A sensor may want to do something special if a trip point is hot or critical.
This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones.
Tested-by Kai-Heng Feng <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>--- drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++ 2 files changed, 30 insertions(+), 16 deletions(-)drivers/thermal/thermal_core.c +18
-15@@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical(struct thermal_zone_device *tz) +{ + dev_emerg(&tz->device, "%s: critical temperature reached, " + "shutting down\n", tz->type); + + mutex_lock(&poweroff_lock); + if (!power_off_triggered) { + /* + * Queue a backup emergency shutdown in the event of + * orderly_poweroff failure + */ + thermal_emergency_poweroff(); + orderly_poweroff(true); + power_off_triggered = true; + } + mutex_unlock(&poweroff_lock); +} +EXPORT_SYMBOL (thermal_zone_device_critical); + static void handle_critical_trips(struct thermal_zone_device *tz, int trip, enum thermal_trip_type trip_type) {@@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz, if (tz->ops->notify) tz->ops->notify(tz, trip, trip_type); - if (trip_type == THERMAL_TRIP_CRITICAL) { - dev_emerg(&tz->device, - "critical temperature reached (%d C), shutting down\n", - tz->temperature / 1000); - mutex_lock(&poweroff_lock); - if (!power_off_triggered) { - /* - * Queue a backup emergency shutdown in the event of - * orderly_poweroff failure - */ - thermal_emergency_poweroff(); - orderly_poweroff(true); - power_off_triggered = true; - } - mutex_unlock(&poweroff_lock); - }Quoted 8 lines
drivers/thermal/thermal_core.c static void handle_critical_trips(struct thermal_zone_device *tz, · line 416
Quoted 4 lines
drivers/thermal/thermal_core.c +4
-0+ if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot(tz); + else if (trip_type == THERMAL_TRIP_CRITICAL) + tz->ops->critical(tz);I can see that in the patch 3/5 there driver .critical() callback calls framework
thermal_zone_device_critical()at the end. I wonder if we could always call this framework function.
Quoted 2 lines
It is actually done on purpose, we want to let the driver to handle the critical routine which may not end up with an emergency shutdown.
I see.
Quoted 12 lines
[ ... ]
Quoted 9 lines
Quoted 4 lines
#else
static inline structthermal_zone_device*thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,I am just concerned about drivers which provide own .critical() callback but forgot to call
thermal_zone_device_critical()at the end and framework could skip it.
Quoted 7 lines
Quoted 2 lines
Or we can make sure during the review that it's not an issue (and ignore out of tree drivers)?
Yes, the framework guarantees if the critical trip point is crossed we call the emergency shutdown by default. If the driver choose to override it, it takes responsibility of the change.
Fair enough. Thus, the patch LGTM
Regards,
Lukasz
[thermal: thermal/next] thermal/core: Add critical and hot ops
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: d7203eedf4f68e9909fd489453168a9d26bf0c3d Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//d7203eedf4f68e9909fd489453168a9d26bf0c3d Author: Daniel Lezcano <[email protected]> AuthorDate: Thu, 10 Dec 2020 13:15:11 +01:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Fri, 11 Dec 2020 14:11:13 +01:00
thermal/core: Add critical and hot ops
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling thermal_zone_device_update assuming all the trip points are defined.
A sensor may want to do something special if a trip point is hot or critical.
This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones.
--- drivers/thermal/thermal_core.c | 43 ++++++++++++++++++++------------- include/linux/thermal.h | 3 ++- 2 files changed, 30 insertions(+), 16 deletions(-)
drivers/thermal/thermal_core.c +27 -16
@@ -380,6 +380,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical (struct thermal_zone_device *tz) +{ +dev_emerg (&tz->device,"%s: critical temperature reached, " +"shutting down\n" , tz->type); + +mutex_lock (&poweroff_lock); +if (!power_off_triggered) { +/* +* Queue a backup emergency shutdown in the event of +* orderly_poweroff failure +*/ +thermal_emergency_poweroff (); +orderly_poweroff (true); + power_off_triggered = true; + } +mutex_unlock (&poweroff_lock); +} +EXPORT_SYMBOL (thermal_zone_device_critical); +static void handle_critical_trips (struct thermal_zone_device *tz,int trip,enum thermal_trip_type trip_type) {
@@ -396,22 +415,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,if (tz->ops->notify) tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_CRITICAL ) { -dev_emerg (&tz->device, -"critical temperature reached (%d C), shutting down\n" , - tz->temperature /1000 ); -mutex_lock (&poweroff_lock); -if (!power_off_triggered) { -/* -* Queue a backup emergency shutdown in the event of -* orderly_poweroff failure -*/ -thermal_emergency_poweroff (); -orderly_poweroff (true); - power_off_triggered = true; - } -mutex_unlock (&poweroff_lock); - } +if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot (tz); +else if (trip_type ==THERMAL_TRIP_CRITICAL ) + tz->ops->critical (tz); }static void handle_thermal_trip (struct thermal_zone_device *tz,int trip)
@@ -1336,6 +1343,10 @@ thermal_zone_device_register(const char *type, int trips, int mask, tz->id = id;strlcpy (tz->type, type,sizeof (tz->type)); + +if (!ops->critical) + ops->critical = thermal_zone_device_critical; + tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class;
include/linux/thermal.h +3 -0
@@ -79,6 +79,8 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +void (*hot)(struct thermal_zone_device *); +void (*critical)(struct thermal_zone_device *); };struct thermal_cooling_device_ops {
@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);void thermal_notify_framework (struct thermal_zone_device *,int );int thermal_zone_device_enable (struct thermal_zone_device *tz);int thermal_zone_device_disable (struct thermal_zone_device *tz); +void thermal_zone_device_critical (struct thermal_zone_device *tz);#else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,
PATCH 3/5 thermal/drivers/acpi: Use hot and critical ops
In reply to Daniel LezcanoThe acpi driver wants to do a netlink notification in case of a hot or critical trip point. Implement the corresponding ops to be used for the thermal zone and use them instead of the notify ops.
--- drivers/acpi/thermal.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/acpi/thermal.c +14 -16
@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,return 0 ; } - -static int thermal_notify (struct thermal_zone_device *thermal,int trip, -enum thermal_trip_type trip_type) +static void acpi_thermal_zone_device_hot (struct thermal_zone_device *thermal) { -u8 type =0 ;struct acpi_thermal *tz = thermal->devdata; -if (trip_type ==THERMAL_TRIP_CRITICAL ) - type =ACPI_THERMAL_NOTIFY_CRITICAL ; -else if (trip_type ==THERMAL_TRIP_HOT ) - type =ACPI_THERMAL_NOTIFY_HOT ; -else -return 0 ; -acpi_bus_generate_netlink_event (tz->device->pnp.device_class, -dev_name (&tz->device->dev), type,1 ); +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_HOT ,1 ); +} -if (trip_type ==THERMAL_TRIP_CRITICAL && nocrt) -return 1 ; +static void acpi_thermal_zone_device_critical (struct thermal_zone_device *thermal) +{ +struct acpi_thermal *tz = thermal->devdata; -return 0 ; +acpi_bus_generate_netlink_event (tz->device->pnp.device_class, +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_CRITICAL ,1 ); + +thermal_zone_device_critical (thermal); } static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, .get_trend = thermal_get_trend, - .notify = thermal_notify, + .hot = acpi_thermal_zone_device_hot, + .critical = acpi_thermal_zone_device_critical, };static int acpi_thermal_register_thermal_zone (struct acpi_thermal *tz)
Signature · 1 line
2.17.1
Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
Quoted 5 lines · Daniel Lezcano
The acpi driver wants to do a netlink notification in case of a hot or critical trip point. Implement the corresponding ops to be used for the thermal zone and use them instead of the notify ops.
Signed-off-by Daniel Lezcano <[email protected]>
Is there any comment on this patch ?
Quoted 59 lines
--- drivers/acpi/thermal.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)drivers/acpi/thermal.c +14
-16@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,return 0 ; } - -static int thermal_notify (struct thermal_zone_device *thermal,int trip, -enum thermal_trip_type trip_type) +static void acpi_thermal_zone_device_hot (struct thermal_zone_device *thermal) { -u8 type =0 ;struct acpi_thermal *tz = thermal->devdata; -if (trip_type ==THERMAL_TRIP_CRITICAL ) - type =ACPI_THERMAL_NOTIFY_CRITICAL ; -else if (trip_type ==THERMAL_TRIP_HOT ) - type =ACPI_THERMAL_NOTIFY_HOT ; -else -return 0 ; -acpi_bus_generate_netlink_event (tz->device->pnp.device_class, -dev_name (&tz->device->dev), type,1 ); +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_HOT ,1 ); +} -if (trip_type ==THERMAL_TRIP_CRITICAL && nocrt) -return 1 ; +static void acpi_thermal_zone_device_critical (struct thermal_zone_device *thermal) +{ +struct acpi_thermal *tz = thermal->devdata; -return 0 ; +acpi_bus_generate_netlink_event (tz->device->pnp.device_class, +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_CRITICAL ,1 ); + +thermal_zone_device_critical (thermal); } static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, .get_trend = thermal_get_trend, - .notify = thermal_notify, + .hot = acpi_thermal_zone_device_hot, + .critical = acpi_thermal_zone_device_critical, };static int acpi_thermal_register_thermal_zone (struct acpi_thermal *tz)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
Quoted 9 lines · Daniel Lezcano
Quoted 6 lines · Daniel Lezcano
The acpi driver wants to do a netlink notification in case of a hot or
critical trip point. Implement the corresponding ops to be used for the thermal zone and use them instead of the notify ops.Signed-off-by Daniel Lezcano <[email protected]>Is there any comment on this patch ?
Looks good to me.
Thanks,
Srinivas
Quoted 74 lines
Quoted 72 lines
---
drivers/acpi/thermal.c | 30 ++++++++++++++----------------1 file changed, 14 insertions(+), 16 deletions(-)drivers/acpi/thermal.c +0
-0@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal, return 0; }drivers/acpi/thermal.c +0
-2- -static int thermal_notify(struct thermal_zone_device *thermal, inttrip,
- enumthermal_trip_typetrip_type) +static voidacpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
{
- u8 type = 0;
structacpi_thermal*tz =thermal->devdata;
- if (trip_type==THERMAL_TRIP_CRITICAL)
- type =ACPI_THERMAL_NOTIFY_CRITICAL; - else if (trip_type==THERMAL_TRIP_HOT)
- type =ACPI_THERMAL_NOTIFY_HOT;
- else
- return 0;
-
acpi_bus_generate_netlink_event(tz->device-Quoted 1 line
pnp.device_class,
- dev_name(&tz->device->dev), type, 1);
+ dev_name(&tz->device->dev), + ACPI_THERMAL_NOTIFY_HOT, 1);
+}
- if (trip_type==THERMAL_TRIP_CRITICAL&& nocrt) - return 1;
+static voidacpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
+{
+ structacpi_thermal*tz =thermal->devdata;
- return 0;
+ acpi_bus_generate_netlink_event(tz->device-Quoted 1 line
pnp.device_class,
+ dev_name(&tz->device->dev), + ACPI_THERMAL_NOTIFY_CRITICA L, 1);
+
+ thermal_zone_device_critical(thermal);
}
static int acpi_thermal_cooling_device_cb(structthermal_zone_device*thermal,drivers/acpi/thermal.c +2
-1@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, .get_trend = thermal_get_trend, - .notify = thermal_notify, + .hot = acpi_thermal_zone_device_hot, + .critical = acpi_thermal_zone_device_critical, };
static intacpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
Quoted 7 lines · Srinivas Pandruvada
Quoted 6 lines · Daniel Lezcano
Quoted 5 lines · Daniel Lezcano
The acpi driver wants to do a netlink notification in case of a hot or
critical trip point. Implement the corresponding ops to be used for the thermal zone and use them instead of the notify ops.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Daniel Lezcano <[email protected]>Is there any comment on this patch ?
Looks good to me.
Thanks for reviewing
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
[thermal: thermal/next] thermal/drivers/acpi: Use hot and critical ops
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: a73cb2024caa3480263a009dce91fa581b3748bf Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a73cb2024caa3480263a009dce91fa581b3748bf Author: Daniel Lezcano <[email protected]> AuthorDate: Thu, 10 Dec 2020 13:15:12 +01:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 07 Jan 2021 17:48:55 +01:00
thermal/drivers/acpi: Use hot and critical ops
The acpi driver wants to do a netlink notification in case of a hot or critical trip point. Implement the corresponding ops to be used for the thermal zone and use them instead of the notify ops.
--- drivers/acpi/thermal.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/acpi/thermal.c +14 -16
@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,return 0 ; } - -static int thermal_notify (struct thermal_zone_device *thermal,int trip, -enum thermal_trip_type trip_type) +static void acpi_thermal_zone_device_hot (struct thermal_zone_device *thermal) { -u8 type =0 ;struct acpi_thermal *tz = thermal->devdata; -if (trip_type ==THERMAL_TRIP_CRITICAL ) - type =ACPI_THERMAL_NOTIFY_CRITICAL ; -else if (trip_type ==THERMAL_TRIP_HOT ) - type =ACPI_THERMAL_NOTIFY_HOT ; -else -return 0 ; -acpi_bus_generate_netlink_event (tz->device->pnp.device_class, -dev_name (&tz->device->dev), type,1 ); +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_HOT ,1 ); +} -if (trip_type ==THERMAL_TRIP_CRITICAL && nocrt) -return 1 ; +static void acpi_thermal_zone_device_critical (struct thermal_zone_device *thermal) +{ +struct acpi_thermal *tz = thermal->devdata; -return 0 ; +acpi_bus_generate_netlink_event (tz->device->pnp.device_class, +dev_name (&tz->device->dev), +ACPI_THERMAL_NOTIFY_CRITICAL ,1 ); + +thermal_zone_device_critical (thermal); } static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .get_trip_temp = thermal_get_trip_temp, .get_crit_temp = thermal_get_crit_temp, .get_trend = thermal_get_trend, - .notify = thermal_notify, + .hot = acpi_thermal_zone_device_hot, + .critical = acpi_thermal_zone_device_critical, };static int acpi_thermal_register_thermal_zone (struct acpi_thermal *tz)
PATCH 4/5 thermal/drivers/rcar: Remove notification usage
In reply to Daniel LezcanoThe ops is only showing a trace telling a critical trip point is crossed. The same information is given by the thermal framework.
This is redundant, remove the code.
--- drivers/thermal/rcar_thermal.c | 19 ------------------- 1 file changed, 19 deletions(-)
drivers/thermal/rcar_thermal.c +0 -19
@@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,return 0 ; } -static int rcar_thermal_notify (struct thermal_zone_device *zone, -int trip,enum thermal_trip_type type) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -switch (type) { -case THERMAL_TRIP_CRITICAL : -/* FIXME */ -dev_warn (dev,"Thermal reached to critical temperature\n" ); -break ; -default : -break ; - } - -return 0 ; -} -static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = { .get_temp = rcar_thermal_of_get_temp, };
@@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = { .get_temp = rcar_thermal_get_temp, .get_trip_type = rcar_thermal_get_trip_type, .get_trip_temp = rcar_thermal_get_trip_temp, - .notify = rcar_thermal_notify, };/*
Signature · 1 line
2.17.1
Re: [PATCH 4/5] thermal/drivers/rcar: Remove notification usage
Hi Daniel,
Thanks for your work.
Quoted 6 lines · Daniel Lezcano
The ops is only showing a trace telling a critical trip point is crossed. The same information is given by the thermal framework.
This is redundant, remove the code.
Signed-off-by Daniel Lezcano <[email protected]>
Quoted 44 lines
--- drivers/thermal/rcar_thermal.c | 19 ------------------- 1 file changed, 19 deletions(-)drivers/thermal/rcar_thermal.c +0
-19@@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,return 0 ; } -static int rcar_thermal_notify (struct thermal_zone_device *zone, -int trip,enum thermal_trip_type type) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -switch (type) { -case THERMAL_TRIP_CRITICAL : -/* FIXME */ -dev_warn (dev,"Thermal reached to critical temperature\n" ); -break ; -default : -break ; - } - -return 0 ; -} -static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = { .get_temp = rcar_thermal_of_get_temp, };@@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = { .get_temp = rcar_thermal_get_temp, .get_trip_type = rcar_thermal_get_trip_type, .get_trip_temp = rcar_thermal_get_trip_temp, - .notify = rcar_thermal_notify, };/* Signature · 1 line
2.17.1
Signature · 2 lines
Regards, Niklas Söderlund
[thermal: thermal/next] thermal/drivers/rcar: Remove notification usage
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 1fa34e49e4b7e66214a1d15261c0224d60366eec Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//1fa34e49e4b7e66214a1d15261c0224d60366eec Author: Daniel Lezcano <[email protected]> AuthorDate: Thu, 10 Dec 2020 13:15:13 +01:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Tue, 15 Dec 2020 17:01:55 +01:00
thermal/drivers/rcar: Remove notification usage
The ops is only showing a trace telling a critical trip point is crossed. The same information is given by the thermal framework.
This is redundant, remove the code.
--- drivers/thermal/rcar_thermal.c | 19 ------------------- 1 file changed, 19 deletions(-)
drivers/thermal/rcar_thermal.c +0 -19
@@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,return 0 ; } -static int rcar_thermal_notify (struct thermal_zone_device *zone, -int trip,enum thermal_trip_type type) -{ -struct rcar_thermal_priv *priv =rcar_zone_to_priv (zone); -struct device *dev =rcar_priv_to_dev (priv); - -switch (type) { -case THERMAL_TRIP_CRITICAL : -/* FIXME */ -dev_warn (dev,"Thermal reached to critical temperature\n" ); -break ; -default : -break ; - } - -return 0 ; -} -static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = { .get_temp = rcar_thermal_of_get_temp, };
@@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = { .get_temp = rcar_thermal_get_temp, .get_trip_type = rcar_thermal_get_trip_type, .get_trip_temp = rcar_thermal_get_trip_temp, - .notify = rcar_thermal_notify, };/*
PATCH 5/5 thermal/core: Remove notify ops
In reply to Daniel LezcanoWith the remove of the notify user in a previous patch, the ops is no longer needed, remove it.
--- drivers/thermal/thermal_core.c | 3 --- include/linux/thermal.h | 2 -- 2 files changed, 5 deletions(-)
drivers/thermal/thermal_core.c +0 -3
@@ -407,9 +407,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,trace_thermal_zone_trip (tz, trip, trip_type); -if (tz->ops->notify) - tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) tz->ops->hot (tz);else if (trip_type ==THERMAL_TRIP_CRITICAL )
include/linux/thermal.h +0 -2
@@ -77,8 +77,6 @@ struct thermal_zone_device_ops {int (*set_emul_temp) (struct thermal_zone_device *,int );int (*get_trend) (struct thermal_zone_device *,int ,enum thermal_trend *); -int (*notify) (struct thermal_zone_device *,int , -enum thermal_trip_type );void (*hot)(struct thermal_zone_device *);void (*critical)(struct thermal_zone_device *); };
Signature · 1 line
2.17.1
Re: [PATCH 5/5] thermal/core: Remove notify ops
Quoted 29 lines · Daniel Lezcano
With the remove of the notify user in a previous patch, the ops is no longer needed, remove it.
Signed-off-by Daniel Lezcano <[email protected]>--- drivers/thermal/thermal_core.c | 3 --- include/linux/thermal.h | 2 -- 2 files changed, 5 deletions(-)drivers/thermal/thermal_core.c +0
-3@@ -407,9 +407,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,trace_thermal_zone_trip (tz, trip, trip_type); -if (tz->ops->notify) - tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) tz->ops->hot (tz);else if (trip_type ==THERMAL_TRIP_CRITICAL )include/linux/thermal.h +0
-0
include/linux/thermal.h struct thermal_zone_device_ops { · line 82
Quoted 8 lines
include/linux/thermal.h +0
-2@@ -77,8 +77,6 @@ struct thermal_zone_device_ops {int (*set_emul_temp) (struct thermal_zone_device *,int );int (*get_trend) (struct thermal_zone_device *,int ,enum thermal_trend *); -int (*notify) (struct thermal_zone_device *,int , -enum thermal_trip_type );void (*hot)(struct thermal_zone_device *);void (*critical)(struct thermal_zone_device *); };
I couldn't find other users apart from those in patch 3/5 and 4/5. I will leave to someone else to review those patches. This patch looks good
[thermal: thermal/next] thermal/core: Remove notify ops
In reply to Daniel LezcanoThe following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 04f111130e9afa41c10d7bcec14e00e3be8b6977 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//04f111130e9afa41c10d7bcec14e00e3be8b6977 Author: Daniel Lezcano <[email protected]> AuthorDate: Thu, 10 Dec 2020 13:15:14 +01:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 07 Jan 2021 17:48:56 +01:00
thermal/core: Remove notify ops
With the removal of the notifys user in a previous patches, the ops is no longer needed, remove it.
--- drivers/thermal/thermal_core.c | 3 --- include/linux/thermal.h | 2 -- 2 files changed, 5 deletions(-)
drivers/thermal/thermal_core.c +0 -3
@@ -412,9 +412,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,trace_thermal_zone_trip (tz, trip, trip_type); -if (tz->ops->notify) - tz->ops->notify (tz, trip, trip_type); -if (trip_type ==THERMAL_TRIP_HOT && tz->ops->hot) tz->ops->hot (tz);else if (trip_type ==THERMAL_TRIP_CRITICAL )
include/linux/thermal.h +0 -2
@@ -77,8 +77,6 @@ struct thermal_zone_device_ops {int (*set_emul_temp) (struct thermal_zone_device *,int );int (*get_trend) (struct thermal_zone_device *,int ,enum thermal_trend *); -int (*notify) (struct thermal_zone_device *,int , -enum thermal_trip_type );void (*hot)(struct thermal_zone_device *);void (*critical)(struct thermal_zone_device *); };
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 433178e75834dc35f1ae79b56ec2cf396f2c6f3c Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//433178e75834dc35f1ae79b56ec2cf396f2c6f3c Author: Daniel Lezcano <[email protected]> AuthorDate: Thu, 10 Dec 2020 13:15:10 +01:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Fri, 11 Dec 2020 14:11:13 +01:00
thermal/core: Emit a warning if the thermal zone is updated without ops
The actual code is silently ignoring a thermal zone update when a driver is requesting it without a get_temp ops set.
That looks not correct, as the caller should not have called this function if the thermal zone is unable to read the temperature.
That makes the code less robust as the check won't detect the driver is inconsistently using the thermal API and that does not help to improve the framework as these circumvolutions hide the problem at the source.
In order to detect the situation when it happens, let's add a warning when the update is requested without the get_temp() ops set.
Any warning emitted will have to be fixed at the source of the
problem: the caller must not call thermal_zone_device_update if there is not get_temp callback set.
--- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +2 -1
@@ -553,7 +553,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,if (atomic_read (&in_suspend))return ; -if (!tz->ops->get_temp) +if (WARN_ONCE (!tz->ops->get_temp,"'%s' must not be called without " +"'get_temp' ops set\n" , __func__))return ;update_temperature (tz);