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

Commit 11db9869 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Get window info debug data without holding the statelock

Avoids a deadlock with mStateLock when calling dumpsys
SurfaceFlinger. Deadlock happens because we make a blocking
call into the background thread holding the mStateLock. Background
thread may try to hold the mStateLock when destroying a layer handle
which can result in a deadlock.

Flag: EXEMPT bugfix
Test: presubmit, run dumpsys
Fixes: 347142017
Change-Id: Icda6d4ee0ead70a4d76a4f6fe766fdf40bae6d2c
parent e5b8ea30
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -6391,15 +6391,23 @@ status_t SurfaceFlinger::doDump(int fd, const DumpArgs& args, bool asProto) {
        return NO_ERROR;
    }

    // Traversal of drawing state must happen on the main thread.
    // Otherwise, SortedVector may have shared ownership during concurrent
    // traversals, which can result in use-after-frees.
    // Collect debug data from main thread
    std::string compositionLayers;
    mScheduler
            ->schedule([&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) {
                dumpVisibleFrontEnd(compositionLayers);
            })
            .get();
    // get window info listener data without the state lock
    auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo();
    compositionLayers.append("Window Infos:\n");
    StringAppendF(&compositionLayers, "  max send vsync id: %" PRId64 "\n",
                  ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId));
    StringAppendF(&compositionLayers, "  max send delay (ns): %" PRId64 " ns\n",
                  windowInfosDebug.maxSendDelayDuration);
    StringAppendF(&compositionLayers, "  unsent messages: %zu\n",
                  windowInfosDebug.pendingMessageCount);
    compositionLayers.append("\n");
    dumpAll(args, compositionLayers, result);
    write(fd, result.c_str(), result.size());
    return NO_ERROR;
@@ -6982,15 +6990,6 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio

    result.append(mTimeStats->miniDump());
    result.append("\n");

    result.append("Window Infos:\n");
    auto windowInfosDebug = mWindowInfosListenerInvoker->getDebugInfo();
    StringAppendF(&result, "  max send vsync id: %" PRId64 "\n",
                  ftl::to_underlying(windowInfosDebug.maxSendDelayVsyncId));
    StringAppendF(&result, "  max send delay (ns): %" PRId64 " ns\n",
                  windowInfosDebug.maxSendDelayDuration);
    StringAppendF(&result, "  unsent messages: %zu\n", windowInfosDebug.pendingMessageCount);
    result.append("\n");
}

mat4 SurfaceFlinger::calculateColorMatrix(float saturation) {