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

Commit 708ebfbc authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: add a backdoor to introduce a janky frame to HWC

Bug: 346503493
Test: adb shell service call SurfaceFlinger 1046 i32 3Test: adb root && adb shell service call SurfaceFlinger 1046 i32 3
Flag: EXEMPT bugfix
Change-Id: Ic4a837ef06aca40a24db9c1121e19e3e1a1e0d80
parent 7a3c56f8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -895,6 +895,12 @@ void Output::writeCompositionState(const compositionengine::CompositionRefreshAr
                                         })) {
        editState().earliestPresentTime = frameTargetPtrOpt->get()->earliestPresentTime();
        editState().expectedPresentTime = frameTargetPtrOpt->get()->expectedPresentTime().ns();
        const auto debugPresentDelay = frameTargetPtrOpt->get()->debugPresentDelay();
        if (debugPresentDelay) {
            SFTRACE_FORMAT_INSTANT("DEBUG delaying presentation by %.2fms",
                                   debugPresentDelay->ns() / 1e6f);
            editState().expectedPresentTime += debugPresentDelay->ns();
        }
    }
    editState().frameInterval = refreshArgs.frameInterval;
    editState().powerCallback = refreshArgs.powerCallback;
+5 −1
Original line number Diff line number Diff line
@@ -203,12 +203,16 @@ void Scheduler::run() {

void Scheduler::onFrameSignal(ICompositor& compositor, VsyncId vsyncId,
                              TimePoint expectedVsyncTime) {
    const auto debugPresentDelay = mDebugPresentDelay.load();
    mDebugPresentDelay.store(std::nullopt);

    const FrameTargeter::BeginFrameArgs beginFrameArgs =
            {.frameBeginTime = SchedulerClock::now(),
             .vsyncId = vsyncId,
             .expectedVsyncTime = expectedVsyncTime,
             .sfWorkDuration = mVsyncModulator->getVsyncConfig().sfWorkDuration,
             .hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration};
             .hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration,
             .debugPresentTimeDelay = debugPresentDelay};

    ftl::NonNull<const Display*> pacesetterPtr = pacesetterPtrLocked();
    pacesetterPtr->targeterPtr->beginFrame(beginFrameArgs, *pacesetterPtr->schedulePtr);
+4 −0
Original line number Diff line number Diff line
@@ -337,6 +337,8 @@ public:
    // recovery should begin.
    void addBufferStuffedUids(BufferStuffingMap bufferStuffedUids);

    void setDebugPresentDelay(TimePoint delay) { mDebugPresentDelay = delay; }

private:
    friend class TestableScheduler;

@@ -602,6 +604,8 @@ private:

    FrameRateOverrideMappings mFrameRateOverrideMappings;
    SmallAreaDetectionAllowMappings mSmallAreaDetectionAllowMappings;

    std::atomic<std::optional<TimePoint>> mDebugPresentDelay;
};

} // namespace scheduler
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public:

    TimePoint expectedPresentTime() const { return mExpectedPresentTime; }

    std::optional<TimePoint> debugPresentDelay() const { return mDebugPresentTimeDelay; }

    std::optional<TimePoint> earliestPresentTime() const { return mEarliestPresentTime; }

    // Equivalent to `expectedSignaledPresentFence` unless running N VSYNCs ahead.
@@ -84,6 +86,7 @@ protected:
    TimePoint mFrameBeginTime;
    TimePoint mExpectedPresentTime;
    std::optional<TimePoint> mEarliestPresentTime;
    std::optional<TimePoint> mDebugPresentTimeDelay;

    TracedOrdinal<bool> mFramePending;
    TracedOrdinal<bool> mFrameMissed;
@@ -135,6 +138,7 @@ public:
        TimePoint expectedVsyncTime;
        Duration sfWorkDuration;
        Duration hwcMinWorkDuration;
        std::optional<TimePoint> debugPresentTimeDelay; // used to introduce jank for testing
    };

    void beginFrame(const BeginFrameArgs&, const IVsyncSource&);
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ void FrameTargeter::beginFrame(const BeginFrameArgs& args, const IVsyncSource& v
                               IsFencePendingFuncPtr isFencePendingFuncPtr) {
    mVsyncId = args.vsyncId;
    mFrameBeginTime = args.frameBeginTime;
    mDebugPresentTimeDelay = args.debugPresentTimeDelay;

    // The `expectedVsyncTime`, which was predicted when this frame was scheduled, is normally in
    // the future relative to `frameBeginTime`, but may not be for delayed frames. Adjust
Loading