Loading services/surfaceflinger/Scheduler/VSyncPredictor.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -255,21 +255,9 @@ void VSyncPredictor::clearTimestamps() { } } bool VSyncPredictor::needsMoreSamples(nsecs_t now) const { using namespace std::literals::chrono_literals; bool VSyncPredictor::needsMoreSamples() const { std::lock_guard<std::mutex> lk(mMutex); bool needsMoreSamples = true; if (mTimestamps.size() >= kMinimumSamplesForPrediction) { nsecs_t constexpr aLongTime = std::chrono::duration_cast<std::chrono::nanoseconds>(500ms).count(); if (!(mLastTimestampIndex < 0 || mTimestamps.empty())) { auto const lastTimestamp = mTimestamps[mLastTimestampIndex]; needsMoreSamples = !((lastTimestamp + aLongTime) > now); } } ATRACE_INT("VSP-moreSamples", needsMoreSamples); return needsMoreSamples; return mTimestamps.size() < kMinimumSamplesForPrediction; } void VSyncPredictor::resetModel() { Loading services/surfaceflinger/Scheduler/VSyncPredictor.h +2 −3 Original line number Diff line number Diff line Loading @@ -52,11 +52,10 @@ public: */ void setPeriod(nsecs_t period) final; /* Query if the model is in need of more samples to make a prediction at timePoint. * \param [in] timePoint The timePoint to inquire of. /* Query if the model is in need of more samples to make a prediction. * \return True, if model would benefit from more samples, False if not. */ bool needsMoreSamples(nsecs_t timePoint) const; bool needsMoreSamples() const final; std::tuple<nsecs_t /* slope */, nsecs_t /* intercept */> getVSyncPredictionModel() const; Loading services/surfaceflinger/Scheduler/VSyncReactor.cpp +19 −4 Original line number Diff line number Diff line Loading @@ -233,6 +233,7 @@ nsecs_t VSyncReactor::expectedPresentTime(nsecs_t now) { } void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { ATRACE_CALL(); mPeriodConfirmationInProgress = true; mPeriodTransitioningTo = newPeriod; mMoreSamplesNeeded = true; Loading @@ -240,8 +241,7 @@ void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { } void VSyncReactor::endPeriodTransition() { setIgnorePresentFencesInternal(false); mMoreSamplesNeeded = false; ATRACE_CALL(); mPeriodTransitioningTo.reset(); mPeriodConfirmationInProgress = false; mLastHwVsync.reset(); Loading @@ -254,6 +254,8 @@ void VSyncReactor::setPeriod(nsecs_t period) { if (!mSupportKernelIdleTimer && period == getPeriod()) { endPeriodTransition(); setIgnorePresentFencesInternal(false); mMoreSamplesNeeded = false; } else { startPeriodTransition(period); } Loading Loading @@ -303,6 +305,7 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwc std::lock_guard<std::mutex> lk(mMutex); if (periodConfirmed(timestamp, hwcVsyncPeriod)) { ATRACE_NAME("VSR: period confirmed"); if (mPeriodTransitioningTo) { mTracker->setPeriod(*mPeriodTransitioningTo); for (auto& entry : mCallbacks) { Loading @@ -310,17 +313,29 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwc } *periodFlushed = true; } if (mLastHwVsync) { mTracker->addVsyncTimestamp(*mLastHwVsync); } mTracker->addVsyncTimestamp(timestamp); endPeriodTransition(); mMoreSamplesNeeded = mTracker->needsMoreSamples(); } else if (mPeriodConfirmationInProgress) { ATRACE_NAME("VSR: still confirming period"); mLastHwVsync = timestamp; mMoreSamplesNeeded = true; *periodFlushed = false; } else { mMoreSamplesNeeded = false; ATRACE_NAME("VSR: adding sample"); *periodFlushed = false; mTracker->addVsyncTimestamp(timestamp); mMoreSamplesNeeded = mTracker->needsMoreSamples(); } mTracker->addVsyncTimestamp(timestamp); if (!mMoreSamplesNeeded) { setIgnorePresentFencesInternal(false); } return mMoreSamplesNeeded; } Loading services/surfaceflinger/Scheduler/VSyncTracker.h +2 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,8 @@ public: /* Inform the tracker that the samples it has are not accurate for prediction. */ virtual void resetModel() = 0; virtual bool needsMoreSamples() const = 0; virtual void dump(std::string& result) const = 0; protected: Loading services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public: void setPeriod(nsecs_t) final {} void resetModel() final {} bool needsMoreSamples() const final { return false; } void dump(std::string&) const final {} private: Loading Loading @@ -86,6 +87,7 @@ public: void setPeriod(nsecs_t) final {} void resetModel() final {} bool needsMoreSamples() const final { return false; } void dump(std::string&) const final {} private: Loading Loading
services/surfaceflinger/Scheduler/VSyncPredictor.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -255,21 +255,9 @@ void VSyncPredictor::clearTimestamps() { } } bool VSyncPredictor::needsMoreSamples(nsecs_t now) const { using namespace std::literals::chrono_literals; bool VSyncPredictor::needsMoreSamples() const { std::lock_guard<std::mutex> lk(mMutex); bool needsMoreSamples = true; if (mTimestamps.size() >= kMinimumSamplesForPrediction) { nsecs_t constexpr aLongTime = std::chrono::duration_cast<std::chrono::nanoseconds>(500ms).count(); if (!(mLastTimestampIndex < 0 || mTimestamps.empty())) { auto const lastTimestamp = mTimestamps[mLastTimestampIndex]; needsMoreSamples = !((lastTimestamp + aLongTime) > now); } } ATRACE_INT("VSP-moreSamples", needsMoreSamples); return needsMoreSamples; return mTimestamps.size() < kMinimumSamplesForPrediction; } void VSyncPredictor::resetModel() { Loading
services/surfaceflinger/Scheduler/VSyncPredictor.h +2 −3 Original line number Diff line number Diff line Loading @@ -52,11 +52,10 @@ public: */ void setPeriod(nsecs_t period) final; /* Query if the model is in need of more samples to make a prediction at timePoint. * \param [in] timePoint The timePoint to inquire of. /* Query if the model is in need of more samples to make a prediction. * \return True, if model would benefit from more samples, False if not. */ bool needsMoreSamples(nsecs_t timePoint) const; bool needsMoreSamples() const final; std::tuple<nsecs_t /* slope */, nsecs_t /* intercept */> getVSyncPredictionModel() const; Loading
services/surfaceflinger/Scheduler/VSyncReactor.cpp +19 −4 Original line number Diff line number Diff line Loading @@ -233,6 +233,7 @@ nsecs_t VSyncReactor::expectedPresentTime(nsecs_t now) { } void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { ATRACE_CALL(); mPeriodConfirmationInProgress = true; mPeriodTransitioningTo = newPeriod; mMoreSamplesNeeded = true; Loading @@ -240,8 +241,7 @@ void VSyncReactor::startPeriodTransition(nsecs_t newPeriod) { } void VSyncReactor::endPeriodTransition() { setIgnorePresentFencesInternal(false); mMoreSamplesNeeded = false; ATRACE_CALL(); mPeriodTransitioningTo.reset(); mPeriodConfirmationInProgress = false; mLastHwVsync.reset(); Loading @@ -254,6 +254,8 @@ void VSyncReactor::setPeriod(nsecs_t period) { if (!mSupportKernelIdleTimer && period == getPeriod()) { endPeriodTransition(); setIgnorePresentFencesInternal(false); mMoreSamplesNeeded = false; } else { startPeriodTransition(period); } Loading Loading @@ -303,6 +305,7 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwc std::lock_guard<std::mutex> lk(mMutex); if (periodConfirmed(timestamp, hwcVsyncPeriod)) { ATRACE_NAME("VSR: period confirmed"); if (mPeriodTransitioningTo) { mTracker->setPeriod(*mPeriodTransitioningTo); for (auto& entry : mCallbacks) { Loading @@ -310,17 +313,29 @@ bool VSyncReactor::addResyncSample(nsecs_t timestamp, std::optional<nsecs_t> hwc } *periodFlushed = true; } if (mLastHwVsync) { mTracker->addVsyncTimestamp(*mLastHwVsync); } mTracker->addVsyncTimestamp(timestamp); endPeriodTransition(); mMoreSamplesNeeded = mTracker->needsMoreSamples(); } else if (mPeriodConfirmationInProgress) { ATRACE_NAME("VSR: still confirming period"); mLastHwVsync = timestamp; mMoreSamplesNeeded = true; *periodFlushed = false; } else { mMoreSamplesNeeded = false; ATRACE_NAME("VSR: adding sample"); *periodFlushed = false; mTracker->addVsyncTimestamp(timestamp); mMoreSamplesNeeded = mTracker->needsMoreSamples(); } mTracker->addVsyncTimestamp(timestamp); if (!mMoreSamplesNeeded) { setIgnorePresentFencesInternal(false); } return mMoreSamplesNeeded; } Loading
services/surfaceflinger/Scheduler/VSyncTracker.h +2 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,8 @@ public: /* Inform the tracker that the samples it has are not accurate for prediction. */ virtual void resetModel() = 0; virtual bool needsMoreSamples() const = 0; virtual void dump(std::string& result) const = 0; protected: Loading
services/surfaceflinger/tests/unittests/VSyncDispatchRealtimeTest.cpp +2 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public: void setPeriod(nsecs_t) final {} void resetModel() final {} bool needsMoreSamples() const final { return false; } void dump(std::string&) const final {} private: Loading Loading @@ -86,6 +87,7 @@ public: void setPeriod(nsecs_t) final {} void resetModel() final {} bool needsMoreSamples() const final { return false; } void dump(std::string&) const final {} private: Loading