From fb5eac94450bd1ae45d300dcfef0f8e9e4c63f86 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 11 Mar 2021 12:51:25 -0800 Subject: [PATCH] Add support for a hw_timeout_multiplier system property. In order to test the platform in emulators that are orders of magnitude slower than real hardware we need to be able to avoid hitting timeouts that prevent it from coming up properly. For this purpose introduce a system property, ro.hw_timeout_multiplier, which may be set to an integer value that acts as a multiplier for various timeouts on the system. Bug: 178231152 Change-Id: I6d7710beed0c4c5b1720e74e7abe3a586778c678 Merged-In: I6d7710beed0c4c5b1720e74e7abe3a586778c678 --- debuggerd/crash_dump.cpp | 6 +++--- debuggerd/tombstoned/intercept_manager.cpp | 4 ++-- debuggerd/tombstoned/tombstoned.cpp | 4 ++-- llkd/libllkd.cpp | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index c8612bfeb..a52f719ee 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp @@ -153,14 +153,14 @@ static bool activity_manager_notify(pid_t pid, int signal, const std::string& am } struct timeval tv = { - .tv_sec = 1 * android::base::TimeoutMultiplier(), + .tv_sec = 1 * android::base::HwTimeoutMultiplier(), .tv_usec = 0, }; if (setsockopt(amfd.get(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) { PLOG(ERROR) << "failed to set send timeout on activity manager socket"; return false; } - tv.tv_sec = 3 * android::base::TimeoutMultiplier(); // 3 seconds on handshake read + tv.tv_sec = 3 * android::base::HwTimeoutMultiplier(); // 3 seconds on handshake read if (setsockopt(amfd.get(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { PLOG(ERROR) << "failed to set receive timeout on activity manager socket"; return false; @@ -448,7 +448,7 @@ int main(int argc, char** argv) { // // Note: processes with many threads and minidebug-info can take a bit to // unwind, do not make this too small. b/62828735 - alarm(30 * android::base::TimeoutMultiplier()); + alarm(30 * android::base::HwTimeoutMultiplier()); // Get the process name (aka cmdline). std::string process_name = get_process_name(g_target_thread); diff --git a/debuggerd/tombstoned/intercept_manager.cpp b/debuggerd/tombstoned/intercept_manager.cpp index 4d4646a33..613e6f57d 100644 --- a/debuggerd/tombstoned/intercept_manager.cpp +++ b/debuggerd/tombstoned/intercept_manager.cpp @@ -163,7 +163,7 @@ static void intercept_request_cb(evutil_socket_t sockfd, short ev, void* arg) { event_assign(intercept->intercept_event, intercept_manager->base, sockfd, EV_READ | EV_TIMEOUT, intercept_close_cb, arg); - struct timeval timeout = {.tv_sec = 10 * android::base::TimeoutMultiplier(), .tv_usec = 0}; + struct timeval timeout = {.tv_sec = 10 * android::base::HwTimeoutMultiplier(), .tv_usec = 0}; event_add(intercept->intercept_event, &timeout); } @@ -179,7 +179,7 @@ static void intercept_accept_cb(evconnlistener* listener, evutil_socket_t sockfd intercept->intercept_manager = static_cast(arg); intercept->sockfd.reset(sockfd); - struct timeval timeout = {1 * android::base::TimeoutMultiplier(), 0}; + struct timeval timeout = {1 * android::base::HwTimeoutMultiplier(), 0}; event_base* base = evconnlistener_get_base(listener); event* intercept_event = event_new(base, sockfd, EV_TIMEOUT | EV_READ, intercept_request_cb, intercept); diff --git a/debuggerd/tombstoned/tombstoned.cpp b/debuggerd/tombstoned/tombstoned.cpp index bc2d33d8f..0b87b7a08 100644 --- a/debuggerd/tombstoned/tombstoned.cpp +++ b/debuggerd/tombstoned/tombstoned.cpp @@ -320,7 +320,7 @@ static void perform_request(std::unique_ptr crash) { } // TODO: Make this configurable by the interceptor? - struct timeval timeout = {10 * android::base::TimeoutMultiplier(), 0}; + struct timeval timeout = {10 * android::base::HwTimeoutMultiplier(), 0}; event_base* base = event_get_base(crash->crash_event); @@ -340,7 +340,7 @@ static void crash_accept_cb(evconnlistener* listener, evutil_socket_t sockfd, so // TODO: Make sure that only java crashes come in on the java socket // and only native crashes on the native socket. - struct timeval timeout = {1 * android::base::TimeoutMultiplier(), 0}; + struct timeval timeout = {1 * android::base::HwTimeoutMultiplier(), 0}; event* crash_event = event_new(base, sockfd, EV_TIMEOUT | EV_READ, crash_request_cb, crash); crash->crash_socket_fd.reset(sockfd); crash->crash_event = crash_event; diff --git a/llkd/libllkd.cpp b/llkd/libllkd.cpp index 9f3e21829..27a8baf3b 100644 --- a/llkd/libllkd.cpp +++ b/llkd/libllkd.cpp @@ -962,7 +962,8 @@ milliseconds llkCheck(bool checkRunning) { // // This alarm is effectively the live lock detection of llkd, as // we understandably can not monitor ourselves otherwise. - ::alarm(duration_cast(llkTimeoutMs * 2 * android::base::TimeoutMultiplier()).count()); + ::alarm(duration_cast(llkTimeoutMs * 2 * android::base::HwTimeoutMultiplier()) + .count()); // kernel jiffy precision fastest acquisition static timespec last;