diff options
author | Kevin DuBois <kevindubois@google.com> | 2020-06-26 17:00:15 -0700 |
---|---|---|
committer | Kevin DuBois <kevindubois@google.com> | 2020-06-29 11:59:01 -0700 |
commit | 241d0eed73c96288dd499697c15a1e3eabaad955 (patch) | |
tree | 61e44998e4da897b84b2d2485a6d901f0baa5c25 | |
parent | b9adcf3bf476d7b2b529a7c21a402590480d4fdd (diff) | |
download | native-241d0eed73c96288dd499697c15a1e3eabaad955.tar.gz |
SF: update VSP timebase on error condition
When an vsync timestamp is recorded that is anonmolous to the currently
recorded timestamp ringbuffer, update the timebase for synthetic
calculations.
Test: 2 new unit tests
Test: visual spot checking interactions on pixel4 device
Test: uibench a/b anti-regression
Test: dogfood with patch based one recent rvc build.
Fixes: 159882858
Change-Id: Ie201cd593a54586d9b1f488c6d2ca44178d75cf1
-rw-r--r-- | services/surfaceflinger/Scheduler/VSyncPredictor.cpp | 17 | ||||
-rw-r--r-- | services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp | 32 |
2 files changed, 47 insertions, 2 deletions
diff --git a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp index a3cb7725a7..ab5773dc09 100644 --- a/services/surfaceflinger/Scheduler/VSyncPredictor.cpp +++ b/services/surfaceflinger/Scheduler/VSyncPredictor.cpp @@ -77,7 +77,14 @@ bool VSyncPredictor::addVsyncTimestamp(nsecs_t timestamp) { std::lock_guard<std::mutex> lk(mMutex); if (!validate(timestamp)) { - ALOGV("timestamp was too far off the last known timestamp"); + // VSR could elect to ignore the incongruent timestamp or resetModel(). If ts is ignored, + // don't insert this ts into mTimestamps ringbuffer. + if (!mTimestamps.empty()) { + mKnownTimestamp = + std::max(timestamp, *std::max_element(mTimestamps.begin(), mTimestamps.end())); + } else { + mKnownTimestamp = timestamp; + } return false; } @@ -236,7 +243,13 @@ void VSyncPredictor::setPeriod(nsecs_t period) { void VSyncPredictor::clearTimestamps() { if (!mTimestamps.empty()) { - mKnownTimestamp = *std::max_element(mTimestamps.begin(), mTimestamps.end()); + auto const maxRb = *std::max_element(mTimestamps.begin(), mTimestamps.end()); + if (mKnownTimestamp) { + mKnownTimestamp = std::max(*mKnownTimestamp, maxRb); + } else { + mKnownTimestamp = maxRb; + } + mTimestamps.clear(); mLastTimestampIndex = 0; } diff --git a/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp b/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp index bf2a889c89..fc39235a93 100644 --- a/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncPredictorTest.cpp @@ -124,6 +124,38 @@ TEST_F(VSyncPredictorTest, uponNotifiedOfInaccuracyUsesSynthetic) { EXPECT_THAT(tracker.nextAnticipatedVSyncTimeFrom(mNow), Eq(mNow + changedPeriod)); } +// b/159882858 +TEST_F(VSyncPredictorTest, updatesTimebaseForSyntheticAfterIdleTime) { + for (auto i = 0u; i < kMinimumSamplesForPrediction; i++) { + EXPECT_TRUE(tracker.addVsyncTimestamp(mNow += mPeriod)); + } + + EXPECT_THAT(tracker.nextAnticipatedVSyncTimeFrom(mNow), Eq(mNow + mPeriod)); + + auto const halfPeriod = mPeriod >> 2; + nsecs_t relativelyLongGapWithDrift = mPeriod * 100 + halfPeriod; + + EXPECT_FALSE(tracker.addVsyncTimestamp(mNow += relativelyLongGapWithDrift)); + + tracker.resetModel(); + EXPECT_THAT(tracker.nextAnticipatedVSyncTimeFrom(mNow), Eq(mNow + mPeriod)); +} + +TEST_F(VSyncPredictorTest, uponBadVsyncWillSwitchToSyntheticWhileRecalibrating) { + auto const slightlyMorePeriod = mPeriod + 10; + for (auto i = 0u; i < kMinimumSamplesForPrediction; i++) { + EXPECT_TRUE(tracker.addVsyncTimestamp(mNow += slightlyMorePeriod)); + } + + EXPECT_THAT(tracker.nextAnticipatedVSyncTimeFrom(mNow), Eq(mNow + slightlyMorePeriod)); + + auto const halfPeriod = mPeriod >> 2; + EXPECT_FALSE(tracker.addVsyncTimestamp(mNow += halfPeriod)); + + tracker.resetModel(); + EXPECT_THAT(tracker.nextAnticipatedVSyncTimeFrom(mNow), Eq(mNow + mPeriod)); +} + TEST_F(VSyncPredictorTest, adaptsToFenceTimelines_60hzHighVariance) { // these are precomputed simulated 16.6s vsyncs with uniform distribution +/- 1.6ms error std::vector<nsecs_t> const simulatedVsyncs{ |