Merge "init: Do full shutdown even for thermal shutdown" am: d5b36f38ef

am: a064892e1a

Change-Id: Ia6ddd5a680caa8283cf9d2a75c1eb49e1c79e413
This commit is contained in:
Keun-young Park 2017-07-20 03:30:39 +00:00 committed by android-build-merger
commit 614ccd7a02

View file

@ -340,13 +340,6 @@ static UmountStat TryUmountAndFsck(bool runFsck, std::chrono::milliseconds timeo
return stat; return stat;
} }
static void __attribute__((noreturn)) DoThermalOff() {
LOG(WARNING) << "Thermal system shutdown";
sync();
RebootSystem(ANDROID_RB_THERMOFF, "");
abort();
}
void DoReboot(unsigned int cmd, const std::string& reason, const std::string& rebootTarget, void DoReboot(unsigned int cmd, const std::string& reason, const std::string& rebootTarget,
bool runFsck) { bool runFsck) {
Timer t; Timer t;
@ -355,19 +348,25 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
android::base::WriteStringToFile(StringPrintf("%s\n", reason.c_str()), LAST_REBOOT_REASON_FILE, android::base::WriteStringToFile(StringPrintf("%s\n", reason.c_str()), LAST_REBOOT_REASON_FILE,
S_IRUSR | S_IWUSR, AID_SYSTEM, AID_SYSTEM); S_IRUSR | S_IWUSR, AID_SYSTEM, AID_SYSTEM);
if (cmd == ANDROID_RB_THERMOFF) { // do not wait if it is thermal bool is_thermal_shutdown = false;
DoThermalOff(); if (cmd == ANDROID_RB_THERMOFF) {
abort(); is_thermal_shutdown = true;
runFsck = false;
} }
auto shutdown_timeout = 0s; auto shutdown_timeout = 0ms;
if (!SHUTDOWN_ZERO_TIMEOUT) { if (!SHUTDOWN_ZERO_TIMEOUT) {
constexpr unsigned int shutdown_timeout_default = 6; if (is_thermal_shutdown) {
auto shutdown_timeout_property = constexpr unsigned int thermal_shutdown_timeout = 1;
android::base::GetUintProperty("ro.build.shutdown_timeout", shutdown_timeout_default); shutdown_timeout = std::chrono::seconds(thermal_shutdown_timeout);
shutdown_timeout = std::chrono::seconds(shutdown_timeout_property); } else {
constexpr unsigned int shutdown_timeout_default = 6;
auto shutdown_timeout_property = android::base::GetUintProperty(
"ro.build.shutdown_timeout", shutdown_timeout_default);
shutdown_timeout = std::chrono::seconds(shutdown_timeout_property);
}
} }
LOG(INFO) << "Shutdown timeout: " << shutdown_timeout.count() << " seconds"; LOG(INFO) << "Shutdown timeout: " << shutdown_timeout.count() << " ms";
// keep debugging tools until non critical ones are all gone. // keep debugging tools until non critical ones are all gone.
const std::set<std::string> kill_after_apps{"tombstoned", "logd", "adbd"}; const std::set<std::string> kill_after_apps{"tombstoned", "logd", "adbd"};
@ -394,7 +393,7 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
// optional shutdown step // optional shutdown step
// 1. terminate all services except shutdown critical ones. wait for delay to finish // 1. terminate all services except shutdown critical ones. wait for delay to finish
if (shutdown_timeout > 0s) { if (shutdown_timeout > 0ms) {
LOG(INFO) << "terminating init services"; LOG(INFO) << "terminating init services";
// Ask all services to terminate except shutdown critical ones. // Ask all services to terminate except shutdown critical ones.
@ -403,8 +402,8 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
}); });
int service_count = 0; int service_count = 0;
// Up to half as long as shutdown_timeout or 3 seconds, whichever is lower. // Only wait up to half of timeout here
auto termination_wait_timeout = std::min((shutdown_timeout + 1s) / 2, 3s); auto termination_wait_timeout = shutdown_timeout / 2;
while (t.duration() < termination_wait_timeout) { while (t.duration() < termination_wait_timeout) {
ServiceManager::GetInstance().ReapAnyOutstandingChildren(); ServiceManager::GetInstance().ReapAnyOutstandingChildren();
@ -456,7 +455,7 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re
UmountStat stat = TryUmountAndFsck(runFsck, shutdown_timeout - t.duration()); UmountStat stat = TryUmountAndFsck(runFsck, shutdown_timeout - t.duration());
// Follow what linux shutdown is doing: one more sync with little bit delay // Follow what linux shutdown is doing: one more sync with little bit delay
sync(); sync();
std::this_thread::sleep_for(100ms); if (!is_thermal_shutdown) std::this_thread::sleep_for(100ms);
LogShutdownTime(stat, &t); LogShutdownTime(stat, &t);
// Reboot regardless of umount status. If umount fails, fsck after reboot will fix it. // Reboot regardless of umount status. If umount fails, fsck after reboot will fix it.
RebootSystem(cmd, rebootTarget); RebootSystem(cmd, rebootTarget);