thermal: Avoid scheduling work during poweroff
Rohit Vaswani [Wed, 20 Jul 2016 02:01:17 +0000 (19:01 -0700)]
During a critical thermal trip, orderly_poweroff is called.
However, if the userspace is slow to react to poweroff (systemd),
and the thermal zone is configured with polling mode because of
either polling_delay or passive_delay, thermal_core may end up
in calling orderly_poweroff multiple times.
This eventually slows the userspace even more by
scheduling overwhelming number of threads in the system.

Relevant dump_stack spew during the shutdown process:
 dump_backtrace+0x0/0xf4
 show_stack+0x14/0x1c
 dump_stack+0x20/0x28
 handle_critical_trips+0x80/0xa0
 handle_thermal_trip+0x40/0x64
 thermal_zone_device_update+0xf0/0x110
 thermal_zone_device_check+0x10/0x18
 process_one_work+0x274/0x430
 worker_thread+0x184/0x294
 kthread+0xc0/0xc8

We should not try to spawn-off more threads once we have
decided to shutdown i.e. we should disable polling mode
once it is known that a critical trip is going to result
in a poweroff. This patch does that by setting the polling
and passive delay to zero which cancels the repeated work
and allows userspace to shutdown.

Change-Id: Ia8714c288f9a332dc8ea7a3ffc7156fc6095ed9e
Signed-off-by: Rohit Vaswani <rvaswani@nvidia.com>
Reviewed-on: http://git-master/r/1183768
Reviewed-by: Navneet Kumar <navneetk@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Wen Yi <wyi@nvidia.com>
Reviewed-by: Ninad Malwade <nmalwade@nvidia.com>
Reviewed-by: Bibek Basu <bbasu@nvidia.com>

drivers/thermal/thermal_core.c

index a5f212a..4a47a4b 100644 (file)
@@ -376,6 +376,8 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
                dev_emerg(&tz->device,
                          "critical temperature reached(%d C),shutting down\n",
                          tz->temperature / 1000);
+               tz->passive_delay = 0;
+               tz->polling_delay = 0;
                orderly_poweroff(true);
        }
 }