Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d36115ef authored by Billy Lau's avatar Billy Lau
Browse files

init: Reworked how we wait for COLDBOOT_DONE

Bug: 31800756

Instead of strictly timing out after 1s waiting for COLDBOOT_DONE,
we wait for a considerably longer period of time, which would also
allow slower non-production heavily instrumented debug builds to
boot up.

Upon successful wait, we measure the time taken and record the
value into a system property: ro.cold_boot.duration.

If timeout is still reached, we log an error message and abandon
boot process, rebooting into recovery mode instead.

Change-Id: Ic1df80546d8721b0e8c998ff294d5c5102de4e98
parent b6552f37
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -163,14 +163,28 @@ static int wait_for_coldboot_done_action(const std::vector<std::string>& args) {
    Timer t;

    LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE "...";

    // History:
    // Any longer than 1s is an unreasonable length of time to delay booting.
    // If you're hitting this timeout, check that you didn't make your
    // sepolicy regular expressions too expensive (http://b/19899875).
    if (wait_for_file(COLDBOOT_DONE, 1s)) {
        LOG(ERROR) << "Timed out waiting for " COLDBOOT_DONE;
    // Update:
    // It is bad to allow device to randomly fail to boot. So, we should
    // instead log an error and abandon boot process if we have waited
    // for a *considerably* long period of time. For attempts that do not
    // exceed the treshold, we keep a record of how long it took for further
    // optimization work.
    // Also, a longer wait period before timeout gives slower builds like
    // heavily instrumented debug builds (e.g. KASan) a chance to fully boot.
    if (wait_for_file(COLDBOOT_DONE, 45s) < 0) {
        LOG(ERROR) << "Timed out waiting for " COLDBOOT_DONE "; rebooting into recovery mode...";
        android_reboot(ANDROID_RB_RESTART2, 0, "recovery");
        while (true) { pause(); }   // in case reboot is denied
    }

    LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE " took " << t.duration() << "s.";
    double duration = t.duration();
    property_set("ro.bootstats.cold_boot_duration", StringPrintf("%fs", duration).c_str());
    LOG(VERBOSE) << "Waiting for " COLDBOOT_DONE " took " << duration << "s.";
    return 0;
}