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 Original line Diff line number Diff line
@@ -895,6 +895,12 @@ void Output::writeCompositionState(const compositionengine::CompositionRefreshAr
                                         })) {
                                         })) {
        editState().earliestPresentTime = frameTargetPtrOpt->get()->earliestPresentTime();
        editState().earliestPresentTime = frameTargetPtrOpt->get()->earliestPresentTime();
        editState().expectedPresentTime = frameTargetPtrOpt->get()->expectedPresentTime().ns();
        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().frameInterval = refreshArgs.frameInterval;
    editState().powerCallback = refreshArgs.powerCallback;
    editState().powerCallback = refreshArgs.powerCallback;
+5 −1
Original line number Original line Diff line number Diff line
@@ -203,12 +203,16 @@ void Scheduler::run() {


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

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


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


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

private:
private:
    friend class TestableScheduler;
    friend class TestableScheduler;


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


    FrameRateOverrideMappings mFrameRateOverrideMappings;
    FrameRateOverrideMappings mFrameRateOverrideMappings;
    SmallAreaDetectionAllowMappings mSmallAreaDetectionAllowMappings;
    SmallAreaDetectionAllowMappings mSmallAreaDetectionAllowMappings;

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


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


    TimePoint expectedPresentTime() const { return mExpectedPresentTime; }
    TimePoint expectedPresentTime() const { return mExpectedPresentTime; }


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

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


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


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


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


    // The `expectedVsyncTime`, which was predicted when this frame was scheduled, is normally in
    // 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
    // the future relative to `frameBeginTime`, but may not be for delayed frames. Adjust
Loading