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

Commit a874f393 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SF: handle long waiting Layer sync point"

parents d4bd9ff9 948c642a
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -819,7 +819,8 @@ void Layer::pushPendingState() {
            // to be applied as per normal (no synchronization).
            // to be applied as per normal (no synchronization).
            mCurrentState.barrierLayer_legacy = nullptr;
            mCurrentState.barrierLayer_legacy = nullptr;
        } else {
        } else {
            auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.barrierFrameNumber, this);
            auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.barrierFrameNumber, this,
                                                         barrierLayer);
            if (barrierLayer->addSyncPoint(syncPoint)) {
            if (barrierLayer->addSyncPoint(syncPoint)) {
                std::stringstream ss;
                std::stringstream ss;
                ss << "Adding sync point " << mCurrentState.barrierFrameNumber;
                ss << "Adding sync point " << mCurrentState.barrierFrameNumber;
@@ -844,7 +845,7 @@ void Layer::popPendingState(State* stateToCommit) {
    ATRACE_CALL();
    ATRACE_CALL();


    *stateToCommit = mPendingStates[0];
    *stateToCommit = mPendingStates[0];
    mPendingStates.removeAt(0);
    mPendingStates.pop_front();
    ATRACE_INT(mTransactionName.c_str(), mPendingStates.size());
    ATRACE_INT(mTransactionName.c_str(), mPendingStates.size());
}
}


@@ -883,6 +884,7 @@ bool Layer::applyPendingStates(State* stateToCommit) {
                mRemoteSyncPoints.pop_front();
                mRemoteSyncPoints.pop_front();
            } else {
            } else {
                ATRACE_NAME("!frameIsAvailable");
                ATRACE_NAME("!frameIsAvailable");
                mRemoteSyncPoints.front()->checkTimeoutAndLog();
                break;
                break;
            }
            }
        } else {
        } else {
+38 −5
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@
#include <utils/RefBase.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
#include <utils/Timers.h>


#include <chrono>
#include <cstdint>
#include <cstdint>
#include <list>
#include <list>
#include <optional>
#include <optional>
@@ -902,12 +903,13 @@ public:
protected:
protected:
    class SyncPoint {
    class SyncPoint {
    public:
    public:
        explicit SyncPoint(uint64_t frameNumber, wp<Layer> requestedSyncLayer)
        explicit SyncPoint(uint64_t frameNumber, wp<Layer> requestedSyncLayer,
                           wp<Layer> barrierLayer_legacy)
              : mFrameNumber(frameNumber),
              : mFrameNumber(frameNumber),
                mFrameIsAvailable(false),
                mFrameIsAvailable(false),
                mTransactionIsApplied(false),
                mTransactionIsApplied(false),
                mRequestedSyncLayer(requestedSyncLayer) {}
                mRequestedSyncLayer(requestedSyncLayer),

                mBarrierLayer_legacy(barrierLayer_legacy) {}
        uint64_t getFrameNumber() const { return mFrameNumber; }
        uint64_t getFrameNumber() const { return mFrameNumber; }


        bool frameIsAvailable() const { return mFrameIsAvailable; }
        bool frameIsAvailable() const { return mFrameIsAvailable; }
@@ -920,11 +922,42 @@ protected:


        sp<Layer> getRequestedSyncLayer() { return mRequestedSyncLayer.promote(); }
        sp<Layer> getRequestedSyncLayer() { return mRequestedSyncLayer.promote(); }


        sp<Layer> getBarrierLayer() const { return mBarrierLayer_legacy.promote(); }

        bool isTimeout() const {
            using namespace std::chrono_literals;
            static constexpr std::chrono::nanoseconds TIMEOUT_THRESHOLD = 1s;

            return std::chrono::steady_clock::now() - mCreateTimeStamp > TIMEOUT_THRESHOLD;
        }

        void checkTimeoutAndLog() {
            using namespace std::chrono_literals;
            static constexpr std::chrono::nanoseconds LOG_PERIOD = 1s;

            if (!frameIsAvailable() && isTimeout()) {
                const auto now = std::chrono::steady_clock::now();
                if (now - mLastLogTime > LOG_PERIOD) {
                    mLastLogTime = now;
                    sp<Layer> requestedSyncLayer = getRequestedSyncLayer();
                    sp<Layer> barrierLayer = getBarrierLayer();
                    ALOGW("[%s] sync point %" PRIu64 " wait timeout %lld for %s",
                          requestedSyncLayer ? requestedSyncLayer->getDebugName() : "Removed",
                          mFrameNumber, (now - mCreateTimeStamp).count(),
                          barrierLayer ? barrierLayer->getDebugName() : "Removed");
                }
            }
        }

    private:
    private:
        const uint64_t mFrameNumber;
        const uint64_t mFrameNumber;
        std::atomic<bool> mFrameIsAvailable;
        std::atomic<bool> mFrameIsAvailable;
        std::atomic<bool> mTransactionIsApplied;
        std::atomic<bool> mTransactionIsApplied;
        wp<Layer> mRequestedSyncLayer;
        wp<Layer> mRequestedSyncLayer;
        wp<Layer> mBarrierLayer_legacy;
        const std::chrono::time_point<std::chrono::steady_clock> mCreateTimeStamp =
                std::chrono::steady_clock::now();
        std::chrono::time_point<std::chrono::steady_clock> mLastLogTime;
    };
    };


    friend class impl::SurfaceInterceptor;
    friend class impl::SurfaceInterceptor;
@@ -1011,12 +1044,12 @@ protected:
    State mDrawingState;
    State mDrawingState;
    // Store a copy of the pending state so that the drawing thread can access the
    // Store a copy of the pending state so that the drawing thread can access the
    // states without a lock.
    // states without a lock.
    Vector<State> mPendingStatesSnapshot;
    std::deque<State> mPendingStatesSnapshot;


    // these are protected by an external lock (mStateLock)
    // these are protected by an external lock (mStateLock)
    State mCurrentState;
    State mCurrentState;
    std::atomic<uint32_t> mTransactionFlags{0};
    std::atomic<uint32_t> mTransactionFlags{0};
    Vector<State> mPendingStates;
    std::deque<State> mPendingStates;


    // Timestamp history for UIAutomation. Thread safe.
    // Timestamp history for UIAutomation. Thread safe.
    FrameTracker mFrameTracker;
    FrameTracker mFrameTracker;