From 0b5b2f22f22b140e2b23da17c96de7120ed4f221 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Tue, 11 Feb 2025 12:09:15 -0800 Subject: Double suspend timeouts for user builds This trades fewer crashes on user builds against worse diagnostic information. We expect many of these crashes to turn into ANRs. We may want to raise these timeouts even further. We do not want to eliminate them, since presumable not all cases will eventually be detected as ANRs. Test: Treehuger Bug: 330444460 Bug: 384107236 (and many other bugs) Change-Id: I13998c30d00e54b1555b1ae63a13707483ac7354 --- runtime/thread_list.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index b4f79ee5a8..6cc526a59f 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -28,6 +28,7 @@ #include #include +#include "android-base/properties.h" #include "android-base/stringprintf.h" #include "art_field-inl.h" #include "base/aborting.h" @@ -765,13 +766,21 @@ static bool WaitOnceForSuspendBarrier(AtomicInteger* barrier, std::optional ThreadList::WaitForSuspendBarrier(AtomicInteger* barrier, pid_t t, int attempt_of_4) { - // Only fail after kIter timeouts, to make us robust against app freezing. #if ART_USE_FUTEXES const uint64_t start_time = NanoTime(); #endif uint64_t timeout_ns = attempt_of_4 == 0 ? thread_suspend_timeout_ns_ : thread_suspend_timeout_ns_ / 4; - + static bool is_user_build = (android::base::GetProperty("ro.build.type", "") == "user"); + // Significantly increase timeouts in user builds, since they result in crashes. + // Many of these are likely to turn into ANRs, which are less informative for the developer, but + // friendlier to the user. We do not completely suppress timeouts, so that we avoid invisible + // problems for cases not covered by ANR detection, e.g. a problem in a clean-up daemon. + if (is_user_build) { + static constexpr int USER_MULTIPLIER = 2; // Start out small, perhaps increase later if we + // still have an issue? + timeout_ns *= USER_MULTIPLIER; + } uint64_t avg_wait_multiplier = 1; uint64_t wait_multiplier = 1; if (attempt_of_4 != 1) { @@ -819,6 +828,7 @@ std::optional ThreadList::WaitForSuspendBarrier(AtomicInteger* barr LOG(WARNING) << "Thread suspension nearly timed out due to Tracing stop (debugger attached?)"; timeout_ns = kTracingWaitNSecs; } + // Only fail after kSuspendBarrierIters timeouts, to make us robust against app freezing. while (i < kSuspendBarrierIters) { if (WaitOnceForSuspendBarrier(barrier, cur_val, timeout_ns + dump_adjustment_ns)) { ++i; -- cgit v1.2.3-59-g8ed1b