blob: 0ad42364a2e78279f357268f03644c005f79a5ac [file] [log] [blame]
Kevin DuBois1678e2c2019-08-22 12:26:24 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Dominik Laskowski62eff352021-12-06 09:59:41 -080021#undef LOG_TAG
22#define LOG_TAG "VSyncPredictor"
23
Kevin DuBois1678e2c2019-08-22 12:26:24 -070024#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Dominik Laskowski62eff352021-12-06 09:59:41 -080025
26#include <algorithm>
27#include <chrono>
28#include <sstream>
29
Kevin DuBois1678e2c2019-08-22 12:26:24 -070030#include <android-base/logging.h>
Ady Abraham5e7371c2020-03-24 14:47:24 -070031#include <android-base/stringprintf.h>
Kevin DuBois1678e2c2019-08-22 12:26:24 -070032#include <cutils/compiler.h>
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -080033#include <cutils/properties.h>
Kevin DuBois1678e2c2019-08-22 12:26:24 -070034#include <utils/Log.h>
35#include <utils/Trace.h>
Kevin DuBois1678e2c2019-08-22 12:26:24 -070036
Dominik Laskowskid82e0f02022-10-26 15:23:04 -040037#include "RefreshRateSelector.h"
Dominik Laskowski62eff352021-12-06 09:59:41 -080038#include "VSyncPredictor.h"
Ady Abraham0bb6a472020-10-12 10:22:13 -070039
Kevin DuBois1678e2c2019-08-22 12:26:24 -070040namespace android::scheduler {
Dominik Laskowski62eff352021-12-06 09:59:41 -080041
Ady Abraham5e7371c2020-03-24 14:47:24 -070042using base::StringAppendF;
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -080043
Kevin DuBois1678e2c2019-08-22 12:26:24 -070044static auto constexpr kMaxPercent = 100u;
45
46VSyncPredictor::~VSyncPredictor() = default;
47
48VSyncPredictor::VSyncPredictor(nsecs_t idealPeriod, size_t historySize,
49 size_t minimumSamplesForPrediction, uint32_t outlierTolerancePercent)
Kevin DuBoisc57f2c32019-12-20 16:32:29 -080050 : mTraceOn(property_get_bool("debug.sf.vsp_trace", true)),
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -080051 kHistorySize(historySize),
Kevin DuBois1678e2c2019-08-22 12:26:24 -070052 kMinimumSamplesForPrediction(minimumSamplesForPrediction),
53 kOutlierTolerancePercent(std::min(outlierTolerancePercent, kMaxPercent)),
54 mIdealPeriod(idealPeriod) {
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -080055 resetModel();
Kevin DuBois1678e2c2019-08-22 12:26:24 -070056}
57
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -080058inline void VSyncPredictor::traceInt64If(const char* name, int64_t value) const {
59 if (CC_UNLIKELY(mTraceOn)) {
60 ATRACE_INT64(name, value);
61 }
62}
63
Ady Abraham9c53ee72020-07-22 21:16:18 -070064inline size_t VSyncPredictor::next(size_t i) const {
Ady Abraham92fa2f42020-02-11 15:33:56 -080065 return (i + 1) % mTimestamps.size();
Kevin DuBois1678e2c2019-08-22 12:26:24 -070066}
67
68bool VSyncPredictor::validate(nsecs_t timestamp) const {
Ady Abraham92fa2f42020-02-11 15:33:56 -080069 if (mLastTimestampIndex < 0 || mTimestamps.empty()) {
Kevin DuBois1678e2c2019-08-22 12:26:24 -070070 return true;
71 }
72
Ady Abraham92fa2f42020-02-11 15:33:56 -080073 auto const aValidTimestamp = mTimestamps[mLastTimestampIndex];
Kevin DuBois1678e2c2019-08-22 12:26:24 -070074 auto const percent = (timestamp - aValidTimestamp) % mIdealPeriod * kMaxPercent / mIdealPeriod;
Ady Abraham99ca3362021-06-17 12:28:46 -070075 if (percent >= kOutlierTolerancePercent &&
76 percent <= (kMaxPercent - kOutlierTolerancePercent)) {
77 return false;
78 }
79
80 const auto iter = std::min_element(mTimestamps.begin(), mTimestamps.end(),
81 [timestamp](nsecs_t a, nsecs_t b) {
82 return std::abs(timestamp - a) < std::abs(timestamp - b);
83 });
84 const auto distancePercent = std::abs(*iter - timestamp) * kMaxPercent / mIdealPeriod;
85 if (distancePercent < kOutlierTolerancePercent) {
86 // duplicate timestamp
87 return false;
88 }
89 return true;
Kevin DuBois1678e2c2019-08-22 12:26:24 -070090}
91
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080092nsecs_t VSyncPredictor::currentPeriod() const {
Ady Abraham9c53ee72020-07-22 21:16:18 -070093 std::lock_guard lock(mMutex);
Ady Abraham0bb6a472020-10-12 10:22:13 -070094 return mRateMap.find(mIdealPeriod)->second.slope;
Kevin DuBois2fd3cea2019-11-14 08:52:45 -080095}
96
Kevin DuBois02d5ed92020-01-27 11:05:46 -080097bool VSyncPredictor::addVsyncTimestamp(nsecs_t timestamp) {
Ady Abraham9c53ee72020-07-22 21:16:18 -070098 std::lock_guard lock(mMutex);
Kevin DuBois1678e2c2019-08-22 12:26:24 -070099
100 if (!validate(timestamp)) {
Kevin DuBois241d0ee2020-06-26 17:00:15 -0700101 // VSR could elect to ignore the incongruent timestamp or resetModel(). If ts is ignored,
Ady Abraham43a3e692020-11-13 12:43:39 -0800102 // don't insert this ts into mTimestamps ringbuffer. If we are still
103 // in the learning phase we should just clear all timestamps and start
104 // over.
105 if (mTimestamps.size() < kMinimumSamplesForPrediction) {
Ady Abraham4c56b642021-06-08 15:03:33 -0700106 // Add the timestamp to mTimestamps before clearing it so we could
107 // update mKnownTimestamp based on the new timestamp.
108 mTimestamps.push_back(timestamp);
Ady Abraham43a3e692020-11-13 12:43:39 -0800109 clearTimestamps();
110 } else if (!mTimestamps.empty()) {
Kevin DuBois241d0ee2020-06-26 17:00:15 -0700111 mKnownTimestamp =
112 std::max(timestamp, *std::max_element(mTimestamps.begin(), mTimestamps.end()));
113 } else {
114 mKnownTimestamp = timestamp;
115 }
Kevin DuBois02d5ed92020-01-27 11:05:46 -0800116 return false;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700117 }
118
Ady Abraham92fa2f42020-02-11 15:33:56 -0800119 if (mTimestamps.size() != kHistorySize) {
120 mTimestamps.push_back(timestamp);
121 mLastTimestampIndex = next(mLastTimestampIndex);
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700122 } else {
Ady Abraham92fa2f42020-02-11 15:33:56 -0800123 mLastTimestampIndex = next(mLastTimestampIndex);
124 mTimestamps[mLastTimestampIndex] = timestamp;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700125 }
126
Dominik Laskowski62eff352021-12-06 09:59:41 -0800127 const size_t numSamples = mTimestamps.size();
128 if (numSamples < kMinimumSamplesForPrediction) {
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700129 mRateMap[mIdealPeriod] = {mIdealPeriod, 0};
Kevin DuBois02d5ed92020-01-27 11:05:46 -0800130 return true;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700131 }
132
133 // This is a 'simple linear regression' calculation of Y over X, with Y being the
134 // vsync timestamps, and X being the ordinal of vsync count.
135 // The calculated slope is the vsync period.
136 // Formula for reference:
137 // Sigma_i: means sum over all timestamps.
138 // mean(variable): statistical mean of variable.
139 // X: snapped ordinal of the timestamp
140 // Y: vsync timestamp
141 //
142 // Sigma_i( (X_i - mean(X)) * (Y_i - mean(Y) )
143 // slope = -------------------------------------------
144 // Sigma_i ( X_i - mean(X) ) ^ 2
145 //
146 // intercept = mean(Y) - slope * mean(X)
147 //
Dominik Laskowski62eff352021-12-06 09:59:41 -0800148 std::vector<nsecs_t> vsyncTS(numSamples);
149 std::vector<nsecs_t> ordinals(numSamples);
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700150
Dominik Laskowski62eff352021-12-06 09:59:41 -0800151 // Normalizing to the oldest timestamp cuts down on error in calculating the intercept.
152 const auto oldestTS = *std::min_element(mTimestamps.begin(), mTimestamps.end());
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700153 auto it = mRateMap.find(mIdealPeriod);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700154 auto const currentPeriod = it->second.slope;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700155
Dominik Laskowski62eff352021-12-06 09:59:41 -0800156 // The mean of the ordinals must be precise for the intercept calculation, so scale them up for
157 // fixed-point arithmetic.
158 constexpr int64_t kScalingFactor = 1000;
159
160 nsecs_t meanTS = 0;
161 nsecs_t meanOrdinal = 0;
162
163 for (size_t i = 0; i < numSamples; i++) {
Ady Abraham92fa2f42020-02-11 15:33:56 -0800164 traceInt64If("VSP-ts", mTimestamps[i]);
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800165
Dominik Laskowski62eff352021-12-06 09:59:41 -0800166 const auto timestamp = mTimestamps[i] - oldestTS;
167 vsyncTS[i] = timestamp;
168 meanTS += timestamp;
169
Rachel Lee934017e2022-08-10 15:34:14 -0700170 const auto ordinal = currentPeriod == 0
171 ? 0
172 : (vsyncTS[i] + currentPeriod / 2) / currentPeriod * kScalingFactor;
Dominik Laskowski62eff352021-12-06 09:59:41 -0800173 ordinals[i] = ordinal;
174 meanOrdinal += ordinal;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700175 }
176
Dominik Laskowski62eff352021-12-06 09:59:41 -0800177 meanTS /= numSamples;
178 meanOrdinal /= numSamples;
179
180 for (size_t i = 0; i < numSamples; i++) {
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700181 vsyncTS[i] -= meanTS;
182 ordinals[i] -= meanOrdinal;
183 }
184
Dominik Laskowski62eff352021-12-06 09:59:41 -0800185 nsecs_t top = 0;
186 nsecs_t bottom = 0;
187 for (size_t i = 0; i < numSamples; i++) {
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700188 top += vsyncTS[i] * ordinals[i];
189 bottom += ordinals[i] * ordinals[i];
190 }
191
192 if (CC_UNLIKELY(bottom == 0)) {
193 it->second = {mIdealPeriod, 0};
Ady Abraham92fa2f42020-02-11 15:33:56 -0800194 clearTimestamps();
Kevin DuBois02d5ed92020-01-27 11:05:46 -0800195 return false;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700196 }
197
Kevin DuBois0049f8b2020-03-11 10:30:11 -0700198 nsecs_t const anticipatedPeriod = top * kScalingFactor / bottom;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700199 nsecs_t const intercept = meanTS - (anticipatedPeriod * meanOrdinal / kScalingFactor);
200
Ady Abraham92fa2f42020-02-11 15:33:56 -0800201 auto const percent = std::abs(anticipatedPeriod - mIdealPeriod) * kMaxPercent / mIdealPeriod;
202 if (percent >= kOutlierTolerancePercent) {
203 it->second = {mIdealPeriod, 0};
204 clearTimestamps();
205 return false;
206 }
207
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800208 traceInt64If("VSP-period", anticipatedPeriod);
209 traceInt64If("VSP-intercept", intercept);
210
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700211 it->second = {anticipatedPeriod, intercept};
212
213 ALOGV("model update ts: %" PRId64 " slope: %" PRId64 " intercept: %" PRId64, timestamp,
214 anticipatedPeriod, intercept);
Kevin DuBois02d5ed92020-01-27 11:05:46 -0800215 return true;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700216}
217
Ady Abraham0bb6a472020-10-12 10:22:13 -0700218nsecs_t VSyncPredictor::nextAnticipatedVSyncTimeFromLocked(nsecs_t timePoint) const {
219 auto const [slope, intercept] = getVSyncPredictionModelLocked();
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700220
Ady Abraham92fa2f42020-02-11 15:33:56 -0800221 if (mTimestamps.empty()) {
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800222 traceInt64If("VSP-mode", 1);
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700223 auto const knownTimestamp = mKnownTimestamp ? *mKnownTimestamp : timePoint;
224 auto const numPeriodsOut = ((timePoint - knownTimestamp) / mIdealPeriod) + 1;
225 return knownTimestamp + numPeriodsOut * mIdealPeriod;
226 }
227
Ady Abraham92fa2f42020-02-11 15:33:56 -0800228 auto const oldest = *std::min_element(mTimestamps.begin(), mTimestamps.end());
Kevin DuBois127a2d92019-12-04 13:52:52 -0800229
230 // See b/145667109, the ordinal calculation must take into account the intercept.
231 auto const zeroPoint = oldest + intercept;
232 auto const ordinalRequest = (timePoint - zeroPoint + slope) / slope;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700233 auto const prediction = (ordinalRequest * slope) + intercept + oldest;
234
Kevin DuBoisecb1f0d2019-12-12 10:47:41 -0800235 traceInt64If("VSP-mode", 0);
236 traceInt64If("VSP-timePoint", timePoint);
237 traceInt64If("VSP-prediction", prediction);
238
Kevin DuBois127a2d92019-12-04 13:52:52 -0800239 auto const printer = [&, slope = slope, intercept = intercept] {
240 std::stringstream str;
241 str << "prediction made from: " << timePoint << "prediction: " << prediction << " (+"
242 << prediction - timePoint << ") slope: " << slope << " intercept: " << intercept
243 << "oldestTS: " << oldest << " ordinal: " << ordinalRequest;
244 return str.str();
245 };
246
247 ALOGV("%s", printer().c_str());
248 LOG_ALWAYS_FATAL_IF(prediction < timePoint, "VSyncPredictor: model miscalculation: %s",
249 printer().c_str());
250
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700251 return prediction;
252}
253
Ady Abraham0bb6a472020-10-12 10:22:13 -0700254nsecs_t VSyncPredictor::nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const {
Ady Abraham9c53ee72020-07-22 21:16:18 -0700255 std::lock_guard lock(mMutex);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700256 return nextAnticipatedVSyncTimeFromLocked(timePoint);
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700257}
258
Ady Abraham0bb6a472020-10-12 10:22:13 -0700259/*
Ady Abraham5cc2e262021-03-25 13:09:17 -0700260 * Returns whether a given vsync timestamp is in phase with a frame rate.
Ady Abrahamcc315492022-02-17 17:06:39 -0800261 * If the frame rate is not a divisor of the refresh rate, it is always considered in phase.
Ady Abraham5cc2e262021-03-25 13:09:17 -0700262 * For example, if the vsync timestamps are (16.6,33.3,50.0,66.6):
263 * isVSyncInPhase(16.6, 30) = true
264 * isVSyncInPhase(33.3, 30) = false
265 * isVSyncInPhase(50.0, 30) = true
Ady Abraham0bb6a472020-10-12 10:22:13 -0700266 */
Ady Abraham5cc2e262021-03-25 13:09:17 -0700267bool VSyncPredictor::isVSyncInPhase(nsecs_t timePoint, Fps frameRate) const {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700268 struct VsyncError {
269 nsecs_t vsyncTimestamp;
270 float error;
271
272 bool operator<(const VsyncError& other) const { return error < other.error; }
273 };
274
Ady Abraham5cc2e262021-03-25 13:09:17 -0700275 std::lock_guard lock(mMutex);
Ady Abrahamcc315492022-02-17 17:06:39 -0800276 const auto divisor =
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400277 RefreshRateSelector::getFrameRateDivisor(Fps::fromPeriodNsecs(mIdealPeriod), frameRate);
Ady Abrahamcc315492022-02-17 17:06:39 -0800278 if (divisor <= 1 || timePoint == 0) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700279 return true;
280 }
281
282 const nsecs_t period = mRateMap[mIdealPeriod].slope;
283 const nsecs_t justBeforeTimePoint = timePoint - period / 2;
Ady Abrahamcc315492022-02-17 17:06:39 -0800284 const nsecs_t dividedPeriod = mIdealPeriod / divisor;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700285
Ady Abrahamcc315492022-02-17 17:06:39 -0800286 // If this is the first time we have asked about this divisor with the
Ady Abraham0bb6a472020-10-12 10:22:13 -0700287 // current vsync period, it is considered in phase and we store the closest
288 // vsync timestamp
Ady Abrahamcc315492022-02-17 17:06:39 -0800289 const auto knownTimestampIter = mRateDivisorKnownTimestampMap.find(dividedPeriod);
290 if (knownTimestampIter == mRateDivisorKnownTimestampMap.end()) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700291 const auto vsync = nextAnticipatedVSyncTimeFromLocked(justBeforeTimePoint);
Ady Abrahamcc315492022-02-17 17:06:39 -0800292 mRateDivisorKnownTimestampMap[dividedPeriod] = vsync;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700293 return true;
294 }
295
Ady Abrahamcc315492022-02-17 17:06:39 -0800296 // Find the next N vsync timestamp where N is the divisor.
Ady Abraham0bb6a472020-10-12 10:22:13 -0700297 // One of these vsyncs will be in phase. We return the one which is
298 // the most aligned with the last known in phase vsync
Ady Abrahamcc315492022-02-17 17:06:39 -0800299 std::vector<VsyncError> vsyncs(static_cast<size_t>(divisor));
Ady Abraham0bb6a472020-10-12 10:22:13 -0700300 const nsecs_t knownVsync = knownTimestampIter->second;
301 nsecs_t point = justBeforeTimePoint;
Ady Abrahamcc315492022-02-17 17:06:39 -0800302 for (size_t i = 0; i < divisor; i++) {
Ady Abraham0bb6a472020-10-12 10:22:13 -0700303 const nsecs_t vsync = nextAnticipatedVSyncTimeFromLocked(point);
Ady Abrahamcc315492022-02-17 17:06:39 -0800304 const auto numPeriods = static_cast<float>(vsync - knownVsync) / (period * divisor);
Ady Abraham0bb6a472020-10-12 10:22:13 -0700305 const auto error = std::abs(std::round(numPeriods) - numPeriods);
306 vsyncs[i] = {vsync, error};
307 point = vsync + 1;
308 }
309
310 const auto minVsyncError = std::min_element(vsyncs.begin(), vsyncs.end());
Ady Abrahamcc315492022-02-17 17:06:39 -0800311 mRateDivisorKnownTimestampMap[dividedPeriod] = minVsyncError->vsyncTimestamp;
Ady Abraham0bb6a472020-10-12 10:22:13 -0700312 return std::abs(minVsyncError->vsyncTimestamp - timePoint) < period / 2;
313}
314
315VSyncPredictor::Model VSyncPredictor::getVSyncPredictionModel() const {
316 std::lock_guard lock(mMutex);
317 const auto model = VSyncPredictor::getVSyncPredictionModelLocked();
318 return {model.slope, model.intercept};
319}
320
321VSyncPredictor::Model VSyncPredictor::getVSyncPredictionModelLocked() const {
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700322 return mRateMap.find(mIdealPeriod)->second;
323}
324
325void VSyncPredictor::setPeriod(nsecs_t period) {
326 ATRACE_CALL();
327
Ady Abraham9c53ee72020-07-22 21:16:18 -0700328 std::lock_guard lock(mMutex);
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700329 static constexpr size_t kSizeLimit = 30;
330 if (CC_UNLIKELY(mRateMap.size() == kSizeLimit)) {
331 mRateMap.erase(mRateMap.begin());
332 }
333
334 mIdealPeriod = period;
335 if (mRateMap.find(period) == mRateMap.end()) {
336 mRateMap[mIdealPeriod] = {period, 0};
337 }
338
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -0800339 clearTimestamps();
340}
341
342void VSyncPredictor::clearTimestamps() {
Ady Abraham92fa2f42020-02-11 15:33:56 -0800343 if (!mTimestamps.empty()) {
Kevin DuBois241d0ee2020-06-26 17:00:15 -0700344 auto const maxRb = *std::max_element(mTimestamps.begin(), mTimestamps.end());
345 if (mKnownTimestamp) {
346 mKnownTimestamp = std::max(*mKnownTimestamp, maxRb);
347 } else {
348 mKnownTimestamp = maxRb;
349 }
350
Ady Abraham92fa2f42020-02-11 15:33:56 -0800351 mTimestamps.clear();
352 mLastTimestampIndex = 0;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700353 }
354}
355
Kevin DuBoisb818bfa2020-07-10 14:29:36 -0700356bool VSyncPredictor::needsMoreSamples() const {
Ady Abraham9c53ee72020-07-22 21:16:18 -0700357 std::lock_guard lock(mMutex);
Kevin DuBoisb818bfa2020-07-10 14:29:36 -0700358 return mTimestamps.size() < kMinimumSamplesForPrediction;
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700359}
360
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -0800361void VSyncPredictor::resetModel() {
Ady Abraham9c53ee72020-07-22 21:16:18 -0700362 std::lock_guard lock(mMutex);
Kevin DuBoisc3e9e8e2020-01-07 09:06:52 -0800363 mRateMap[mIdealPeriod] = {mIdealPeriod, 0};
364 clearTimestamps();
365}
366
Ady Abraham5e7371c2020-03-24 14:47:24 -0700367void VSyncPredictor::dump(std::string& result) const {
Ady Abraham9c53ee72020-07-22 21:16:18 -0700368 std::lock_guard lock(mMutex);
Ady Abraham5e7371c2020-03-24 14:47:24 -0700369 StringAppendF(&result, "\tmIdealPeriod=%.2f\n", mIdealPeriod / 1e6f);
370 StringAppendF(&result, "\tRefresh Rate Map:\n");
371 for (const auto& [idealPeriod, periodInterceptTuple] : mRateMap) {
372 StringAppendF(&result,
373 "\t\tFor ideal period %.2fms: period = %.2fms, intercept = %" PRId64 "\n",
Ady Abraham0bb6a472020-10-12 10:22:13 -0700374 idealPeriod / 1e6f, periodInterceptTuple.slope / 1e6f,
375 periodInterceptTuple.intercept);
Ady Abraham5e7371c2020-03-24 14:47:24 -0700376 }
377}
378
Kevin DuBois1678e2c2019-08-22 12:26:24 -0700379} // namespace android::scheduler
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800380
Marin Shalamanovbed7fd32020-12-21 20:02:20 +0100381// TODO(b/129481165): remove the #pragma below and fix conversion issues
Dominik Laskowski62eff352021-12-06 09:59:41 -0800382#pragma clang diagnostic pop // ignored "-Wextra"