thermal/core: Emit a warning if the thermal zone is updated without ops
Subsystems (3)
RFC PATCH 1/4 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" , __FUNCTION__))return ;update_temperature (tz);
Signature · 1 line
2.17.1
RFC PATCH 2/4 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 | 42 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++ 2 files changed, 29 insertions(+), 16 deletions(-)
drivers/thermal/thermal_core.c +26 -16
@@ -375,6 +375,24 @@ 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); +} +static void handle_critical_trips (struct thermal_zone_device *tz,int trip,enum thermal_trip_type trip_type) {
@@ -391,22 +409,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 +1337,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
Re: [PATCH RFC 2/4] thermal/core: Add critical and hot ops
Quoted 7 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.
Quoted 8 lines
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.
Signed-off-by Daniel Lezcano <[email protected]>
Thanks. This can solve my issue once .critical callbacks are added in thermal drivers.
Quoted 96 lines
---
drivers/thermal/thermal_core.c| 42 +++++++++++++++++++++-------------include/linux/thermal.h| 3 +++2 files changed, 29 insertions(+), 16 deletions(-)drivers/thermal/thermal_core.c +26
-16@@ -375,6 +375,24 @@ 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); +} +static void handle_critical_trips (struct thermal_zone_device *tz,int trip,enum thermal_trip_type trip_type) {@@ -391,22 +409,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 +1337,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
RFC PATCH 3/4 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
kernel test robot
build botRe: [PATCH RFC 3/4] thermal/drivers/acpi: Use hot and critical ops
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on pm/linux-next]
[also build test ERROR on linux/master linus/master v5.10-rc7 next-20201209] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: i386-randconfig-a015-20201209 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/b29ce9f78e0cabc5d6f1ec5a612e4f7fdb7bf477 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 git checkout b29ce9f78e0cabc5d6f1ec5a612e4f7fdb7bf477 # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "thermal_zone_device_critical" [drivers/acpi/thermal.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH 4/4 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
@@ -406,9 +406,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
kernel test robot
build botRe: [PATCH RFC 4/4] thermal/core: Remove notify ops
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on pm/linux-next]
[also build test ERROR on linux/master linus/master v5.10-rc7 next-20201209] [cannot apply to thermal/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: nios2-randconfig-r015-20201209 (attached as .config) compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/96e276bc9b59eae0b9c1478fb4902727d9aac6c2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 git checkout 96e276bc9b59eae0b9c1478fb4902727d9aac6c2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/thermal/rcar_thermal.c:352:3: error: 'struct thermal_zone_device_ops' has no member named 'notify'
352 | .notify = rcar_thermal_notify,
| ^~~~~~
>> drivers/thermal/rcar_thermal.c:352:13: error: initialization of 'int (*)(struct thermal_zone_device *, int, int)' from incompatible pointer type 'int (*)(struct thermal_zone_device *, int, enum thermal_trip_type)' [-Werror=incompatible-pointer-types] 352 | .notify = rcar_thermal_notify,
| ^~~~~~~~~~~~~~~~~~~
drivers/thermal/rcar_thermal.c:352:13: note: (near initialization for 'rcar_thermal_zone_ops.set_trip_temp')
cc1: some warnings being treated as errors
vim +352 drivers/thermal/rcar_thermal.c
8b477ea56383dc Kuninori Morimoto 2016-01-28 347
1e426ffddf2f15 Kuninori Morimoto 2012-07-21 348 static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
1e426ffddf2f15 Kuninori Morimoto 2012-07-21 349 .get_temp = rcar_thermal_get_temp,
d2a73e225d113f Kuninori Morimoto 2012-12-02 350 .get_trip_type = rcar_thermal_get_trip_type,
d2a73e225d113f Kuninori Morimoto 2012-12-02 351 .get_trip_temp = rcar_thermal_get_trip_temp,d2a73e225d113f Kuninori Morimoto 2012-12-02 @352 .notify = rcar_thermal_notify,1e426ffddf2f15 Kuninori Morimoto 2012-07-21 353 }; 1e426ffddf2f15 Kuninori Morimoto 2012-07-21 354
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH RFC 4/4] thermal/core: Remove notify ops
In reply to Daniel Lezcano[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Daniel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on pm/linux-next]
[also build test ERROR on linux/master linus/master v5.10-rc7 next-20201209] [cannot apply to thermal/next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next config: arm64-randconfig-r005-20201210 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 1968804ac726e7674d5de22bc2204b45857da344)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/96e276bc9b59eae0b9c1478fb4902727d9aac6c2
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Daniel-Lezcano/thermal-core-Emit-a-warning-if-the-thermal-zone-is-updated-without-ops/20201209-233832 git checkout 96e276bc9b59eae0b9c1478fb4902727d9aac6c2
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/thermal/rcar_thermal.c:352:3: error: field designator 'notify' does not refer to any field in type 'struct thermal_zone_device_ops'
.notify = rcar_thermal_notify,
^
1 error generated.
vim +352 drivers/thermal/rcar_thermal.c
8b477ea56383dc Kuninori Morimoto 2016-01-28 347
1e426ffddf2f15 Kuninori Morimoto 2012-07-21 348 static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
1e426ffddf2f15 Kuninori Morimoto 2012-07-21 349 .get_temp = rcar_thermal_get_temp,
d2a73e225d113f Kuninori Morimoto 2012-12-02 350 .get_trip_type = rcar_thermal_get_trip_type,
d2a73e225d113f Kuninori Morimoto 2012-12-02 351 .get_trip_temp = rcar_thermal_get_trip_temp,d2a73e225d113f Kuninori Morimoto 2012-12-02 @352 .notify = rcar_thermal_notify,1e426ffddf2f15 Kuninori Morimoto 2012-07-21 353 }; 1e426ffddf2f15 Kuninori Morimoto 2012-07-21 354
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Hi Daniel,
Quoted 33 lines · Daniel Lezcano
The actual code is silently ignoring a thermal zone update when a driver is requesting it without a
get_tempops 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 callthermal_zone_device_updateif there is notget_tempcallback set.Cc Thara Gopinath <[email protected]>Cc Amit Kucheria <[email protected]>Signed-off-by Daniel Lezcano <[email protected]>--- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/thermal/thermal_core.c +0
-0
drivers/thermal/thermal_core.c void thermal_zone_device_update(struct thermal_zone_device *tz, · line 555
Quoted 9 lines
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" , __FUNCTION__))return ;update_temperature (tz);
With this RFC and the link that you gave me in previous thread, I see the motivation.
I would change __FUNCTION__ into __func__, but other than that LGTM.
Regards,
Lukasz