From 8c00e42f20edbfb6108b9544c1bc80476a6a427a Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 16 Aug 2017 14:01:46 -0700 Subject: [PATCH] Skip unnecessary sleep during shutdown Skip sleep if timeout is zero Skip sleep if first pass umount succeed Bug: 64768138 Test: reboot Change-Id: I5ef731611320ade51974b414f7e47520ce36b287 --- init/reboot.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/init/reboot.cpp b/init/reboot.cpp index 24ccdfc6a..4d580f2ad 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -267,8 +267,6 @@ static void DumpUmountDebuggingInfo(bool dump_all) { static UmountStat UmountPartitions(std::chrono::milliseconds timeout) { Timer t; - UmountStat stat = UMOUNT_STAT_TIMEOUT; - int retry = 0; /* data partition needs all pending writes to be completed and all emulated partitions * umounted.If the current waiting is not good enough, give * up and leave it to e2fsck after reboot to fix it. @@ -280,25 +278,27 @@ static UmountStat UmountPartitions(std::chrono::milliseconds timeout) { return UMOUNT_STAT_ERROR; } if (block_devices.size() == 0) { - stat = UMOUNT_STAT_SUCCESS; - break; + return UMOUNT_STAT_SUCCESS; } - if ((timeout < t.duration()) && retry > 0) { // try umount at least once - stat = UMOUNT_STAT_TIMEOUT; - break; + bool unmount_done = true; + if (emulated_devices.size() > 0) { + unmount_done = std::all_of(emulated_devices.begin(), emulated_devices.end(), + [](auto& entry) { return entry.Umount(); }); + if (unmount_done) { + sync(); + } } - if (emulated_devices.size() > 0 && - std::all_of(emulated_devices.begin(), emulated_devices.end(), - [](auto& entry) { return entry.Umount(); })) { - sync(); + unmount_done = std::all_of(block_devices.begin(), block_devices.end(), + [](auto& entry) { return entry.Umount(); }) && + unmount_done; + if (unmount_done) { + return UMOUNT_STAT_SUCCESS; } - for (auto& entry : block_devices) { - entry.Umount(); + if ((timeout < t.duration())) { // try umount at least once + return UMOUNT_STAT_TIMEOUT; } - retry++; std::this_thread::sleep_for(100ms); } - return stat; } static void KillAllProcesses() { android::base::WriteStringToFile("i", "/proc/sysrq-trigger"); }