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

Commit 8bbe0936 authored by Tang Ding's avatar Tang Ding Committed by Makoto Onuki
Browse files

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
parent f34b066b
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -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,10 +1586,18 @@ public final class ActivityThread extends ClientTransactionHandler

        @Override
        public void dumpGfxInfo(ParcelFileDescriptor pfd, String[] args) {
            nDumpGraphicsInfo(pfd.getFileDescriptor());
            WindowManagerGlobal.getInstance().dumpGfxInfo(pfd.getFileDescriptor(), args);
            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
        public void dumpCacheInfo(ParcelFileDescriptor pfd, String[] args) {
@@ -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 {