From 8bbe093657a6c329aceda5d4e3c79e2fe0f8dc20 Mon Sep 17 00:00:00 2001 From: Tang Ding Date: Thu, 8 Apr 2021 05:47:56 +0000 Subject: [PATCH] Avoiding system server dump stuck by pipe buffer full. Problem: RenderThread blocked during dumping gfx info. Root Cause: Though dumpGfxInfo() uses an async binder invocation ,When the caller is system server, this invocation is not IPC that means it is not asynchronous, it will keep waiting if dumpGfxinfo output size larger than 16*4KB as reader thread start by transferpipe.go cannot be executed because write pipe waiting. Ensure this invocation is asynchronous to prevent writer waiting if buffer cannot be consumed. Solution: Send write action to handler thread so reader thread can be started to consume the data in buffer. Fix: 185806813 Test: dumpsys gfxinfo Change-Id: I37b1c1881a857970019eddfb762ae620e0353744 --- core/java/android/app/ActivityThread.java | 31 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 98fee9cf90cfc..652b3b2b86b66 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -39,7 +39,6 @@ import android.annotation.Nullable; import android.app.assist.AssistContent; import android.app.assist.AssistStructure; import android.app.backup.BackupAgent; -import android.app.backup.BackupManager; import android.app.servertransaction.ActivityLifecycleItem; import android.app.servertransaction.ActivityLifecycleItem.LifecycleState; import android.app.servertransaction.ActivityRelaunchItem; @@ -1587,9 +1586,17 @@ public final class ActivityThread extends ClientTransactionHandler @Override public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) { - nDumpGraphicsInfo(pfd.getFileDescriptor()); - WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args); - IoUtils.closeQuietly(pfd); + DumpComponentInfo data = new DumpComponentInfo(); + try { + data.fd = pfd.dup(); + data.token = null; + data.args = args; + sendMessage(H.DUMP_GFXINFO, data, 0, 0, true /*async*/); + } catch (IOException e) { + Slog.w(TAG, "dumpGfxInfo failed", e); + } finally { + IoUtils.closeQuietly(pfd); + } } @Override @@ -1961,6 +1968,7 @@ public final class ActivityThread extends ClientTransactionHandler public static final int ATTACH_STARTUP_AGENTS = 162; public static final int UPDATE_UI_TRANSLATION_STATE = 163; public static final int SET_CONTENT_CAPTURE_OPTIONS_CALLBACK = 164; + public static final int DUMP_GFXINFO = 165; public static final int INSTRUMENT_WITHOUT_RESTART = 170; public static final int FINISH_INSTRUMENTATION_WITHOUT_RESTART = 171; @@ -2010,6 +2018,7 @@ public final class ActivityThread extends ClientTransactionHandler case UPDATE_UI_TRANSLATION_STATE: return "UPDATE_UI_TRANSLATION_STATE"; case SET_CONTENT_CAPTURE_OPTIONS_CALLBACK: return "SET_CONTENT_CAPTURE_OPTIONS_CALLBACK"; + case DUMP_GFXINFO: return "DUMP GFXINFO"; case INSTRUMENT_WITHOUT_RESTART: return "INSTRUMENT_WITHOUT_RESTART"; case FINISH_INSTRUMENTATION_WITHOUT_RESTART: return "FINISH_INSTRUMENTATION_WITHOUT_RESTART"; @@ -2083,6 +2092,9 @@ public final class ActivityThread extends ClientTransactionHandler case DUMP_SERVICE: handleDumpService((DumpComponentInfo)msg.obj); break; + case DUMP_GFXINFO: + handleDumpGfxInfo((DumpComponentInfo) msg.obj); + break; case LOW_MEMORY: Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "lowMemory"); handleLowMemory(); @@ -4483,6 +4495,17 @@ public final class ActivityThread extends ClientTransactionHandler } } + private void handleDumpGfxInfo(DumpComponentInfo info) { + try { + nDumpGraphicsInfo(info.fd.getFileDescriptor()); + WindowManagerGlobal.getInstance().dumpGfxInfo(info.fd.getFileDescriptor(), info.args); + } catch (Exception e) { + Log.w(TAG, "Caught exception from dumpGfxInfo()", e); + } finally { + IoUtils.closeQuietly(info.fd); + } + } + private void handleDumpService(DumpComponentInfo info) { final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); try {