Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/scheduler/Scheduler.h" | 6 #include "platform/scheduler/Scheduler.h" |
| 7 | 7 |
| 8 #include "platform/PlatformThreadData.h" | 8 #include "platform/PlatformThreadData.h" |
| 9 #include "platform/Task.h" | 9 #include "platform/Task.h" |
| 10 #include "platform/ThreadTimers.h" | 10 #include "platform/ThreadTimers.h" |
| 11 #include "platform/TraceEvent.h" | 11 #include "platform/TraceEvent.h" |
| 12 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 13 #include "wtf/MainThread.h" | 13 #include "wtf/MainThread.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // The time we should stay in CompositorPriority mode for, after a touch event. | 19 // The time we should stay in CompositorPriority mode for, after a touch event. |
| 20 double kLowSchedulerPolicyAfterTouchTimeSeconds = 0.1; | 20 double kLowSchedulerPolicyAfterTouchTimeSeconds = 0.1; |
| 21 | 21 |
| 22 // Can be created from any thread. | |
| 23 // Note if the scheduler gets shutdown, this may be run after. | |
| 24 class MainThreadIdleTaskAdapter : public WebThread::Task { | |
| 25 public: | |
| 26 MainThreadIdleTaskAdapter(const Scheduler::IdleTask& idleTask, double allott edTimeMs, const TraceLocation& location) | |
| 27 : m_idleTask(idleTask) | |
| 28 , m_allottedTimeMs(allottedTimeMs) | |
| 29 , m_location(location) | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 // WebThread::Task implementation. | |
| 34 virtual void run() OVERRIDE | |
| 35 { | |
| 36 TRACE_EVENT2("blink", "MainThreadIdleTaskAdapter::run", | |
| 37 "src_file", m_location.fileName(), | |
| 38 "src_func", m_location.functionName()); | |
| 39 m_idleTask(m_allottedTimeMs); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 Scheduler::IdleTask m_idleTask; | |
| 44 double m_allottedTimeMs; | |
| 45 TraceLocation m_location; | |
| 46 }; | |
| 47 | |
| 48 } // namespace | 22 } // namespace |
| 49 | 23 |
| 50 // Typically only created from compositor or render threads. | 24 // Typically only created from compositor or render threads. |
| 51 // Note if the scheduler gets shutdown, this may be run after. | 25 // Note if the scheduler gets shutdown, this may be run after. |
| 52 class Scheduler::MainThreadPendingHighPriorityTaskRunner : public WebThread::Tas k { | 26 class Scheduler::MainThreadPendingHighPriorityTaskRunner : public WebThread::Tas k { |
| 53 public: | 27 public: |
| 54 MainThreadPendingHighPriorityTaskRunner() | 28 MainThreadPendingHighPriorityTaskRunner() |
| 55 { | 29 { |
| 56 ASSERT(Scheduler::shared()); | 30 ASSERT(Scheduler::shared()); |
| 57 } | 31 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 79 const Scheduler::Task& task, const TraceLocation& location, const char* traceName) | 53 const Scheduler::Task& task, const TraceLocation& location, const char* traceName) |
| 80 : m_task(task, location, traceName) | 54 : m_task(task, location, traceName) |
| 81 { | 55 { |
| 82 ASSERT(Scheduler::shared()); | 56 ASSERT(Scheduler::shared()); |
| 83 } | 57 } |
| 84 | 58 |
| 85 // WebThread::Task implementation. | 59 // WebThread::Task implementation. |
| 86 virtual void run() OVERRIDE | 60 virtual void run() OVERRIDE |
| 87 { | 61 { |
| 88 Scheduler* scheduler = Scheduler::shared(); | 62 Scheduler* scheduler = Scheduler::shared(); |
| 89 // FIXME: This check should't be necessary, tasks should not outlive bli nk. | 63 // FIXME: This check shouldn't be necessary, tasks should not outlive bl ink. |
| 90 ASSERT(scheduler); | 64 ASSERT(scheduler); |
| 91 if (scheduler) | 65 if (scheduler) |
| 92 Scheduler::shared()->runPendingHighPriorityTasksIfInCompositorPriori ty(); | 66 scheduler->runPendingHighPriorityTasksIfInCompositorPriority(); |
| 67 | |
| 93 m_task.run(); | 68 m_task.run(); |
| 94 } | 69 } |
| 95 | 70 |
| 96 TracedTask m_task; | 71 private: |
| 72 TracedStandardTask m_task; | |
| 97 }; | 73 }; |
| 98 | 74 |
| 75 | |
| 76 // Can be created from any thread. | |
| 77 // Note if the scheduler gets shutdown, this may be run after. | |
| 78 class Scheduler::MainThreadPendingIdleTaskRunner : public WebThread::Task { | |
| 79 public: | |
| 80 MainThreadPendingIdleTaskRunner(const TracedIdleTask& idleTask) | |
| 81 : m_idleTask(idleTask) | |
| 82 { | |
| 83 ASSERT(Scheduler::shared()); | |
| 84 } | |
| 85 | |
| 86 // WebThread::Task implementation. | |
| 87 virtual void run() OVERRIDE | |
| 88 { | |
| 89 Scheduler* scheduler = Scheduler::shared(); | |
| 90 // FIXME: This check shouldn't be necessary, tasks should not outlive bl ink. | |
| 91 ASSERT(scheduler); | |
| 92 if (scheduler) { | |
| 93 scheduler->runPendingHighPriorityTasksIfInCompositorPriority(); | |
| 94 | |
| 95 if (scheduler->canRunIdleTask()) { | |
| 96 m_idleTask.run(); | |
| 97 // Run the next idle task if possible. | |
| 98 scheduler->maybePostMainThreadPendingIdleTask(); | |
| 99 } else { | |
| 100 scheduler->repostIdleTaskAtFront(m_idleTask); | |
|
alexclarke
2014/09/30 15:47:51
It seems complex to pop and then repost the task i
Sami
2014/09/30 16:14:47
Yeah, that seems simpler. Just need to be careful
rmcilroy
2014/10/03 09:40:24
Make sense, done.
| |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 private: | |
| 106 TracedIdleTask m_idleTask; | |
| 107 }; | |
| 108 | |
| 109 | |
| 99 Scheduler* Scheduler::s_sharedScheduler = nullptr; | 110 Scheduler* Scheduler::s_sharedScheduler = nullptr; |
| 100 | 111 |
| 101 void Scheduler::initializeOnMainThread() | 112 void Scheduler::initializeOnMainThread() |
| 102 { | 113 { |
| 103 s_sharedScheduler = new Scheduler(); | 114 s_sharedScheduler = new Scheduler(); |
| 104 } | 115 } |
| 105 | 116 |
| 106 void Scheduler::shutdown() | 117 void Scheduler::shutdown() |
| 107 { | 118 { |
| 108 delete s_sharedScheduler; | 119 delete s_sharedScheduler; |
| 109 s_sharedScheduler = nullptr; | 120 s_sharedScheduler = nullptr; |
| 110 } | 121 } |
| 111 | 122 |
| 112 Scheduler* Scheduler::shared() | 123 Scheduler* Scheduler::shared() |
| 113 { | 124 { |
| 114 return s_sharedScheduler; | 125 return s_sharedScheduler; |
| 115 } | 126 } |
| 116 | 127 |
| 117 Scheduler::Scheduler() | 128 Scheduler::Scheduler() |
| 118 : m_sharedTimerFunction(nullptr) | 129 : m_sharedTimerFunction(nullptr) |
| 119 , m_mainThread(blink::Platform::current()->currentThread()) | 130 , m_mainThread(blink::Platform::current()->currentThread()) |
| 120 , m_compositorPriorityPolicyEndTimeSeconds(0) | 131 , m_compositorPriorityPolicyEndTimeSeconds(0) |
| 132 , m_currentFrameDeadlineSeconds(0) | |
| 121 , m_highPriorityTaskCount(0) | 133 , m_highPriorityTaskCount(0) |
| 122 , m_highPriorityTaskRunnerPosted(false) | 134 , m_highPriorityTaskRunnerPosted(false) |
| 123 , m_schedulerPolicy(Normal) | 135 , m_schedulerPolicy(Normal) |
| 124 { | 136 { |
| 125 } | 137 } |
| 126 | 138 |
| 127 Scheduler::~Scheduler() | 139 Scheduler::~Scheduler() |
| 128 { | 140 { |
| 129 while (hasPendingHighPriorityWork()) { | 141 while (hasPendingHighPriorityWork()) { |
| 130 swapQueuesAndRunPendingTasks(); | 142 swapQueuesAndRunPendingTasks(); |
| 131 } | 143 } |
| 132 } | 144 } |
| 133 | 145 |
| 134 void Scheduler::willBeginFrame(const WebBeginFrameArgs& args) | 146 void Scheduler::willBeginFrame(double frameDeadlineSeconds) |
| 135 { | 147 { |
| 136 // TODO: Use frame deadline and interval to schedule idle tasks. | 148 m_currentFrameCommitted = false; |
| 149 m_currentFrameDeadlineSeconds = frameDeadlineSeconds; | |
| 150 | |
| 151 // TODO: Schedule a deferred task here to run idle work if didCommitFrameToC ompositor never get's called | |
| 137 } | 152 } |
| 138 | 153 |
| 139 void Scheduler::didCommitFrameToCompositor() | 154 void Scheduler::didCommitFrameToCompositor() |
| 140 { | 155 { |
| 141 // TODO: Trigger the frame deadline immediately. | 156 m_currentFrameCommitted = true; |
| 142 } | 157 maybePostMainThreadPendingIdleTask(); |
| 143 | |
| 144 void Scheduler::scheduleIdleTask(const TraceLocation& location, const IdleTask& idleTask) | |
| 145 { | |
| 146 // TODO: send a real allottedTime here. | |
| 147 m_mainThread->postTask(new MainThreadIdleTaskAdapter(idleTask, 0, location)) ; | |
| 148 } | 158 } |
| 149 | 159 |
| 150 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName) | 160 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName) |
| 151 { | 161 { |
| 152 Locker<Mutex> lock(m_pendingTasksMutex); | 162 Locker<Mutex> lock(m_pendingTasksMutex); |
| 153 | 163 |
| 154 m_pendingHighPriorityTasks.append(TracedTask(task, location, traceName)); | 164 m_pendingHighPriorityTasks.append(TracedStandardTask(task, location, traceNa me)); |
| 155 atomicIncrement(&m_highPriorityTaskCount); | 165 atomicIncrement(&m_highPriorityTaskCount); |
| 156 maybePostMainThreadPendingHighPriorityTaskRunner(); | 166 maybePostMainThreadPendingHighPriorityTaskRunner(); |
| 157 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); | 167 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); |
| 158 } | 168 } |
| 159 | 169 |
| 170 void Scheduler::postIdleTaskInternal(const TraceLocation& location, const IdleTa sk& idleTask, const char* traceName) | |
| 171 { | |
| 172 Locker<Mutex> lock(m_pendingTasksMutex); | |
| 173 m_pendingIdleTasks.append(TracedIdleTask(idleTask, location, traceName)); | |
| 174 } | |
| 175 | |
| 160 void Scheduler::postTask(const TraceLocation& location, const Task& task) | 176 void Scheduler::postTask(const TraceLocation& location, const Task& task) |
| 161 { | 177 { |
| 162 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask")); | 178 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask")); |
| 163 } | 179 } |
| 164 | 180 |
| 165 void Scheduler::postInputTask(const TraceLocation& location, const Task& task) | 181 void Scheduler::postInputTask(const TraceLocation& location, const Task& task) |
| 166 { | 182 { |
| 167 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask"); | 183 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask"); |
| 168 } | 184 } |
| 169 | 185 |
| 170 void Scheduler::didReceiveInputEvent() | 186 void Scheduler::didReceiveInputEvent() |
| 171 { | 187 { |
| 172 enterSchedulerPolicy(CompositorPriority); | 188 enterSchedulerPolicy(CompositorPriority); |
| 173 } | 189 } |
| 174 | 190 |
| 175 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk) | 191 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk) |
| 176 { | 192 { |
| 177 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask"); | 193 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask"); |
| 178 } | 194 } |
| 179 | 195 |
| 180 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task) | 196 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task) |
| 181 { | 197 { |
| 182 // FIXME: we want IPCs to be high priority, but we can't currently do that b ecause some of them can take a very long | 198 // FIXME: we want IPCs to be high priority, but we can't currently do that b ecause some of them can take a very long |
| 183 // time to process. These need refactoring but we need to add some infrastru cture to identify them. | 199 // time to process. These need refactoring but we need to add some infrastru cture to identify them. |
| 184 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::IpcTask")); | 200 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::IpcTask")); |
| 185 } | 201 } |
| 186 | 202 |
| 203 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task) | |
| 204 { | |
| 205 postIdleTaskInternal(location, idleTask, "Scheduler::IdleTask"); | |
| 206 } | |
| 207 | |
| 187 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() | 208 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() |
| 188 { | 209 { |
| 189 ASSERT(m_pendingTasksMutex.locked()); | 210 ASSERT(m_pendingTasksMutex.locked()); |
| 190 if (m_highPriorityTaskRunnerPosted) | 211 if (m_highPriorityTaskRunnerPosted) |
| 191 return; | 212 return; |
| 192 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner()); | 213 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner()); |
| 193 m_highPriorityTaskRunnerPosted = true; | 214 m_highPriorityTaskRunnerPosted = true; |
| 194 } | 215 } |
| 195 | 216 |
| 196 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task) | 217 bool Scheduler::maybePostMainThreadPendingIdleTask() |
| 197 { | 218 { |
| 198 scheduleIdleTask(location, idleTask); | 219 TRACE_EVENT0("blink", "Scheduler::maybePostMainThreadPendingIdleTask"); |
| 220 if (canRunIdleTask()) { | |
| 221 Locker<Mutex> lock(m_pendingTasksMutex); | |
| 222 if (!m_pendingIdleTasks.isEmpty()) { | |
| 223 m_mainThread->postTask(new MainThreadPendingIdleTaskRunner(m_pending IdleTasks.takeFirst())); | |
| 224 return true; | |
| 225 } | |
| 226 } | |
| 227 return false; | |
| 199 } | 228 } |
| 200 | 229 |
| 201 void Scheduler::tickSharedTimer() | 230 void Scheduler::tickSharedTimer() |
| 202 { | 231 { |
| 203 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); | 232 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); |
| 204 | 233 |
| 205 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately. | 234 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately. |
| 206 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority(); | 235 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority(); |
| 207 m_sharedTimerFunction(); | 236 m_sharedTimerFunction(); |
| 208 | 237 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 221 return swapQueuesAndRunPendingTasks(); | 250 return swapQueuesAndRunPendingTasks(); |
| 222 } | 251 } |
| 223 | 252 |
| 224 bool Scheduler::swapQueuesAndRunPendingTasks() | 253 bool Scheduler::swapQueuesAndRunPendingTasks() |
| 225 { | 254 { |
| 226 ASSERT(isMainThread()); | 255 ASSERT(isMainThread()); |
| 227 | 256 |
| 228 // These locks guard against another thread posting input or compositor task s while we swap the buffers. | 257 // These locks guard against another thread posting input or compositor task s while we swap the buffers. |
| 229 // One the buffers have been swapped we can safely access the returned deque without having to lock. | 258 // One the buffers have been swapped we can safely access the returned deque without having to lock. |
| 230 m_pendingTasksMutex.lock(); | 259 m_pendingTasksMutex.lock(); |
| 231 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); | 260 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers(); |
| 232 maybeEnterNormalSchedulerPolicy(); | 261 maybeEnterNormalSchedulerPolicy(); |
| 233 m_pendingTasksMutex.unlock(); | 262 m_pendingTasksMutex.unlock(); |
| 234 return executeHighPriorityTasks(highPriorityTasks); | 263 return executeHighPriorityTasks(highPriorityTasks); |
| 235 } | 264 } |
| 236 | 265 |
| 237 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting() | 266 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting() |
| 238 { | 267 { |
| 239 ASSERT(isMainThread()); | 268 ASSERT(isMainThread()); |
| 240 | 269 |
| 241 // These locks guard against another thread posting input or compositor task s while we swap the buffers. | 270 // These locks guard against another thread posting input or compositor task s while we swap the buffers. |
| 242 // One the buffers have been swapped we can safely access the returned deque without having to lock. | 271 // One the buffers have been swapped we can safely access the returned deque without having to lock. |
| 243 m_pendingTasksMutex.lock(); | 272 m_pendingTasksMutex.lock(); |
| 244 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); | 273 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers(); |
| 245 m_highPriorityTaskRunnerPosted = false; | 274 m_highPriorityTaskRunnerPosted = false; |
| 246 maybeEnterNormalSchedulerPolicy(); | 275 maybeEnterNormalSchedulerPolicy(); |
| 247 m_pendingTasksMutex.unlock(); | 276 m_pendingTasksMutex.unlock(); |
| 248 executeHighPriorityTasks(highPriorityTasks); | 277 executeHighPriorityTasks(highPriorityTasks); |
| 249 } | 278 } |
| 250 | 279 |
| 251 void Scheduler::maybeEnterNormalSchedulerPolicy() | 280 void Scheduler::maybeEnterNormalSchedulerPolicy() |
| 252 { | 281 { |
| 253 ASSERT(isMainThread()); | 282 ASSERT(isMainThread()); |
| 254 ASSERT(m_pendingTasksMutex.locked()); | 283 ASSERT(m_pendingTasksMutex.locked()); |
| 255 | 284 |
| 256 // Go back to the normal scheduler policy if enough time has elapsed. | 285 // Go back to the normal scheduler policy if enough time has elapsed. |
| 257 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds) | 286 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds) |
| 258 enterSchedulerPolicyLocked(Normal); | 287 enterSchedulerPolicyLocked(Normal); |
| 259 } | 288 } |
| 260 | 289 |
| 261 bool Scheduler::executeHighPriorityTasks(Deque<TracedTask>& highPriorityTasks) | 290 bool Scheduler::executeHighPriorityTasks(Deque<TracedStandardTask>& highPriority Tasks) |
| 262 { | 291 { |
| 263 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks"); | 292 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks"); |
| 264 int highPriorityTasksExecuted = 0; | 293 int highPriorityTasksExecuted = 0; |
| 265 while (!highPriorityTasks.isEmpty()) { | 294 while (!highPriorityTasks.isEmpty()) { |
| 266 highPriorityTasks.takeFirst().run(); | 295 highPriorityTasks.takeFirst().run(); |
| 267 highPriorityTasksExecuted++; | 296 highPriorityTasksExecuted++; |
| 268 } | 297 } |
| 269 | 298 |
| 270 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted); | 299 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted); |
| 271 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0); | 300 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0); |
| 272 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); | 301 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); |
| 273 return highPriorityTasksExecuted > 0; | 302 return highPriorityTasksExecuted > 0; |
| 274 } | 303 } |
| 275 | 304 |
| 305 void Scheduler::repostIdleTaskAtFront(const TracedIdleTask& idleTask) | |
| 306 { | |
| 307 Locker<Mutex> lock(m_pendingTasksMutex); | |
| 308 // Post at the front since the task didn't get a chance to run. | |
| 309 m_pendingIdleTasks.prepend(idleTask); | |
| 310 } | |
| 311 | |
| 276 void Scheduler::sharedTimerAdapter() | 312 void Scheduler::sharedTimerAdapter() |
| 277 { | 313 { |
| 278 shared()->tickSharedTimer(); | 314 shared()->tickSharedTimer(); |
| 279 } | 315 } |
| 280 | 316 |
| 281 void Scheduler::setSharedTimerFiredFunction(void (*function)()) | 317 void Scheduler::setSharedTimerFiredFunction(void (*function)()) |
| 282 { | 318 { |
| 283 m_sharedTimerFunction = function; | 319 m_sharedTimerFunction = function; |
| 284 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr); | 320 blink::Platform::current()->setSharedTimerFiredFunction(function ? &Schedule r::sharedTimerAdapter : nullptr); |
| 285 } | 321 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 306 bool Scheduler::hasPendingHighPriorityWork() const | 342 bool Scheduler::hasPendingHighPriorityWork() const |
| 307 { | 343 { |
| 308 // This method is expected to be run on the main thread, but the high priori ty tasks will be posted by | 344 // This method is expected to be run on the main thread, but the high priori ty tasks will be posted by |
| 309 // other threads. We could use locks here, but this function is (sometimes) called a lot by | 345 // other threads. We could use locks here, but this function is (sometimes) called a lot by |
| 310 // ThreadTimers::sharedTimerFiredInternal so we decided to use atomics + bar rier loads here which | 346 // ThreadTimers::sharedTimerFiredInternal so we decided to use atomics + bar rier loads here which |
| 311 // should be cheaper. | 347 // should be cheaper. |
| 312 // NOTE it's possible the barrier read is overkill here, since delayed yield ing isn't a big deal. | 348 // NOTE it's possible the barrier read is overkill here, since delayed yield ing isn't a big deal. |
| 313 return acquireLoad(&m_highPriorityTaskCount) != 0; | 349 return acquireLoad(&m_highPriorityTaskCount) != 0; |
| 314 } | 350 } |
| 315 | 351 |
| 352 double Scheduler::currentFrameDeadlineSeconds() const | |
| 353 { | |
| 354 return m_currentFrameDeadlineSeconds; | |
| 355 } | |
| 356 | |
| 357 bool Scheduler::canRunIdleTask() const | |
| 358 { | |
| 359 return m_currentFrameCommitted && (m_currentFrameDeadlineSeconds > Platform: :current()->monotonicallyIncreasingTime()); | |
| 360 } | |
| 361 | |
| 316 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const | 362 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const |
| 317 { | 363 { |
| 318 ASSERT(isMainThread()); | 364 ASSERT(isMainThread()); |
| 319 // It's important not to miss the transition from normal to low latency mode , otherwise we're likely to | 365 // It's important not to miss the transition from normal to low latency mode , otherwise we're likely to |
| 320 // delay the processing of input tasks. Since that transition is triggered b y a different thread, we | 366 // delay the processing of input tasks. Since that transition is triggered b y a different thread, we |
| 321 // need either a lock or a memory barrier, and the memory barrier is probabl y cheaper. | 367 // need either a lock or a memory barrier, and the memory barrier is probabl y cheaper. |
| 322 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy)); | 368 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy)); |
| 323 } | 369 } |
| 324 | 370 |
| 325 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy) | 371 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy) |
| 326 { | 372 { |
| 327 Locker<Mutex> lock(m_pendingTasksMutex); | 373 Locker<Mutex> lock(m_pendingTasksMutex); |
| 328 enterSchedulerPolicyLocked(schedulerPolicy); | 374 enterSchedulerPolicyLocked(schedulerPolicy); |
| 329 } | 375 } |
| 330 | 376 |
| 331 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy) | 377 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy) |
| 332 { | 378 { |
| 333 ASSERT(m_pendingTasksMutex.locked()); | 379 ASSERT(m_pendingTasksMutex.locked()); |
| 334 if (schedulerPolicy == CompositorPriority) | 380 if (schedulerPolicy == CompositorPriority) |
| 335 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds; | 381 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds; |
| 336 | 382 |
| 337 releaseStore(&m_schedulerPolicy, schedulerPolicy); | 383 releaseStore(&m_schedulerPolicy, schedulerPolicy); |
| 338 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy); | 384 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy); |
| 339 } | 385 } |
| 340 | 386 |
| 341 } // namespace blink | 387 } // namespace blink |
| OLD | NEW |