Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scheduler/renderer/task_queue_throttler.h" | 5 #include "platform/scheduler/renderer/task_queue_throttler.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 TaskQueue* task_queue = map_entry.first; | 308 TaskQueue* task_queue = map_entry.first; |
| 309 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); | 309 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); |
| 310 task_queue->RemoveFence(); | 310 task_queue->RemoveFence(); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); | 314 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { | 317 void TaskQueueThrottler::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { |
| 318 // Both the TaskQueueThrottler and other systems want to enable and disable | |
| 319 // task queues. The policy we've adopted to deal with this is: | |
| 320 // | |
| 321 // A task queue is disabled if either the TaskQueueThrottler or the caller | |
| 322 // vote to disable it. | |
| 323 // | |
| 324 // A task queue is enabled only if both the TaskQueueThrottler and the caller | |
| 325 // vote to enable it. | |
| 318 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); | 326 TaskQueueMap::iterator find_it = queue_details_.find(task_queue); |
| 319 | 327 |
| 328 // If TaskQueueThrottler does not know about this queue, just call | |
| 329 // SetQueueEnabled directly. | |
| 320 if (find_it == queue_details_.end()) { | 330 if (find_it == queue_details_.end()) { |
| 321 task_queue->SetQueueEnabled(enabled); | 331 task_queue->SetQueueEnabled(enabled); |
| 322 return; | 332 return; |
| 323 } | 333 } |
| 324 | 334 |
| 335 // Remember the caller's preference so we know what to do when the task queue | |
| 336 // isn't throttled, or has budget to run. | |
| 325 find_it->second.enabled = enabled; | 337 find_it->second.enabled = enabled; |
| 326 | 338 |
| 339 // If this queue is not throttled by task queue throttler, just call | |
| 340 // SetQueueEnabled directly. | |
| 327 if (!find_it->second.IsThrottled()) { | 341 if (!find_it->second.IsThrottled()) { |
|
Sami
2016/11/24 16:05:49
I think this needs a rebase; IsThrottled() isn't t
altimin
2016/11/24 16:09:36
It does indeed, thanks.
| |
| 328 task_queue->SetQueueEnabled(enabled); | 342 task_queue->SetQueueEnabled(enabled); |
| 329 return; | 343 return; |
| 330 } | 344 } |
| 331 | 345 |
| 332 // We don't enable the queue here because it's throttled and there might be | 346 if (enabled) { |
| 333 // tasks in it's work queue that would execute immediatly rather than after | 347 // If the task queue is throttled and we want to enable it, we can't |
| 334 // PumpThrottledTasks runs. | 348 // do it immediately due to task alignment requirement and we should |
| 335 if (!enabled) { | 349 // schedule a call to PumpThrottledTasks. |
| 336 task_queue->SetQueueEnabled(false); | |
| 337 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, | 350 MaybeSchedulePumpQueue(FROM_HERE, tick_clock_->NowTicks(), task_queue, |
| 338 base::nullopt); | 351 base::nullopt); |
| 352 } else { | |
| 353 task_queue->SetQueueEnabled(false); | |
| 339 } | 354 } |
| 340 } | 355 } |
| 341 | 356 |
| 342 void TaskQueueThrottler::IncreaseThrottleRefCount(TaskQueue* task_queue) { | 357 void TaskQueueThrottler::IncreaseThrottleRefCount(TaskQueue* task_queue) { |
| 343 DCHECK_NE(task_queue, task_runner_.get()); | 358 DCHECK_NE(task_queue, task_runner_.get()); |
| 344 | 359 |
| 345 std::pair<TaskQueueMap::iterator, bool> insert_result = | 360 std::pair<TaskQueueMap::iterator, bool> insert_result = |
| 346 queue_details_.insert(std::make_pair(task_queue, Metadata())); | 361 queue_details_.insert(std::make_pair(task_queue, Metadata())); |
| 347 | 362 |
| 348 if (!insert_result.first->second.IsThrottled()) { | 363 if (!insert_result.first->second.IsThrottled()) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 queue->SetTimeDomain(time_domain_.get()); | 677 queue->SetTimeDomain(time_domain_.get()); |
| 663 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, | 678 MaybeSchedulePumpQueue(FROM_HERE, lazy_now.Now(), queue, |
| 664 GetNextAllowedRunTime(lazy_now.Now(), queue)); | 679 GetNextAllowedRunTime(lazy_now.Now(), queue)); |
| 665 } | 680 } |
| 666 | 681 |
| 667 TRACE_EVENT0(tracing_category_, "TaskQueueThrottler_EnableThrottling"); | 682 TRACE_EVENT0(tracing_category_, "TaskQueueThrottler_EnableThrottling"); |
| 668 } | 683 } |
| 669 | 684 |
| 670 } // namespace scheduler | 685 } // namespace scheduler |
| 671 } // namespace blink | 686 } // namespace blink |
| OLD | NEW |