Skip to content

Commit 79fa723

Browse files
Fabio Estevamdlezcano
authored andcommitted
reboot: Introduce thermal_zone_device_critical_reboot()
Introduce thermal_zone_device_critical_reboot() to trigger an emergency reboot. It is a counterpart of thermal_zone_device_critical() with the difference that it will force a reboot instead of shutdown. The motivation for doing this is to allow the thermal subystem to trigger a reboot when the temperature reaches the critical temperature. Signed-off-by: Fabio Estevam <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5a0e241 commit 79fa723

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

drivers/thermal/thermal_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ static void thermal_zone_device_halt(struct thermal_zone_device *tz, bool shutdo
324324

325325
if (shutdown)
326326
hw_protection_shutdown(msg, poweroff_delay_ms);
327+
else
328+
hw_protection_reboot(msg, poweroff_delay_ms);
327329
}
328330

329331
void thermal_zone_device_critical(struct thermal_zone_device *tz)
@@ -332,6 +334,11 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz)
332334
}
333335
EXPORT_SYMBOL(thermal_zone_device_critical);
334336

337+
void thermal_zone_device_critical_reboot(struct thermal_zone_device *tz)
338+
{
339+
thermal_zone_device_halt(tz, false);
340+
}
341+
335342
static void handle_critical_trips(struct thermal_zone_device *tz,
336343
const struct thermal_trip *trip)
337344
{

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
114114
int thermal_build_list_of_policies(char *buf);
115115
void __thermal_zone_device_update(struct thermal_zone_device *tz,
116116
enum thermal_notify_event event);
117+
void thermal_zone_device_critical_reboot(struct thermal_zone_device *tz);
117118

118119
/* Helpers */
119120
#define for_each_trip(__tz, __trip) \

include/linux/reboot.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ extern void orderly_poweroff(bool force);
179179
extern void orderly_reboot(void);
180180
void __hw_protection_shutdown(const char *reason, int ms_until_forced, bool shutdown);
181181

182+
static inline void hw_protection_reboot(const char *reason, int ms_until_forced)
183+
{
184+
__hw_protection_shutdown(reason, ms_until_forced, false);
185+
}
186+
182187
static inline void hw_protection_shutdown(const char *reason, int ms_until_forced)
183188
{
184189
__hw_protection_shutdown(reason, ms_until_forced, true);

kernel/reboot.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -957,19 +957,22 @@ static void hw_failure_emergency_poweroff(int poweroff_delay_ms)
957957
}
958958

959959
/**
960-
* __hw_protection_shutdown - Trigger an emergency system poweroff
960+
* __hw_protection_shutdown - Trigger an emergency system shutdown or reboot
961961
*
962-
* @reason: Reason of emergency shutdown to be printed.
963-
* @ms_until_forced: Time to wait for orderly shutdown before tiggering a
964-
* forced shudown. Negative value disables the forced
965-
* shutdown.
962+
* @reason: Reason of emergency shutdown or reboot to be printed.
963+
* @ms_until_forced: Time to wait for orderly shutdown or reboot before
964+
* triggering it. Negative value disables the forced
965+
* shutdown or reboot.
966+
* @shutdown: If true, indicates that a shutdown will happen
967+
* after the critical tempeature is reached.
968+
* If false, indicates that a reboot will happen
969+
* after the critical tempeature is reached.
966970
*
967-
* Initiate an emergency system shutdown in order to protect hardware from
968-
* further damage. Usage examples include a thermal protection or a voltage or
969-
* current regulator failures.
970-
* NOTE: The request is ignored if protection shutdown is already pending even
971-
* if the previous request has given a large timeout for forced shutdown.
972-
* Can be called from any context.
971+
* Initiate an emergency system shutdown or reboot in order to protect
972+
* hardware from further damage. Usage examples include a thermal protection.
973+
* NOTE: The request is ignored if protection shutdown or reboot is already
974+
* pending even if the previous request has given a large timeout for forced
975+
* shutdown/reboot.
973976
*/
974977
void __hw_protection_shutdown(const char *reason, int ms_until_forced, bool shutdown)
975978
{
@@ -988,7 +991,10 @@ void __hw_protection_shutdown(const char *reason, int ms_until_forced, bool shut
988991
hw_failure_emergency_poweroff(ms_until_forced);
989992
if (shutdown)
990993
orderly_poweroff(true);
994+
else
995+
orderly_reboot();
991996
}
997+
EXPORT_SYMBOL_GPL(__hw_protection_shutdown);
992998

993999
static int __init reboot_setup(char *str)
9941000
{

0 commit comments

Comments
 (0)