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() | |
81 { | |
82 ASSERT(Scheduler::shared()); | |
83 } | |
84 | |
85 // WebThread::Task implementation. | |
86 virtual void run() OVERRIDE | |
87 { | |
88 Scheduler* scheduler = Scheduler::shared(); | |
89 // FIXME: This check shouldn't be necessary, tasks should not outlive bl ink. | |
90 ASSERT(scheduler); | |
91 if (scheduler) { | |
92 scheduler->runPendingHighPriorityTasksIfInCompositorPriority(); | |
jochen (gone - plz use gerrit)
2014/10/06 07:33:19
if we're in compositor priority, why run an idle t
Sami
2014/10/06 09:48:30
Right, this call could be removed from here and we
rmcilroy
2014/10/06 11:29:42
The original reason I had this here was in case we
| |
93 scheduler->maybeRunPendingIdleTask(); | |
94 // If possible, run the next idle task by reposting on the main thre ad. | |
95 scheduler->maybePostMainThreadPendingIdleTask(); | |
96 } | |
97 } | |
98 | |
99 }; | |
100 | |
101 | |
99 Scheduler* Scheduler::s_sharedScheduler = nullptr; | 102 Scheduler* Scheduler::s_sharedScheduler = nullptr; |
100 | 103 |
101 void Scheduler::initializeOnMainThread() | 104 void Scheduler::initializeOnMainThread() |
102 { | 105 { |
103 s_sharedScheduler = new Scheduler(); | 106 s_sharedScheduler = new Scheduler(); |
104 } | 107 } |
105 | 108 |
106 void Scheduler::shutdown() | 109 void Scheduler::shutdown() |
107 { | 110 { |
108 delete s_sharedScheduler; | 111 delete s_sharedScheduler; |
109 s_sharedScheduler = nullptr; | 112 s_sharedScheduler = nullptr; |
110 } | 113 } |
111 | 114 |
112 Scheduler* Scheduler::shared() | 115 Scheduler* Scheduler::shared() |
113 { | 116 { |
114 return s_sharedScheduler; | 117 return s_sharedScheduler; |
115 } | 118 } |
116 | 119 |
117 Scheduler::Scheduler() | 120 Scheduler::Scheduler() |
118 : m_sharedTimerFunction(nullptr) | 121 : m_sharedTimerFunction(nullptr) |
119 , m_mainThread(blink::Platform::current()->currentThread()) | 122 , m_mainThread(blink::Platform::current()->currentThread()) |
120 , m_compositorPriorityPolicyEndTimeSeconds(0) | 123 , m_compositorPriorityPolicyEndTimeSeconds(0) |
124 , m_currentFrameDeadlineSeconds(0) | |
121 , m_highPriorityTaskCount(0) | 125 , m_highPriorityTaskCount(0) |
122 , m_highPriorityTaskRunnerPosted(false) | 126 , m_highPriorityTaskRunnerPosted(false) |
123 , m_schedulerPolicy(Normal) | 127 , m_schedulerPolicy(Normal) |
124 { | 128 { |
125 } | 129 } |
126 | 130 |
127 Scheduler::~Scheduler() | 131 Scheduler::~Scheduler() |
128 { | 132 { |
129 while (hasPendingHighPriorityWork()) { | 133 while (hasPendingHighPriorityWork()) { |
130 swapQueuesAndRunPendingTasks(); | 134 swapQueuesAndRunPendingTasks(); |
131 } | 135 } |
132 } | 136 } |
133 | 137 |
134 void Scheduler::willBeginFrame(const WebBeginFrameArgs& args) | 138 void Scheduler::willBeginFrame(double frameDeadlineSeconds) |
135 { | 139 { |
136 // TODO: Use frame deadline and interval to schedule idle tasks. | 140 ASSERT(isMainThread()); |
141 m_currentFrameCommitted = false; | |
142 m_currentFrameDeadlineSeconds = frameDeadlineSeconds; | |
143 // TODO: Schedule a deferred task here to run idle work if didCommitFrameToC ompositor never get's called | |
137 } | 144 } |
138 | 145 |
139 void Scheduler::didCommitFrameToCompositor() | 146 void Scheduler::didCommitFrameToCompositor() |
140 { | 147 { |
141 // TODO: Trigger the frame deadline immediately. | 148 ASSERT(isMainThread()); |
142 } | 149 m_currentFrameCommitted = true; |
143 | 150 maybePostMainThreadPendingIdleTask(); |
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 } | 151 } |
149 | 152 |
150 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName) | 153 void Scheduler::postHighPriorityTaskInternal(const TraceLocation& location, cons t Task& task, const char* traceName) |
151 { | 154 { |
152 Locker<Mutex> lock(m_pendingTasksMutex); | 155 Locker<Mutex> lock(m_pendingTasksMutex); |
153 | 156 |
154 m_pendingHighPriorityTasks.append(TracedTask(task, location, traceName)); | 157 m_pendingHighPriorityTasks.append(TracedStandardTask(task, location, traceNa me)); |
155 atomicIncrement(&m_highPriorityTaskCount); | 158 atomicIncrement(&m_highPriorityTaskCount); |
156 maybePostMainThreadPendingHighPriorityTaskRunner(); | 159 maybePostMainThreadPendingHighPriorityTaskRunner(); |
157 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); | 160 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "PendingHighPri orityTasks", m_highPriorityTaskCount); |
158 } | 161 } |
159 | 162 |
163 void Scheduler::postIdleTaskInternal(const TraceLocation& location, const IdleTa sk& idleTask, const char* traceName) | |
164 { | |
165 Locker<Mutex> lock(m_pendingTasksMutex); | |
166 m_pendingIdleTasks.append(TracedIdleTask(idleTask, location, traceName)); | |
167 } | |
168 | |
160 void Scheduler::postTask(const TraceLocation& location, const Task& task) | 169 void Scheduler::postTask(const TraceLocation& location, const Task& task) |
161 { | 170 { |
162 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask")); | 171 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::MainThreadTask")); |
163 } | 172 } |
164 | 173 |
165 void Scheduler::postInputTask(const TraceLocation& location, const Task& task) | 174 void Scheduler::postInputTask(const TraceLocation& location, const Task& task) |
166 { | 175 { |
167 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask"); | 176 postHighPriorityTaskInternal(location, task, "Scheduler::InputTask"); |
168 } | 177 } |
169 | 178 |
170 void Scheduler::didReceiveInputEvent() | 179 void Scheduler::didReceiveInputEvent() |
171 { | 180 { |
172 enterSchedulerPolicy(CompositorPriority); | 181 enterSchedulerPolicy(CompositorPriority); |
173 } | 182 } |
174 | 183 |
175 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk) | 184 void Scheduler::postCompositorTask(const TraceLocation& location, const Task& ta sk) |
176 { | 185 { |
177 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask"); | 186 postHighPriorityTaskInternal(location, task, "Scheduler::CompositorTask"); |
178 } | 187 } |
179 | 188 |
180 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task) | 189 void Scheduler::postIpcTask(const TraceLocation& location, const Task& task) |
181 { | 190 { |
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 | 191 // 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. | 192 // 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")); | 193 m_mainThread->postTask(new MainThreadPendingTaskRunner(task, location, "Sche duler::IpcTask")); |
185 } | 194 } |
186 | 195 |
196 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task) | |
197 { | |
198 postIdleTaskInternal(location, idleTask, "Scheduler::IdleTask"); | |
199 } | |
200 | |
187 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() | 201 void Scheduler::maybePostMainThreadPendingHighPriorityTaskRunner() |
188 { | 202 { |
189 ASSERT(m_pendingTasksMutex.locked()); | 203 ASSERT(m_pendingTasksMutex.locked()); |
190 if (m_highPriorityTaskRunnerPosted) | 204 if (m_highPriorityTaskRunnerPosted) |
191 return; | 205 return; |
192 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner()); | 206 m_mainThread->postTask(new MainThreadPendingHighPriorityTaskRunner()); |
193 m_highPriorityTaskRunnerPosted = true; | 207 m_highPriorityTaskRunnerPosted = true; |
194 } | 208 } |
195 | 209 |
196 void Scheduler::postIdleTask(const TraceLocation& location, const IdleTask& idle Task) | 210 bool Scheduler::maybePostMainThreadPendingIdleTask() |
197 { | 211 { |
198 scheduleIdleTask(location, idleTask); | 212 ASSERT(isMainThread()); |
213 TRACE_EVENT0("blink", "Scheduler::maybePostMainThreadPendingIdleTask"); | |
214 if (canRunIdleTask()) { | |
215 Locker<Mutex> lock(m_pendingTasksMutex); | |
216 if (!m_pendingIdleTasks.isEmpty()) { | |
217 m_mainThread->postTask(new MainThreadPendingIdleTaskRunner()); | |
218 return true; | |
219 } | |
220 } | |
221 return false; | |
199 } | 222 } |
200 | 223 |
201 void Scheduler::tickSharedTimer() | 224 void Scheduler::tickSharedTimer() |
202 { | 225 { |
203 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); | 226 TRACE_EVENT0("blink", "Scheduler::tickSharedTimer"); |
204 | 227 |
205 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately. | 228 // Run any high priority tasks that are queued up, otherwise the blink timer s will yield immediately. |
206 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority(); | 229 bool workDone = runPendingHighPriorityTasksIfInCompositorPriority(); |
207 m_sharedTimerFunction(); | 230 m_sharedTimerFunction(); |
208 | 231 |
209 // The blink timers may have just yielded, so run any high priority tasks th at where queued up | 232 // The blink timers may have just yielded, so run any high priority tasks th at where queued up |
210 // while the blink timers were executing. | 233 // while the blink timers were executing. |
211 if (!workDone) | 234 if (!workDone) |
212 runPendingHighPriorityTasksIfInCompositorPriority(); | 235 runPendingHighPriorityTasksIfInCompositorPriority(); |
213 } | 236 } |
214 | 237 |
215 bool Scheduler::runPendingHighPriorityTasksIfInCompositorPriority() | 238 bool Scheduler::runPendingHighPriorityTasksIfInCompositorPriority() |
216 { | 239 { |
217 ASSERT(isMainThread()); | 240 ASSERT(isMainThread()); |
218 if (schedulerPolicy() != CompositorPriority) | 241 if (schedulerPolicy() != CompositorPriority) |
219 return false; | 242 return false; |
220 | 243 |
221 return swapQueuesAndRunPendingTasks(); | 244 return swapQueuesAndRunPendingTasks(); |
222 } | 245 } |
223 | 246 |
247 bool Scheduler::maybeRunPendingIdleTask() | |
248 { | |
249 ASSERT(isMainThread()); | |
250 if (!canRunIdleTask()) | |
251 return false; | |
252 | |
253 takeFirstPendingIdleTask().run(); | |
254 return true; | |
255 } | |
256 | |
257 TracedIdleTask Scheduler::takeFirstPendingIdleTask() | |
258 { | |
259 Locker<Mutex> lock(m_pendingTasksMutex); | |
260 ASSERT(!m_pendingIdleTasks.isEmpty()); | |
261 return m_pendingIdleTasks.takeFirst(); | |
262 } | |
263 | |
224 bool Scheduler::swapQueuesAndRunPendingTasks() | 264 bool Scheduler::swapQueuesAndRunPendingTasks() |
225 { | 265 { |
226 ASSERT(isMainThread()); | 266 ASSERT(isMainThread()); |
227 | 267 |
228 // These locks guard against another thread posting input or compositor task s while we swap the buffers. | 268 // 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. | 269 // One the buffers have been swapped we can safely access the returned deque without having to lock. |
230 m_pendingTasksMutex.lock(); | 270 m_pendingTasksMutex.lock(); |
231 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); | 271 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers(); |
232 maybeEnterNormalSchedulerPolicy(); | 272 maybeEnterNormalSchedulerPolicy(); |
233 m_pendingTasksMutex.unlock(); | 273 m_pendingTasksMutex.unlock(); |
234 return executeHighPriorityTasks(highPriorityTasks); | 274 return executeHighPriorityTasks(highPriorityTasks); |
235 } | 275 } |
236 | 276 |
237 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting() | 277 void Scheduler::swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting() |
238 { | 278 { |
239 ASSERT(isMainThread()); | 279 ASSERT(isMainThread()); |
240 | 280 |
241 // These locks guard against another thread posting input or compositor task s while we swap the buffers. | 281 // 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. | 282 // One the buffers have been swapped we can safely access the returned deque without having to lock. |
243 m_pendingTasksMutex.lock(); | 283 m_pendingTasksMutex.lock(); |
244 Deque<TracedTask>& highPriorityTasks = m_pendingHighPriorityTasks.swapBuffer s(); | 284 Deque<TracedStandardTask>& highPriorityTasks = m_pendingHighPriorityTasks.sw apBuffers(); |
245 m_highPriorityTaskRunnerPosted = false; | 285 m_highPriorityTaskRunnerPosted = false; |
246 maybeEnterNormalSchedulerPolicy(); | 286 maybeEnterNormalSchedulerPolicy(); |
247 m_pendingTasksMutex.unlock(); | 287 m_pendingTasksMutex.unlock(); |
248 executeHighPriorityTasks(highPriorityTasks); | 288 executeHighPriorityTasks(highPriorityTasks); |
249 } | 289 } |
250 | 290 |
251 void Scheduler::maybeEnterNormalSchedulerPolicy() | 291 void Scheduler::maybeEnterNormalSchedulerPolicy() |
252 { | 292 { |
253 ASSERT(isMainThread()); | 293 ASSERT(isMainThread()); |
254 ASSERT(m_pendingTasksMutex.locked()); | 294 ASSERT(m_pendingTasksMutex.locked()); |
255 | 295 |
256 // Go back to the normal scheduler policy if enough time has elapsed. | 296 // Go back to the normal scheduler policy if enough time has elapsed. |
257 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds) | 297 if (schedulerPolicy() == CompositorPriority && Platform::current()->monotoni callyIncreasingTime() > m_compositorPriorityPolicyEndTimeSeconds) |
258 enterSchedulerPolicyLocked(Normal); | 298 enterSchedulerPolicyLocked(Normal); |
259 } | 299 } |
260 | 300 |
261 bool Scheduler::executeHighPriorityTasks(Deque<TracedTask>& highPriorityTasks) | 301 bool Scheduler::executeHighPriorityTasks(Deque<TracedStandardTask>& highPriority Tasks) |
262 { | 302 { |
263 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks"); | 303 TRACE_EVENT0("blink", "Scheduler::executeHighPriorityTasks"); |
264 int highPriorityTasksExecuted = 0; | 304 int highPriorityTasksExecuted = 0; |
265 while (!highPriorityTasks.isEmpty()) { | 305 while (!highPriorityTasks.isEmpty()) { |
266 highPriorityTasks.takeFirst().run(); | 306 highPriorityTasks.takeFirst().run(); |
267 highPriorityTasksExecuted++; | 307 highPriorityTasksExecuted++; |
268 } | 308 } |
269 | 309 |
270 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted); | 310 int highPriorityTaskCount = atomicSubtract(&m_highPriorityTaskCount, highPri orityTasksExecuted); |
271 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0); | 311 ASSERT_UNUSED(highPriorityTaskCount, highPriorityTaskCount >= 0); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 bool Scheduler::hasPendingHighPriorityWork() const | 346 bool Scheduler::hasPendingHighPriorityWork() const |
307 { | 347 { |
308 // This method is expected to be run on the main thread, but the high priori ty tasks will be posted by | 348 // 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 | 349 // 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 | 350 // ThreadTimers::sharedTimerFiredInternal so we decided to use atomics + bar rier loads here which |
311 // should be cheaper. | 351 // should be cheaper. |
312 // NOTE it's possible the barrier read is overkill here, since delayed yield ing isn't a big deal. | 352 // 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; | 353 return acquireLoad(&m_highPriorityTaskCount) != 0; |
314 } | 354 } |
315 | 355 |
356 double Scheduler::currentFrameDeadlineForIdleTasks() const | |
357 { | |
358 ASSERT(isMainThread()); | |
359 // TODO: Make idle time more fine-grain chunks when in Compositor priority. | |
360 return m_currentFrameDeadlineSeconds; | |
361 } | |
362 | |
363 bool Scheduler::canRunIdleTask() const | |
364 { | |
365 ASSERT(isMainThread()); | |
366 return m_currentFrameCommitted && (m_currentFrameDeadlineSeconds > Platform: :current()->monotonicallyIncreasingTime()); | |
Sami
2014/10/06 09:48:30
To jochen's point, should we be checking !shouldYi
rmcilroy
2014/10/06 11:29:42
Done.
| |
367 } | |
368 | |
316 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const | 369 Scheduler::SchedulerPolicy Scheduler::schedulerPolicy() const |
317 { | 370 { |
318 ASSERT(isMainThread()); | 371 ASSERT(isMainThread()); |
319 // It's important not to miss the transition from normal to low latency mode , otherwise we're likely to | 372 // 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 | 373 // 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. | 374 // need either a lock or a memory barrier, and the memory barrier is probabl y cheaper. |
322 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy)); | 375 return static_cast<SchedulerPolicy>(acquireLoad(&m_schedulerPolicy)); |
323 } | 376 } |
324 | 377 |
325 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy) | 378 void Scheduler::enterSchedulerPolicy(SchedulerPolicy schedulerPolicy) |
326 { | 379 { |
327 Locker<Mutex> lock(m_pendingTasksMutex); | 380 Locker<Mutex> lock(m_pendingTasksMutex); |
328 enterSchedulerPolicyLocked(schedulerPolicy); | 381 enterSchedulerPolicyLocked(schedulerPolicy); |
329 } | 382 } |
330 | 383 |
331 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy) | 384 void Scheduler::enterSchedulerPolicyLocked(SchedulerPolicy schedulerPolicy) |
332 { | 385 { |
333 ASSERT(m_pendingTasksMutex.locked()); | 386 ASSERT(m_pendingTasksMutex.locked()); |
334 if (schedulerPolicy == CompositorPriority) | 387 if (schedulerPolicy == CompositorPriority) |
335 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds; | 388 m_compositorPriorityPolicyEndTimeSeconds = Platform::current()->monotoni callyIncreasingTime() + kLowSchedulerPolicyAfterTouchTimeSeconds; |
336 | 389 |
337 releaseStore(&m_schedulerPolicy, schedulerPolicy); | 390 releaseStore(&m_schedulerPolicy, schedulerPolicy); |
338 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy); | 391 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("blink.scheduler"), "SchedulerPolic y", schedulerPolicy); |
339 } | 392 } |
340 | 393 |
341 } // namespace blink | 394 } // namespace blink |
OLD | NEW |