Skip to contentSkip to conversation

thermal: core: skip update disabled thermal zones after suspend

PATCH In review Wei Wang 2 participants 5 messages Apr 16, 2019 – Apr 23, 2019 Thermal

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH 1/1 thermal: core: skip update disabled thermal zones after suspend

It is unnecessary to update disabled thermal zones post suspend and sometimes leads error/warning in bad behaved thermal drivers.

---
 drivers/thermal/thermal_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +8 -0
index 6590bb5cb688..5baf5cfab999 100644
@@ -1494,6 +1494,7 @@ static int thermal_pm_notify(struct notifier_block *nb,
 			     unsigned long mode, void *_unused)
 {
 	struct thermal_zone_device *tz;
+	enum thermal_device_mode tz_mode;
 
 	switch (mode) {
 	case PM_HIBERNATION_PREPARE:
@@ -1506,6 +1507,13 @@ static int thermal_pm_notify(struct notifier_block *nb,
 	case PM_POST_SUSPEND:
 		atomic_set(&in_suspend, 0);
 		list_for_each_entry(tz, &thermal_tz_list, node) {
+			tz_mode = THERMAL_DEVICE_ENABLED;
+			if (tz->ops->get_mode)
+				tz->ops->get_mode(tz, &tz_mode);
+
+			if (tz_mode == THERMAL_DEVICE_DISABLED)
+				continue;
+
 			thermal_zone_device_init(tz);
 			thermal_zone_device_update(tz,
 						   THERMAL_EVENT_UNSPECIFIED);
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
reviewer
#1 lore raw
Quoted 3 lines · Wei Wang

It is unnecessary to update disabled thermal zones post suspend and sometimes leads error/warning in bad behaved thermal drivers.

a good catch, and in fact, there are more issues about thermal handling for disabled thermal zones, like we're able to read the temperature of disabled thermal zones, either via sysfs or via function calls like thermal_zone_device_update.
For this patch, I will take it as it fixes one of the problem.

thanks,
rui

Quoted 35 lines

---
 drivers/thermal/thermal_core.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +1 -0
index 6590bb5cb688..5baf5cfab999 100644
@@ -1494,6 +1494,7 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
  			     unsigned long mode, void *_unused)
  {
  	struct thermal_zone_device *tz;
+	enum thermal_device_mode tz_mode;


  switch (mode) {
  case PM_HIBERNATION_PREPARE:

drivers/thermal/thermal_core.c +0 -0
@@ -1506,6 +1507,13 @@ static int thermal_pm_notify(struct
 notifier_block *nb,

  case PM_POST_SUSPEND:
  atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) {

drivers/thermal/thermal_core.c +7 -0
+			tz_mode = THERMAL_DEVICE_ENABLED;
+			if (tz->ops->get_mode)
+				tz->ops->get_mode(tz, &tz_mode);
+
+			if (tz_mode == THERMAL_DEVICE_DISABLED)
+				continue;
+

  thermal_zone_device_init(tz); thermal_zone_device_update(tz, THERMAL_EVENT_UNS PECIFIED);

author
#2 lore raw
Quoted 9 lines · Zhang Rui
Quoted 3 lines · Wei Wang

It is unnecessary to update disabled thermal zones post suspend and sometimes leads error/warning in bad behaved thermal drivers.

a good catch, and in fact, there are more issues about thermal handling for disabled thermal zones, like we're able to read the temperature of disabled thermal zones, either via sysfs or via function calls like thermal_zone_device_update.

Thanks Rui for following up. Yes, we noticed the same behavior. Right now, individual thermal driver can still respect set_mode and present value meaningful or return error when thermal zone disabled, and that's what we do locally.
Currently, sysfs-api documents "Preventing kernel thermal zone driver actions upon trip points so that user application can take full charge of the thermal management.", so is it intended for some other agents in kernel or user land polling temperature with function call or sysfs respectively?

Thanks!
-Wei

Quoted 40 lines

For this patch, I will take it as it fixes one of the problem.

thanks,
rui

Quoted 35 lines
---
 drivers/thermal/thermal_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +1 -0
index 6590bb5cb688..5baf5cfab999 100644
@@ -1494,6 +1494,7 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
                           unsigned long mode, void *_unused)
 {
      struct thermal_zone_device *tz;
+     enum thermal_device_mode tz_mode;
 
      switch (mode) {

case PM_HIBERNATION_PREPARE:

drivers/thermal/thermal_core.c +7 -0
@@ -1506,6 +1507,13 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
      case PM_POST_SUSPEND:
              atomic_set(&in_suspend, 0);
              list_for_each_entry(tz, &thermal_tz_list, node) {
+                     tz_mode = THERMAL_DEVICE_ENABLED;
+                     if (tz->ops->get_mode)
+                             tz->ops->get_mode(tz, &tz_mode);
+
+                     if (tz_mode == THERMAL_DEVICE_DISABLED)
+                             continue;
+
                      thermal_zone_device_init(tz);
                      thermal_zone_device_update(tz,

THERMAL_EVENT_UNS
PECIFIED);

reviewer
#3 lore raw
Quoted 16 lines · Wei Wang
Quoted 8 lines · Zhang Rui
Quoted 5 lines · Wei Wang

It is unnecessary to update disabled thermal zones post suspend and
sometimes leads error/warning in bad behaved thermal drivers.

Quoted 6 lines

a good catch, and in fact, there are more issues about thermal handling
for disabled thermal zones, like we're able to read the temperature of
disabled thermal zones, either via sysfs or via function calls like thermal_zone_device_update.

Quoted 11 lines

Thanks Rui for following up. Yes, we noticed the same behavior. Right now, individual thermal driver can still respect set_mode and present value meaningful or return error when thermal zone disabled, and that's what we do locally.
Currently, sysfs-api documents "Preventing kernel thermal zone driver actions upon trip points so that user application can take full charge
of the thermal management.", so is it intended for some other agents in kernel or user land polling temperature with function call or sysfs
respectively?

hmmm, here we have three cases,
1). we can read the temperature and we can take cooling actions. 2). we can read the temperature only
3). we can not read the temperature

we do have a case for 3), e.g. the wifi device, which registers a thermal zone, but it does not work if wifi firmware is unloaded. And IMO, we should set the thermal zone mode to disable for this case.

I'm not sure if there is any case for 2), but if we do, it seems to me that we should set its governor to nop, rather then the way we're describing in the sys-abi file.

we should fix the code and doc to use "mode" attribute to handle case
3) instead.

thanks,
rui

Quoted 46 lines

Thanks!
-Wei

Quoted 43 lines

For this patch, I will take it as it fixes one of the problem.

thanks,
rui

Quoted 37 lines

---
 drivers/thermal/thermal_core.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +1 -0
index 6590bb5cb688..5baf5cfab999 100644
@@ -1494,6 +1494,7 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
                            unsigned long mode, void *_unused)
  {
       struct thermal_zone_device *tz;
+     enum thermal_device_mode tz_mode;
 
       switch (mode) {

      case PM_HIBERNATION_PREPARE:

drivers/thermal/thermal_core.c +0 -0
@@ -1506,6 +1507,13 @@ static int thermal_pm_notify(struct
 notifier_block *nb,

      case PM_POST_SUSPEND:
              atomic_set(&in_suspend, 0); list_for_each_entry(tz, &thermal_tz_list, node) { +                     tz_mode = THERMAL_DEVICE_ENABLED; +                     if (tz->ops->get_mode)
+                             tz->ops->get_mode(tz, &tz_mode);

drivers/thermal/thermal_core.c +4 -0
+
+                     if (tz_mode == THERMAL_DEVICE_DISABLED)
+                             continue;
+

                      thermal_zone_device_init(tz); thermal_zone_device_update(tz, THERMAL_EVENT_UN S
PECIFIED);

author
#4 lore raw
Quoted 30 lines · Zhang Rui
Quoted 16 lines · Wei Wang
Quoted 8 lines · Zhang Rui
Quoted 5 lines · Wei Wang

It is unnecessary to update disabled thermal zones post suspend and
sometimes leads error/warning in bad behaved thermal drivers.

Quoted 6 lines

a good catch, and in fact, there are more issues about thermal handling
for disabled thermal zones, like we're able to read the temperature of
disabled thermal zones, either via sysfs or via function calls like thermal_zone_device_update.

Quoted 11 lines

Thanks Rui for following up. Yes, we noticed the same behavior. Right now, individual thermal driver can still respect set_mode and present value meaningful or return error when thermal zone disabled, and that's what we do locally.
Currently, sysfs-api documents "Preventing kernel thermal zone driver actions upon trip points so that user application can take full charge
of the thermal management.", so is it intended for some other agents in kernel or user land polling temperature with function call or sysfs
respectively?

Quoted 8 lines

hmmm, here we have three cases,
1). we can read the temperature and we can take cooling actions. 2). we can read the temperature only
3). we can not read the temperature

we do have a case for 3), e.g. the wifi device, which registers a thermal zone, but it does not work if wifi firmware is unloaded. And IMO, we should set the thermal zone mode to disable for this case.

Agree.

Another thought of suspend/resume case is in mobile world, most of the thermal zone sensors are interrupt capable and the linked cooling devices are platform cooling devices whose states won't be affected during suspend. So resetting each thermal zone during suspend/resume just wasted cycles/power on mobile due to re-setting trip threshold again and again and also delays in device resume. I am proposing that we have a flag in device tree per thermal zone to let thermal core not reset during suspend/resume.

Quoted 3 lines

I'm not sure if there is any case for 2), but if we do, it seems to me that we should set its governor to nop, rather then the way we're describing in the sys-abi file.

+1 noop sounds good. Do you have plan to change it?

Quoted 52 lines

we should fix the code and doc to use "mode" attribute to handle case
3) instead.

thanks,
rui

Quoted 46 lines

Thanks!
-Wei

Quoted 43 lines

For this patch, I will take it as it fixes one of the problem.

thanks,
rui

Quoted 37 lines
---
 drivers/thermal/thermal_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/thermal/thermal_core.c +1 -0
index 6590bb5cb688..5baf5cfab999 100644
@@ -1494,6 +1494,7 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
                           unsigned long mode, void *_unused)
 {
      struct thermal_zone_device *tz;
+     enum thermal_device_mode tz_mode;
 
      switch (mode) {

case PM_HIBERNATION_PREPARE:

drivers/thermal/thermal_core.c +7 -0
@@ -1506,6 +1507,13 @@ static int thermal_pm_notify(struct
 notifier_block *nb,
      case PM_POST_SUSPEND:
              atomic_set(&in_suspend, 0);
              list_for_each_entry(tz, &thermal_tz_list, node) {
+                     tz_mode = THERMAL_DEVICE_ENABLED;
+                     if (tz->ops->get_mode)
+                             tz->ops->get_mode(tz, &tz_mode);
+
+                     if (tz_mode == THERMAL_DEVICE_DISABLED)
+                             continue;
+
                      thermal_zone_device_init(tz);
                      thermal_zone_device_update(tz,

THERMAL_EVENT_UN
S
PECIFIED);