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

Commit b9a7dabf authored by Adithya Srinivasan's avatar Adithya Srinivasan
Browse files

Fix Transaction tracking for FrameTimeline

The current setup only supports one SurfaceFrame per DrawingState for
Transactions. This becomes problematic if more than one Transaction is
submitted for the same vsync, on the same layer. On top of this, the
Blast transactions can have a buffer that could result in a buffer drop.

This change adds the support to hold multiple SurfaceFrames in the
Layer's State. It also adds a bufferSurfaceFrame that's intended only
for Blast Transactions with a Buffer. All other Transactions are tracked
in the bufferlessSurfaceFrames.

Additionally, this change also adds a lastLatchTime. It is needed for
classifying BufferStuffing properly.

Bug: 176106798
Test: open any app from the launcher and at the same time check dumpsys
Change-Id: Id3b8369ca206f8b89be3041e5fc018f1f1be1d23
Merged-In: Id3b8369ca206f8b89be3041e5fc018f1f1be1d23
parent c00282a5
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -282,8 +282,7 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
            mConsumer->mergeSurfaceDamage(mQueueItems[0].item.mSurfaceDamage);
            mFlinger->mTimeStats->removeTimeRecord(layerId, mQueueItems[0].item.mFrameNumber);
            if (mQueueItems[0].surfaceFrame) {
                mQueueItems[0].surfaceFrame->setPresentState(PresentState::Dropped);
                mFlinger->mFrameTimeline->addSurfaceFrame(mQueueItems[0].surfaceFrame);
                addSurfaceFrameDroppedForBuffer(mQueueItems[0].surfaceFrame);
            }
            mQueueItems.erase(mQueueItems.begin());
            mQueuedFrames--;
@@ -298,8 +297,7 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
            Mutex::Autolock lock(mQueueItemLock);
            for (auto& [item, surfaceFrame] : mQueueItems) {
                if (surfaceFrame) {
                    surfaceFrame->setPresentState(PresentState::Dropped);
                    mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame);
                    addSurfaceFrameDroppedForBuffer(surfaceFrame);
                }
            }
            mQueueItems.clear();
@@ -329,8 +327,7 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
            mConsumer->mergeSurfaceDamage(mQueueItems[0].item.mSurfaceDamage);
            mFlinger->mTimeStats->removeTimeRecord(layerId, mQueueItems[0].item.mFrameNumber);
            if (mQueueItems[0].surfaceFrame) {
                mQueueItems[0].surfaceFrame->setPresentState(PresentState::Dropped);
                mFlinger->mFrameTimeline->addSurfaceFrame(mQueueItems[0].surfaceFrame);
                addSurfaceFrameDroppedForBuffer(mQueueItems[0].surfaceFrame);
            }
            mQueueItems.erase(mQueueItems.begin());
            mQueuedFrames--;
@@ -342,11 +339,9 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
                                               FrameTracer::FrameEvent::LATCH);

        if (mQueueItems[0].surfaceFrame) {
            mQueueItems[0].surfaceFrame->setAcquireFenceTime(
                    mQueueItems[0].item.mFenceTime->getSignalTime());
            mQueueItems[0].surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime);
            mFlinger->mFrameTimeline->addSurfaceFrame(mQueueItems[0].surfaceFrame);
            mLastLatchTime = latchTime;
            addSurfaceFramePresentedForBuffer(mQueueItems[0].surfaceFrame,
                                              mQueueItems[0].item.mFenceTime->getSignalTime(),
                                              latchTime);
        }
        mQueueItems.erase(mQueueItems.begin());
    }
@@ -444,10 +439,7 @@ void BufferQueueLayer::onFrameAvailable(const BufferItem& item) {
            }
        }

        auto surfaceFrame =
                mFlinger->mFrameTimeline->createSurfaceFrameForToken(mFrameTimelineInfo, mOwnerPid,
                                                                     mOwnerUid, mName, mName);
        surfaceFrame->setActualQueueTime(systemTime());
        auto surfaceFrame = createSurfaceFrameForBuffer(mFrameTimelineInfo, systemTime(), mName);

        mQueueItems.push_back({item, surfaceFrame});
        mQueuedFrames++;
@@ -483,10 +475,7 @@ void BufferQueueLayer::onFrameReplaced(const BufferItem& item) {
            return;
        }

        auto surfaceFrame =
                mFlinger->mFrameTimeline->createSurfaceFrameForToken(mFrameTimelineInfo, mOwnerPid,
                                                                     mOwnerUid, mName, mName);
        surfaceFrame->setActualQueueTime(systemTime());
        auto surfaceFrame = createSurfaceFrameForBuffer(mFrameTimelineInfo, systemTime(), mName);
        mQueueItems[mQueueItems.size() - 1].item = item;
        mQueueItems[mQueueItems.size() - 1].surfaceFrame = std::move(surfaceFrame);

