blob: 30fba3c59ed75975df4c1a7bf3379a888cb127c9 [file] [log] [blame]
Ana Krulec98b5b242018-08-10 15:03:23 -07001/*
2 * Copyright 2018 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
Ana Krulec7ab56032018-11-02 20:51:06 +010017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Ana Krulec98b5b242018-08-10 15:03:23 -070019#include "Scheduler.h"
20
Ana Krulec434c22d2018-11-28 13:48:36 +010021#include <algorithm>
Ana Krulec98b5b242018-08-10 15:03:23 -070022#include <cinttypes>
23#include <cstdint>
24#include <memory>
Ana Krulec7ab56032018-11-02 20:51:06 +010025#include <numeric>
Ana Krulec98b5b242018-08-10 15:03:23 -070026
Ana Krulece588e312018-09-18 12:32:24 -070027#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
28#include <android/hardware/configstore/1.1/ISurfaceFlingerConfigs.h>
29#include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h>
30#include <configstore/Utils.h>
Ana Krulecfb772822018-11-30 10:44:07 +010031#include <cutils/properties.h>
Ana Krulece588e312018-09-18 12:32:24 -070032#include <ui/DisplayStatInfo.h>
Ana Krulec3084c052018-11-21 20:27:17 +010033#include <utils/Timers.h>
Ana Krulec7ab56032018-11-02 20:51:06 +010034#include <utils/Trace.h>
Ana Krulec98b5b242018-08-10 15:03:23 -070035
36#include "DispSync.h"
37#include "DispSyncSource.h"
Ana Krulece588e312018-09-18 12:32:24 -070038#include "EventControlThread.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070039#include "EventThread.h"
Ana Krulecfb772822018-11-30 10:44:07 +010040#include "IdleTimer.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070041#include "InjectVSyncSource.h"
Ana Krulec434c22d2018-11-28 13:48:36 +010042#include "SchedulerUtils.h"
Sundong Ahnd5e08f62018-12-12 20:27:28 +090043#include "SurfaceFlingerProperties.h"
Ana Krulec98b5b242018-08-10 15:03:23 -070044
45namespace android {
46
Ana Krulece588e312018-09-18 12:32:24 -070047using namespace android::hardware::configstore;
48using namespace android::hardware::configstore::V1_0;
Sundong Ahnd5e08f62018-12-12 20:27:28 +090049using namespace android::sysprop;
Ana Krulece588e312018-09-18 12:32:24 -070050
Ana Krulec0c8cd522018-08-31 12:27:28 -070051#define RETURN_VALUE_IF_INVALID(value) \
52 if (handle == nullptr || mConnections.count(handle->id) == 0) return value
53#define RETURN_IF_INVALID() \
54 if (handle == nullptr || mConnections.count(handle->id) == 0) return
55
Ana Krulec98b5b242018-08-10 15:03:23 -070056std::atomic<int64_t> Scheduler::sNextId = 0;
57
Ana Krulece588e312018-09-18 12:32:24 -070058Scheduler::Scheduler(impl::EventControlThread::SetVSyncEnabledFunction function)
Sundong Ahnd5e08f62018-12-12 20:27:28 +090059 : mHasSyncFramework(running_without_sync_framework(true)),
60 mDispSyncPresentTimeOffset(present_time_offset_from_vsync_ns(0)),
Ana Krulece588e312018-09-18 12:32:24 -070061 mPrimaryHWVsyncEnabled(false),
62 mHWVsyncAvailable(false) {
63 // Note: We create a local temporary with the real DispSync implementation
64 // type temporarily so we can initialize it with the configured values,
65 // before storing it for more generic use using the interface type.
66 auto primaryDispSync = std::make_unique<impl::DispSync>("SchedulerDispSync");
67 primaryDispSync->init(mHasSyncFramework, mDispSyncPresentTimeOffset);
68 mPrimaryDispSync = std::move(primaryDispSync);
69 mEventControlThread = std::make_unique<impl::EventControlThread>(function);
Ana Krulecfb772822018-11-30 10:44:07 +010070
71 char value[PROPERTY_VALUE_MAX];
Ana Kruleca5bdd9d2019-01-29 19:00:58 -080072 property_get("debug.sf.set_idle_timer_ms", value, "0");
Ana Krulecfb772822018-11-30 10:44:07 +010073 mSetIdleTimerMs = atoi(value);
74
75 if (mSetIdleTimerMs > 0) {
76 mIdleTimer =
77 std::make_unique<scheduler::IdleTimer>(std::chrono::milliseconds(mSetIdleTimerMs),
Ady Abrahama1a49af2019-02-07 14:36:55 -080078 [this] { resetTimerCallback(); },
Ana Krulecfb772822018-11-30 10:44:07 +010079 [this] { expiredTimerCallback(); });
80 mIdleTimer->start();
81 }
Ana Krulece588e312018-09-18 12:32:24 -070082}
83
Lloyd Pique1f9f1a42019-01-31 13:04:00 -080084Scheduler::~Scheduler() {
85 // Ensure the IdleTimer thread is joined before we start destroying state.
86 mIdleTimer.reset();
87}
Ana Krulec0c8cd522018-08-31 12:27:28 -070088
Ana Krulec98b5b242018-08-10 15:03:23 -070089sp<Scheduler::ConnectionHandle> Scheduler::createConnection(
Dominik Laskowskibd52c842019-01-28 18:11:23 -080090 const char* connectionName, int64_t phaseOffsetNs, ResyncCallback resyncCallback,
Ana Krulec98b5b242018-08-10 15:03:23 -070091 impl::EventThread::InterceptVSyncsCallback interceptCallback) {
92 const int64_t id = sNextId++;
93 ALOGV("Creating a connection handle with ID: %" PRId64 "\n", id);
94
Ana Krulec98b5b242018-08-10 15:03:23 -070095 std::unique_ptr<EventThread> eventThread =
Dominik Laskowskif654d572018-12-20 11:03:06 -080096 makeEventThread(connectionName, mPrimaryDispSync.get(), phaseOffsetNs,
Dominik Laskowskibd52c842019-01-28 18:11:23 -080097 std::move(interceptCallback));
Dominik Laskowskif654d572018-12-20 11:03:06 -080098
Dominik Laskowskiccf37d72019-02-01 16:47:58 -080099 auto eventThreadConnection =
Ady Abrahama1a49af2019-02-07 14:36:55 -0800100 createConnectionInternal(eventThread.get(), std::move(resyncCallback));
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800101 mConnections.emplace(id,
102 std::make_unique<Connection>(new ConnectionHandle(id),
103 eventThreadConnection,
104 std::move(eventThread)));
Ana Krulec98b5b242018-08-10 15:03:23 -0700105 return mConnections[id]->handle;
106}
107
Ana Krulec0c8cd522018-08-31 12:27:28 -0700108std::unique_ptr<EventThread> Scheduler::makeEventThread(
Dominik Laskowskibd52c842019-01-28 18:11:23 -0800109 const char* connectionName, DispSync* dispSync, int64_t phaseOffsetNs,
Ana Krulec0c8cd522018-08-31 12:27:28 -0700110 impl::EventThread::InterceptVSyncsCallback interceptCallback) {
111 std::unique_ptr<VSyncSource> eventThreadSource =
Dominik Laskowskibd52c842019-01-28 18:11:23 -0800112 std::make_unique<DispSyncSource>(dispSync, phaseOffsetNs, true, connectionName);
113 return std::make_unique<impl::EventThread>(std::move(eventThreadSource),
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800114 std::move(interceptCallback), connectionName);
115}
116
Ady Abrahama1a49af2019-02-07 14:36:55 -0800117sp<EventThreadConnection> Scheduler::createConnectionInternal(EventThread* eventThread,
118 ResyncCallback&& resyncCallback) {
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800119 return eventThread->createEventConnection(std::move(resyncCallback),
Ady Abrahama1a49af2019-02-07 14:36:55 -0800120 [this] { resetIdleTimer(); });
Ana Krulec0c8cd522018-08-31 12:27:28 -0700121}
122
Ana Krulec98b5b242018-08-10 15:03:23 -0700123sp<IDisplayEventConnection> Scheduler::createDisplayEventConnection(
Ady Abrahama1a49af2019-02-07 14:36:55 -0800124 const sp<Scheduler::ConnectionHandle>& handle, ResyncCallback resyncCallback) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700125 RETURN_VALUE_IF_INVALID(nullptr);
Dominik Laskowskiccf37d72019-02-01 16:47:58 -0800126 return createConnectionInternal(mConnections[handle->id]->thread.get(),
Ady Abrahama1a49af2019-02-07 14:36:55 -0800127 std::move(resyncCallback));
Ana Krulec98b5b242018-08-10 15:03:23 -0700128}
129
130EventThread* Scheduler::getEventThread(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700131 RETURN_VALUE_IF_INVALID(nullptr);
132 return mConnections[handle->id]->thread.get();
Ana Krulec98b5b242018-08-10 15:03:23 -0700133}
134
Ana Krulec85c39af2018-12-26 17:29:57 -0800135sp<EventThreadConnection> Scheduler::getEventConnection(const sp<ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700136 RETURN_VALUE_IF_INVALID(nullptr);
137 return mConnections[handle->id]->eventConnection;
Ana Krulec98b5b242018-08-10 15:03:23 -0700138}
139
140void Scheduler::hotplugReceived(const sp<Scheduler::ConnectionHandle>& handle,
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800141 PhysicalDisplayId displayId, bool connected) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700142 RETURN_IF_INVALID();
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800143 mConnections[handle->id]->thread->onHotplugReceived(displayId, connected);
Ana Krulec98b5b242018-08-10 15:03:23 -0700144}
145
146void Scheduler::onScreenAcquired(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700147 RETURN_IF_INVALID();
148 mConnections[handle->id]->thread->onScreenAcquired();
Ana Krulec98b5b242018-08-10 15:03:23 -0700149}
150
151void Scheduler::onScreenReleased(const sp<Scheduler::ConnectionHandle>& handle) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700152 RETURN_IF_INVALID();
153 mConnections[handle->id]->thread->onScreenReleased();
Ana Krulec98b5b242018-08-10 15:03:23 -0700154}
155
Yiwei Zhang5434a782018-12-05 18:06:32 -0800156void Scheduler::dump(const sp<Scheduler::ConnectionHandle>& handle, std::string& result) const {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700157 RETURN_IF_INVALID();
158 mConnections.at(handle->id)->thread->dump(result);
Ana Krulec98b5b242018-08-10 15:03:23 -0700159}
160
161void Scheduler::setPhaseOffset(const sp<Scheduler::ConnectionHandle>& handle, nsecs_t phaseOffset) {
Ana Krulec0c8cd522018-08-31 12:27:28 -0700162 RETURN_IF_INVALID();
163 mConnections[handle->id]->thread->setPhaseOffset(phaseOffset);
Ana Krulec98b5b242018-08-10 15:03:23 -0700164}
Ana Krulece588e312018-09-18 12:32:24 -0700165
166void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats) {
167 stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0);
168 stats->vsyncPeriod = mPrimaryDispSync->getPeriod();
169}
170
171void Scheduler::enableHardwareVsync() {
172 std::lock_guard<std::mutex> lock(mHWVsyncLock);
173 if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
174 mPrimaryDispSync->beginResync();
175 mEventControlThread->setVsyncEnabled(true);
176 mPrimaryHWVsyncEnabled = true;
177 }
178}
179
180void Scheduler::disableHardwareVsync(bool makeUnavailable) {
181 std::lock_guard<std::mutex> lock(mHWVsyncLock);
182 if (mPrimaryHWVsyncEnabled) {
183 mEventControlThread->setVsyncEnabled(false);
184 mPrimaryDispSync->endResync();
185 mPrimaryHWVsyncEnabled = false;
186 }
187 if (makeUnavailable) {
188 mHWVsyncAvailable = false;
189 }
190}
191
Ana Krulecc2870422019-01-29 19:00:58 -0800192void Scheduler::resyncToHardwareVsync(bool makeAvailable, nsecs_t period) {
193 {
194 std::lock_guard<std::mutex> lock(mHWVsyncLock);
195 if (makeAvailable) {
196 mHWVsyncAvailable = makeAvailable;
197 } else if (!mHWVsyncAvailable) {
198 // Hardware vsync is not currently available, so abort the resync
199 // attempt for now
200 return;
201 }
202 }
203
204 if (period <= 0) {
205 return;
206 }
207
208 setVsyncPeriod(period);
209}
210
211ResyncCallback Scheduler::makeResyncCallback(GetVsyncPeriod&& getVsyncPeriod) {
212 std::weak_ptr<VsyncState> ptr = mPrimaryVsyncState;
213 return [ptr, getVsyncPeriod = std::move(getVsyncPeriod)]() {
214 if (const auto vsync = ptr.lock()) {
215 vsync->resync(getVsyncPeriod);
216 }
217 };
218}
219
220void Scheduler::VsyncState::resync(const GetVsyncPeriod& getVsyncPeriod) {
221 static constexpr nsecs_t kIgnoreDelay = ms2ns(500);
222
223 const nsecs_t now = systemTime();
224 const nsecs_t last = lastResyncTime.exchange(now);
225
226 if (now - last > kIgnoreDelay) {
227 scheduler.resyncToHardwareVsync(false, getVsyncPeriod());
228 }
229}
230
231void Scheduler::setRefreshSkipCount(int count) {
232 mPrimaryDispSync->setRefreshSkipCount(count);
233}
234
Ana Krulece588e312018-09-18 12:32:24 -0700235void Scheduler::setVsyncPeriod(const nsecs_t period) {
Ady Abraham3aff9172019-02-07 19:10:26 -0800236 std::lock_guard<std::mutex> lock(mHWVsyncLock);
Ana Krulece588e312018-09-18 12:32:24 -0700237 mPrimaryDispSync->reset();
238 mPrimaryDispSync->setPeriod(period);
Ady Abraham3aff9172019-02-07 19:10:26 -0800239
240 if (!mPrimaryHWVsyncEnabled) {
241 mPrimaryDispSync->beginResync();
242 mEventControlThread->setVsyncEnabled(true);
243 mPrimaryHWVsyncEnabled = true;
244 }
Ana Krulece588e312018-09-18 12:32:24 -0700245}
246
247void Scheduler::addResyncSample(const nsecs_t timestamp) {
248 bool needsHwVsync = false;
249 { // Scope for the lock
250 std::lock_guard<std::mutex> lock(mHWVsyncLock);
251 if (mPrimaryHWVsyncEnabled) {
252 needsHwVsync = mPrimaryDispSync->addResyncSample(timestamp);
253 }
254 }
255
256 if (needsHwVsync) {
257 enableHardwareVsync();
258 } else {
259 disableHardwareVsync(false);
260 }
261}
262
263void Scheduler::addPresentFence(const std::shared_ptr<FenceTime>& fenceTime) {
264 if (mPrimaryDispSync->addPresentFence(fenceTime)) {
265 enableHardwareVsync();
266 } else {
267 disableHardwareVsync(false);
268 }
269}
270
271void Scheduler::setIgnorePresentFences(bool ignore) {
272 mPrimaryDispSync->setIgnorePresentFences(ignore);
273}
274
Ady Abrahamc3e21312019-02-07 14:30:23 -0800275nsecs_t Scheduler::expectedPresentTime() {
276 return mPrimaryDispSync->expectedPresentTime();
277}
278
Ady Abraham3aff9172019-02-07 19:10:26 -0800279void Scheduler::dumpPrimaryDispSync(std::string& result) const {
280 mPrimaryDispSync->dump(result);
281}
282
Ana Krulec3084c052018-11-21 20:27:17 +0100283void Scheduler::addFramePresentTimeForLayer(const nsecs_t framePresentTime, bool isAutoTimestamp,
284 const std::string layerName) {
285 // This is V1 logic. It calculates the average FPS based on the timestamp frequency
286 // regardless of which layer the timestamp came from.
287 // For now, the averages and FPS are recorded in the systrace.
288 determineTimestampAverage(isAutoTimestamp, framePresentTime);
289
290 // This is V2 logic. It calculates the average and median timestamp difference based on the
291 // individual layer history. The results are recorded in the systrace.
292 determineLayerTimestampStats(layerName, framePresentTime);
293}
294
295void Scheduler::incrementFrameCounter() {
296 mLayerHistory.incrementCounter();
297}
298
Ana Krulec7d1d6832018-12-27 11:10:09 -0800299void Scheduler::setExpiredIdleTimerCallback(const ExpiredIdleTimerCallback& expiredTimerCallback) {
300 std::lock_guard<std::mutex> lock(mCallbackLock);
301 mExpiredTimerCallback = expiredTimerCallback;
302}
303
Ady Abrahama1a49af2019-02-07 14:36:55 -0800304void Scheduler::setResetIdleTimerCallback(const ResetIdleTimerCallback& resetTimerCallback) {
305 std::lock_guard<std::mutex> lock(mCallbackLock);
306 mResetTimerCallback = resetTimerCallback;
307}
308
Ana Krulec3084c052018-11-21 20:27:17 +0100309void Scheduler::updateFrameSkipping(const int64_t skipCount) {
310 ATRACE_INT("FrameSkipCount", skipCount);
311 if (mSkipCount != skipCount) {
312 // Only update DispSync if it hasn't been updated yet.
313 mPrimaryDispSync->setRefreshSkipCount(skipCount);
314 mSkipCount = skipCount;
315 }
316}
317
318void Scheduler::determineLayerTimestampStats(const std::string layerName,
319 const nsecs_t framePresentTime) {
320 mLayerHistory.insert(layerName, framePresentTime);
321 std::vector<int64_t> differencesMs;
322
323 // Traverse through the layer history, and determine the differences in present times.
324 nsecs_t newestPresentTime = framePresentTime;
Ana Krulec434c22d2018-11-28 13:48:36 +0100325 std::string differencesText = "";
Ana Krulec3084c052018-11-21 20:27:17 +0100326 for (int i = 1; i < mLayerHistory.getSize(); i++) {
327 std::unordered_map<std::string, nsecs_t> layers = mLayerHistory.get(i);
328 for (auto layer : layers) {
329 if (layer.first != layerName) {
330 continue;
331 }
332 int64_t differenceMs = (newestPresentTime - layer.second) / 1000000;
Ana Krulec3084c052018-11-21 20:27:17 +0100333 // Dismiss noise.
334 if (differenceMs > 10 && differenceMs < 60) {
335 differencesMs.push_back(differenceMs);
336 }
Ana Krulec434c22d2018-11-28 13:48:36 +0100337 IF_ALOGV() { differencesText += (std::to_string(differenceMs) + " "); }
Ana Krulec3084c052018-11-21 20:27:17 +0100338 newestPresentTime = layer.second;
339 }
340 }
Ana Krulec434c22d2018-11-28 13:48:36 +0100341 ALOGV("Layer %s timestamp intervals: %s", layerName.c_str(), differencesText.c_str());
Ana Krulec3084c052018-11-21 20:27:17 +0100342
Ana Krulec434c22d2018-11-28 13:48:36 +0100343 if (!differencesMs.empty()) {
344 // Mean/Average is a good indicator for when 24fps videos are playing, because the frames
345 // come in 33, and 49 ms intervals with occasional 41ms.
346 const int64_t meanMs = scheduler::calculate_mean(differencesMs);
347 const auto tagMean = "TimestampMean_" + layerName;
348 ATRACE_INT(tagMean.c_str(), meanMs);
349
350 // Mode and median are good indicators for 30 and 60 fps videos, because the majority of
351 // frames come in 16, or 33 ms intervals.
Ana Krulec3084c052018-11-21 20:27:17 +0100352 const auto tagMedian = "TimestampMedian_" + layerName;
Ana Krulec434c22d2018-11-28 13:48:36 +0100353 ATRACE_INT(tagMedian.c_str(), scheduler::calculate_median(&differencesMs));
Ana Krulec3084c052018-11-21 20:27:17 +0100354
Ana Krulec434c22d2018-11-28 13:48:36 +0100355 const auto tagMode = "TimestampMode_" + layerName;
356 ATRACE_INT(tagMode.c_str(), scheduler::calculate_mode(differencesMs));
Ana Krulec3084c052018-11-21 20:27:17 +0100357 }
Ana Krulec3084c052018-11-21 20:27:17 +0100358}
359
360void Scheduler::determineTimestampAverage(bool isAutoTimestamp, const nsecs_t framePresentTime) {
Ana Krulec7ab56032018-11-02 20:51:06 +0100361 ATRACE_INT("AutoTimestamp", isAutoTimestamp);
Ana Krulec3084c052018-11-21 20:27:17 +0100362
Ana Krulec7ab56032018-11-02 20:51:06 +0100363 // Video does not have timestamp automatically set, so we discard timestamps that are
364 // coming in from other sources for now.
365 if (isAutoTimestamp) {
366 return;
367 }
Ana Krulec3084c052018-11-21 20:27:17 +0100368 int64_t differenceMs = (framePresentTime - mPreviousFrameTimestamp) / 1000000;
369 mPreviousFrameTimestamp = framePresentTime;
Ana Krulec7ab56032018-11-02 20:51:06 +0100370
371 if (differenceMs < 10 || differenceMs > 100) {
372 // Dismiss noise.
373 return;
374 }
375 ATRACE_INT("TimestampDiff", differenceMs);
376
Ana Krulec434c22d2018-11-28 13:48:36 +0100377 mTimeDifferences[mCounter % scheduler::ARRAY_SIZE] = differenceMs;
Ana Krulec7ab56032018-11-02 20:51:06 +0100378 mCounter++;
Ana Krulec434c22d2018-11-28 13:48:36 +0100379 int64_t mean = scheduler::calculate_mean(mTimeDifferences);
380 ATRACE_INT("AutoTimestampMean", mean);
Ana Krulec7ab56032018-11-02 20:51:06 +0100381
382 // TODO(b/113612090): This are current numbers from trial and error while running videos
383 // from YouTube at 24, 30, and 60 fps.
Ana Krulec434c22d2018-11-28 13:48:36 +0100384 if (mean > 14 && mean < 18) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800385 ATRACE_INT("MediaFPS", 60);
Ana Krulec434c22d2018-11-28 13:48:36 +0100386 } else if (mean > 31 && mean < 34) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800387 ATRACE_INT("MediaFPS", 30);
Ana Krulec7ab56032018-11-02 20:51:06 +0100388 return;
Ana Krulec434c22d2018-11-28 13:48:36 +0100389 } else if (mean > 39 && mean < 42) {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800390 ATRACE_INT("MediaFPS", 24);
Ana Krulec7ab56032018-11-02 20:51:06 +0100391 }
Ana Krulec7ab56032018-11-02 20:51:06 +0100392}
393
Ana Krulecfb772822018-11-30 10:44:07 +0100394void Scheduler::resetIdleTimer() {
395 if (mIdleTimer) {
396 mIdleTimer->reset();
Ady Abrahama1a49af2019-02-07 14:36:55 -0800397 }
398}
399
400void Scheduler::resetTimerCallback() {
401 std::lock_guard<std::mutex> lock(mCallbackLock);
402 if (mResetTimerCallback) {
403 mResetTimerCallback();
Ana Krulecfb772822018-11-30 10:44:07 +0100404 ATRACE_INT("ExpiredIdleTimer", 0);
405 }
406}
407
408void Scheduler::expiredTimerCallback() {
Ana Krulec7d1d6832018-12-27 11:10:09 -0800409 std::lock_guard<std::mutex> lock(mCallbackLock);
410 if (mExpiredTimerCallback) {
411 mExpiredTimerCallback();
412 ATRACE_INT("ExpiredIdleTimer", 1);
413 }
Ana Krulecfb772822018-11-30 10:44:07 +0100414}
415
Ana Krulecb43429d2019-01-09 14:28:51 -0800416std::string Scheduler::doDump() {
417 std::ostringstream stream;
418 stream << "+ Idle timer interval: " << mSetIdleTimerMs << " ms" << std::endl;
419 return stream.str();
420}
421
Ana Krulec98b5b242018-08-10 15:03:23 -0700422} // namespace android