From 7ad419a46c1afbf6207333b6ef2ff10e0f2e4254 Mon Sep 17 00:00:00 2001 From: Olivier Gaillard Date: Fri, 1 Apr 2022 13:12:47 +0100 Subject: [PATCH] Add thread to check for lock contention. Using the foreground thread will block the foreground thread when there is lock contention. Some of the lock checks are guarding code which is writing to disk for instance. Test: manual Change-Id: I431c5c34984c7f58cfe4f4127071521811edefb8 --- services/core/java/com/android/server/Watchdog.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/Watchdog.java b/services/core/java/com/android/server/Watchdog.java index 8b48d0f39aaa0..a900f6fe4921d 100644 --- a/services/core/java/com/android/server/Watchdog.java +++ b/services/core/java/com/android/server/Watchdog.java @@ -390,11 +390,16 @@ public class Watchdog { // potentially hold longer running operations with no guarantees about the timeliness // of operations there. // - // The shared foreground thread is the main checker. It is where we - // will also dispatch monitor checks and do other work. - mMonitorChecker = new HandlerChecker(FgThread.getHandler(), - "foreground thread"); + // Use a custom thread to check monitors to avoid lock contention from impacted other + // threads. + ServiceThread t = new ServiceThread("watchdog.monitor", + android.os.Process.THREAD_PRIORITY_DEFAULT, true /*allowIo*/); + t.start(); + mMonitorChecker = new HandlerChecker(new Handler(t.getLooper()), "monitor thread"); mHandlerCheckers.add(withDefaultTimeout(mMonitorChecker)); + + mHandlerCheckers.add(withDefaultTimeout( + new HandlerChecker(FgThread.getHandler(), "foreground thread"))); // Add checker for main thread. We only do a quick check since there // can be UI running on the thread. mHandlerCheckers.add(withDefaultTimeout(