+0 −5
Original line number Diff line number Diff line
@@ -149,11 +149,6 @@ private:
    // a buffer to correlate the buffer with the vsync id. Can only be accessed
    // with the SF state lock held.
    FrameTimelineInfo mFrameTimelineInfo;

    // Keeps track of the time SF latched the last buffer from this layer.
    // Used in buffer stuffing analysis in FrameTimeline.
    // TODO(b/176106798): Find a way to do this for BLASTBufferQueue as well.
    nsecs_t mLastLatchTime = 0;
};

} // namespace android
+24 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include <limits>

#include <FrameTimeline/FrameTimeline.h>
#include <compositionengine/LayerFECompositionState.h>
#include <gui/BufferQueue.h>
#include <private/gui/SyncFeatures.h>
@@ -38,6 +39,7 @@

namespace android {

using PresentState = frametimeline::SurfaceFrame::PresentState;
// clang-format off
const std::array<float, 16> BufferStateLayer::IDENTITY_MATRIX{
        1, 0, 0, 0,
@@ -335,7 +337,8 @@ bool BufferStateLayer::addFrameEvent(const sp<Fence>& acquireFence, nsecs_t post
bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence>& acquireFence,
                                 nsecs_t postTime, nsecs_t desiredPresentTime, bool isAutoTimestamp,
                                 const client_cache_t& clientCacheId, uint64_t frameNumber,
                                 std::optional<nsecs_t> /* dequeueTime */) {
                                 std::optional<nsecs_t> /* dequeueTime */,
                                 const FrameTimelineInfo& info) {
    ATRACE_CALL();

    if (mCurrentState.buffer) {
@@ -345,6 +348,10 @@ bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence
            // before swapping to drawing state, then the first buffer will be
            // dropped and we should decrement the pending buffer count.
            decrementPendingBufferCount();
            if (mCurrentState.bufferSurfaceFrameTX != nullptr) {
                addSurfaceFrameDroppedForBuffer(mCurrentState.bufferSurfaceFrameTX);
                mCurrentState.bufferSurfaceFrameTX.reset();
            }
        }
    }

@@ -365,6 +372,11 @@ bool BufferStateLayer::setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence
                                             LayerHistory::LayerUpdateType::Buffer);

    addFrameEvent(acquireFence, postTime, isAutoTimestamp ? 0 : desiredPresentTime);

    if (info.vsyncId != FrameTimelineInfo::INVALID_VSYNC_ID) {
        setFrameTimelineVsyncForBufferTransaction(info, postTime);
    }

    return true;
}

@@ -620,6 +632,17 @@ status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nse
                                          std::make_shared<FenceTime>(mDrawingState.acquireFence));
    mFlinger->mTimeStats->setLatchTime(layerId, mDrawingState.frameNumber, latchTime);

    auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX;
    if (bufferSurfaceFrame != nullptr &&
        bufferSurfaceFrame->getPresentState() != PresentState::Presented) {
        // Update only if the bufferSurfaceFrame wasn't already presented. A Presented
        // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we
        // are processing the next state.
        addSurfaceFramePresentedForBuffer(bufferSurfaceFrame,
                                          mDrawingState.acquireFence->getSignalTime(), latchTime);
        bufferSurfaceFrame.reset();
    }

    mCurrentStateModified = false;

    return NO_ERROR;
+3 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public:
    bool setBuffer(const sp<GraphicBuffer>& buffer, const sp<Fence>& acquireFence, nsecs_t postTime,
                   nsecs_t desiredPresentTime, bool isAutoTimestamp,
                   const client_cache_t& clientCacheId, uint64_t frameNumber,
                   std::optional<nsecs_t> dequeueTime) override;
                   std::optional<nsecs_t> dequeueTime, const FrameTimelineInfo& info) override;
    bool setAcquireFence(const sp<Fence>& fence) override;
    bool setDataspace(ui::Dataspace dataspace) override;
    bool setHdrMetadata(const HdrMetadata& hdrMetadata) override;
@@ -124,6 +124,8 @@ protected:

private:
    friend class SlotGenerationTest;
    friend class TransactionSurfaceFrameTest;

    inline void tracePendingBufferCount();

    bool updateFrameEventHistory(const sp<Fence>& acquireFence, nsecs_t postedTime,
+4 −0
Original line number Diff line number Diff line
@@ -312,6 +312,10 @@ void SurfaceFrame::setAcquireFenceTime(nsecs_t acquireFenceTime) {

void SurfaceFrame::setPresentState(PresentState presentState, nsecs_t lastLatchTime) {
    std::scoped_lock lock(mMutex);
    LOG_ALWAYS_FATAL_IF(mPresentState != PresentState::Unknown,
                        "setPresentState called on a SurfaceFrame from Layer - %s, that has a "
                        "PresentState - %s set already.",
                        mDebugName.c_str(), toString(mPresentState).c_str());
    mPresentState = presentState;
    mLastLatchTime = lastLatchTime;
}
Loading