Loading services/surfaceflinger/Scheduler/PhaseOffsets.cpp +30 −22 Original line number Diff line number Diff line Loading @@ -60,6 +60,12 @@ namespace impl { PhaseOffsets::PhaseOffsets(const scheduler::RefreshRateConfigs& refreshRateConfigs) : PhaseOffsets(getRefreshRatesFromConfigs(refreshRateConfigs), refreshRateConfigs.getCurrentRefreshRate().getFps(), sysprop::vsync_event_phase_offset_ns(1000000), sysprop::vsync_sf_event_phase_offset_ns(1000000), getProperty("debug.sf.early_phase_offset_ns"), getProperty("debug.sf.early_gl_phase_offset_ns"), getProperty("debug.sf.early_app_phase_offset_ns"), getProperty("debug.sf.early_gl_app_phase_offset_ns"), // Below defines the threshold when an offset is considered to be negative, // i.e. targeting for the N+2 vsync instead of N+1. This means that: For offset // < threshold, SF wake up (vsync_duration - offset) before HW vsync. For Loading @@ -69,8 +75,18 @@ PhaseOffsets::PhaseOffsets(const scheduler::RefreshRateConfigs& refreshRateConfi .value_or(std::numeric_limits<nsecs_t>::max())) {} PhaseOffsets::PhaseOffsets(const std::vector<float>& refreshRates, float currentFps, nsecs_t thresholdForNextVsync) : mThresholdForNextVsync(thresholdForNextVsync), nsecs_t vsyncPhaseOffsetNs, nsecs_t sfVSyncPhaseOffsetNs, std::optional<nsecs_t> earlySfOffsetNs, std::optional<nsecs_t> earlyGlSfOffsetNs, std::optional<nsecs_t> earlyAppOffsetNs, std::optional<nsecs_t> earlyGlAppOffsetNs, nsecs_t thresholdForNextVsync) : mVSyncPhaseOffsetNs(vsyncPhaseOffsetNs), mSfVSyncPhaseOffsetNs(sfVSyncPhaseOffsetNs), mEarlySfOffsetNs(earlySfOffsetNs), mEarlyGlSfOffsetNs(earlyGlSfOffsetNs), mEarlyAppOffsetNs(earlyAppOffsetNs), mEarlyGlAppOffsetNs(earlyGlAppOffsetNs), mThresholdForNextVsync(thresholdForNextVsync), mOffsets(initializeOffsets(refreshRates)), mRefreshRateFps(currentFps) {} Loading Loading @@ -106,35 +122,27 @@ PhaseOffsets::Offsets PhaseOffsets::getPhaseOffsets(float fps, nsecs_t vsyncPeri } PhaseOffsets::Offsets PhaseOffsets::getDefaultOffsets(nsecs_t vsyncDuration) const { const int64_t vsyncPhaseOffsetNs = sysprop::vsync_event_phase_offset_ns(1000000); const int64_t sfVsyncPhaseOffsetNs = sysprop::vsync_sf_event_phase_offset_ns(1000000); const auto earlySfOffsetNs = getProperty("debug.sf.early_phase_offset_ns"); const auto earlyGlSfOffsetNs = getProperty("debug.sf.early_gl_phase_offset_ns"); const auto earlyAppOffsetNs = getProperty("debug.sf.early_app_phase_offset_ns"); const auto earlyGlAppOffsetNs = getProperty("debug.sf.early_gl_app_phase_offset_ns"); return { { earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) < mThresholdForNextVsync ? earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) : earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) - vsyncDuration, mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync ? mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) : mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) - vsyncDuration, earlyAppOffsetNs.value_or(vsyncPhaseOffsetNs), mEarlyAppOffsetNs.value_or(mVSyncPhaseOffsetNs), }, { earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) < mThresholdForNextVsync ? earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) : earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) - vsyncDuration, mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync ? mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) : mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) - vsyncDuration, earlyGlAppOffsetNs.value_or(vsyncPhaseOffsetNs), mEarlyGlAppOffsetNs.value_or(mVSyncPhaseOffsetNs), }, { sfVsyncPhaseOffsetNs < mThresholdForNextVsync ? sfVsyncPhaseOffsetNs : sfVsyncPhaseOffsetNs - vsyncDuration, mSfVSyncPhaseOffsetNs < mThresholdForNextVsync ? mSfVSyncPhaseOffsetNs : mSfVSyncPhaseOffsetNs - vsyncDuration, vsyncPhaseOffsetNs, mVSyncPhaseOffsetNs, }, }; } Loading services/surfaceflinger/Scheduler/PhaseOffsets.h +9 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,9 @@ public: protected: // Used for unit tests PhaseOffsets(const std::vector<float>& refreshRates, float currentFps, nsecs_t vsyncPhaseOffsetNs, nsecs_t sfVSyncPhaseOffsetNs, std::optional<nsecs_t> earlySfOffsetNs, std::optional<nsecs_t> earlyGlSfOffsetNs, std::optional<nsecs_t> earlyAppOffsetNs, std::optional<nsecs_t> earlyGlAppOffsetNs, nsecs_t thresholdForNextVsync); std::unordered_map<float, Offsets> initializeOffsets( const std::vector<float>& refreshRates) const; Loading @@ -76,6 +79,12 @@ protected: Offsets getHighFpsOffsets(nsecs_t vsyncPeriod) const; Offsets getPhaseOffsets(float fps, nsecs_t vsyncPeriod) const; const nsecs_t mVSyncPhaseOffsetNs; const nsecs_t mSfVSyncPhaseOffsetNs; const std::optional<nsecs_t> mEarlySfOffsetNs; const std::optional<nsecs_t> mEarlyGlSfOffsetNs; const std::optional<nsecs_t> mEarlyAppOffsetNs; const std::optional<nsecs_t> mEarlyGlAppOffsetNs; const nsecs_t mThresholdForNextVsync; const std::unordered_map<float, Offsets> mOffsets; Loading services/surfaceflinger/tests/unittests/PhaseOffsetsTest.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,9 @@ TEST_F(PhaseDurationTest, getOffsetsForRefreshRate_unknownRefreshRate) { class TestablePhaseOffsets : public impl::PhaseOffsets { public: TestablePhaseOffsets() : impl::PhaseOffsets({60.0f, 90.0f}, 60.0f, 10'000'000) {} TestablePhaseOffsets() : impl::PhaseOffsets({60.0f, 90.0f}, 60.0f, 1'000'000, 1'000'000, {}, {}, {}, {}, 10'000'000) {} }; class PhaseOffsetsTest : public testing::Test { Loading Loading
services/surfaceflinger/Scheduler/PhaseOffsets.cpp +30 −22 Original line number Diff line number Diff line Loading @@ -60,6 +60,12 @@ namespace impl { PhaseOffsets::PhaseOffsets(const scheduler::RefreshRateConfigs& refreshRateConfigs) : PhaseOffsets(getRefreshRatesFromConfigs(refreshRateConfigs), refreshRateConfigs.getCurrentRefreshRate().getFps(), sysprop::vsync_event_phase_offset_ns(1000000), sysprop::vsync_sf_event_phase_offset_ns(1000000), getProperty("debug.sf.early_phase_offset_ns"), getProperty("debug.sf.early_gl_phase_offset_ns"), getProperty("debug.sf.early_app_phase_offset_ns"), getProperty("debug.sf.early_gl_app_phase_offset_ns"), // Below defines the threshold when an offset is considered to be negative, // i.e. targeting for the N+2 vsync instead of N+1. This means that: For offset // < threshold, SF wake up (vsync_duration - offset) before HW vsync. For Loading @@ -69,8 +75,18 @@ PhaseOffsets::PhaseOffsets(const scheduler::RefreshRateConfigs& refreshRateConfi .value_or(std::numeric_limits<nsecs_t>::max())) {} PhaseOffsets::PhaseOffsets(const std::vector<float>& refreshRates, float currentFps, nsecs_t thresholdForNextVsync) : mThresholdForNextVsync(thresholdForNextVsync), nsecs_t vsyncPhaseOffsetNs, nsecs_t sfVSyncPhaseOffsetNs, std::optional<nsecs_t> earlySfOffsetNs, std::optional<nsecs_t> earlyGlSfOffsetNs, std::optional<nsecs_t> earlyAppOffsetNs, std::optional<nsecs_t> earlyGlAppOffsetNs, nsecs_t thresholdForNextVsync) : mVSyncPhaseOffsetNs(vsyncPhaseOffsetNs), mSfVSyncPhaseOffsetNs(sfVSyncPhaseOffsetNs), mEarlySfOffsetNs(earlySfOffsetNs), mEarlyGlSfOffsetNs(earlyGlSfOffsetNs), mEarlyAppOffsetNs(earlyAppOffsetNs), mEarlyGlAppOffsetNs(earlyGlAppOffsetNs), mThresholdForNextVsync(thresholdForNextVsync), mOffsets(initializeOffsets(refreshRates)), mRefreshRateFps(currentFps) {} Loading Loading @@ -106,35 +122,27 @@ PhaseOffsets::Offsets PhaseOffsets::getPhaseOffsets(float fps, nsecs_t vsyncPeri } PhaseOffsets::Offsets PhaseOffsets::getDefaultOffsets(nsecs_t vsyncDuration) const { const int64_t vsyncPhaseOffsetNs = sysprop::vsync_event_phase_offset_ns(1000000); const int64_t sfVsyncPhaseOffsetNs = sysprop::vsync_sf_event_phase_offset_ns(1000000); const auto earlySfOffsetNs = getProperty("debug.sf.early_phase_offset_ns"); const auto earlyGlSfOffsetNs = getProperty("debug.sf.early_gl_phase_offset_ns"); const auto earlyAppOffsetNs = getProperty("debug.sf.early_app_phase_offset_ns"); const auto earlyGlAppOffsetNs = getProperty("debug.sf.early_gl_app_phase_offset_ns"); return { { earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) < mThresholdForNextVsync ? earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) : earlySfOffsetNs.value_or(sfVsyncPhaseOffsetNs) - vsyncDuration, mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync ? mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) : mEarlySfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) - vsyncDuration, earlyAppOffsetNs.value_or(vsyncPhaseOffsetNs), mEarlyAppOffsetNs.value_or(mVSyncPhaseOffsetNs), }, { earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) < mThresholdForNextVsync ? earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) : earlyGlSfOffsetNs.value_or(sfVsyncPhaseOffsetNs) - vsyncDuration, mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) < mThresholdForNextVsync ? mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) : mEarlyGlSfOffsetNs.value_or(mSfVSyncPhaseOffsetNs) - vsyncDuration, earlyGlAppOffsetNs.value_or(vsyncPhaseOffsetNs), mEarlyGlAppOffsetNs.value_or(mVSyncPhaseOffsetNs), }, { sfVsyncPhaseOffsetNs < mThresholdForNextVsync ? sfVsyncPhaseOffsetNs : sfVsyncPhaseOffsetNs - vsyncDuration, mSfVSyncPhaseOffsetNs < mThresholdForNextVsync ? mSfVSyncPhaseOffsetNs : mSfVSyncPhaseOffsetNs - vsyncDuration, vsyncPhaseOffsetNs, mVSyncPhaseOffsetNs, }, }; } Loading
services/surfaceflinger/Scheduler/PhaseOffsets.h +9 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,9 @@ public: protected: // Used for unit tests PhaseOffsets(const std::vector<float>& refreshRates, float currentFps, nsecs_t vsyncPhaseOffsetNs, nsecs_t sfVSyncPhaseOffsetNs, std::optional<nsecs_t> earlySfOffsetNs, std::optional<nsecs_t> earlyGlSfOffsetNs, std::optional<nsecs_t> earlyAppOffsetNs, std::optional<nsecs_t> earlyGlAppOffsetNs, nsecs_t thresholdForNextVsync); std::unordered_map<float, Offsets> initializeOffsets( const std::vector<float>& refreshRates) const; Loading @@ -76,6 +79,12 @@ protected: Offsets getHighFpsOffsets(nsecs_t vsyncPeriod) const; Offsets getPhaseOffsets(float fps, nsecs_t vsyncPeriod) const; const nsecs_t mVSyncPhaseOffsetNs; const nsecs_t mSfVSyncPhaseOffsetNs; const std::optional<nsecs_t> mEarlySfOffsetNs; const std::optional<nsecs_t> mEarlyGlSfOffsetNs; const std::optional<nsecs_t> mEarlyAppOffsetNs; const std::optional<nsecs_t> mEarlyGlAppOffsetNs; const nsecs_t mThresholdForNextVsync; const std::unordered_map<float, Offsets> mOffsets; Loading
services/surfaceflinger/tests/unittests/PhaseOffsetsTest.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,9 @@ TEST_F(PhaseDurationTest, getOffsetsForRefreshRate_unknownRefreshRate) { class TestablePhaseOffsets : public impl::PhaseOffsets { public: TestablePhaseOffsets() : impl::PhaseOffsets({60.0f, 90.0f}, 60.0f, 10'000'000) {} TestablePhaseOffsets() : impl::PhaseOffsets({60.0f, 90.0f}, 60.0f, 1'000'000, 1'000'000, {}, {}, {}, {}, 10'000'000) {} }; class PhaseOffsetsTest : public testing::Test { Loading