| 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 "components/scheduler/renderer/throttling_helper.h" | 5 #include "components/scheduler/renderer/throttling_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/scheduler/base/real_time_domain.h" | 8 #include "components/scheduler/base/real_time_domain.h" |
| 9 #include "components/scheduler/child/scheduler_tqm_delegate.h" | 9 #include "components/scheduler/child/scheduler_tqm_delegate.h" |
| 10 #include "components/scheduler/renderer/renderer_scheduler_impl.h" | 10 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 void ThrottlingHelper::IncreaseThrottleRefCount(TaskQueue* task_queue) { | 46 void ThrottlingHelper::IncreaseThrottleRefCount(TaskQueue* task_queue) { |
| 47 DCHECK_NE(task_queue, task_runner_.get()); | 47 DCHECK_NE(task_queue, task_runner_.get()); |
| 48 | 48 |
| 49 std::pair<TaskQueueMap::iterator, bool> insert_result = | 49 std::pair<TaskQueueMap::iterator, bool> insert_result = |
| 50 throttled_queues_.insert(std::make_pair(task_queue, 1)); | 50 throttled_queues_.insert(std::make_pair(task_queue, 1)); |
| 51 | 51 |
| 52 if (insert_result.second) { | 52 if (insert_result.second) { |
| 53 // The insert was succesful so we need to throttle the queue. | 53 // The insert was succesful so we need to throttle the queue. |
| 54 task_queue->SetTimeDomain(time_domain_.get()); | 54 task_queue->SetTimeDomain(time_domain_.get()); |
| 55 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::MANUAL); | 55 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::MANUAL); |
| 56 task_queue->SetQueueEnabled(false); |
| 56 | 57 |
| 57 if (!task_queue->IsEmpty()) { | 58 if (!task_queue->IsEmpty()) { |
| 58 if (task_queue->HasPendingImmediateWork()) { | 59 if (task_queue->HasPendingImmediateWork()) { |
| 59 OnTimeDomainHasImmediateWork(); | 60 OnTimeDomainHasImmediateWork(); |
| 60 } else { | 61 } else { |
| 61 OnTimeDomainHasDelayedWork(); | 62 OnTimeDomainHasDelayedWork(); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 } else { | 65 } else { |
| 65 // An entry already existed in the map so we need to increment the refcount. | 66 // An entry already existed in the map so we need to increment the refcount. |
| 66 insert_result.first->second++; | 67 insert_result.first->second++; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ThrottlingHelper::DecreaseThrottleRefCount(TaskQueue* task_queue) { | 71 void ThrottlingHelper::DecreaseThrottleRefCount(TaskQueue* task_queue) { |
| 71 TaskQueueMap::iterator iter = throttled_queues_.find(task_queue); | 72 TaskQueueMap::iterator iter = throttled_queues_.find(task_queue); |
| 72 | 73 |
| 73 if (iter != throttled_queues_.end() && --iter->second == 0) { | 74 if (iter != throttled_queues_.end() && --iter->second == 0) { |
| 74 // The refcount has become zero, we need to unthrottle the queue. | 75 // The refcount has become zero, we need to unthrottle the queue. |
| 75 throttled_queues_.erase(iter); | 76 throttled_queues_.erase(iter); |
| 76 | 77 |
| 77 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); | 78 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); |
| 78 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::AUTO); | 79 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::AUTO); |
| 80 task_queue->SetQueueEnabled(true); |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 | 83 |
| 82 void ThrottlingHelper::UnregisterTaskQueue(TaskQueue* task_queue) { | 84 void ThrottlingHelper::UnregisterTaskQueue(TaskQueue* task_queue) { |
| 83 throttled_queues_.erase(task_queue); | 85 throttled_queues_.erase(task_queue); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ThrottlingHelper::OnTimeDomainHasImmediateWork() { | 88 void ThrottlingHelper::OnTimeDomainHasImmediateWork() { |
| 87 // Forward to the main thread if called from another thread. | 89 // Forward to the main thread if called from another thread. |
| 88 if (!task_runner_->RunsTasksOnCurrentThread()) { | 90 if (!task_runner_->RunsTasksOnCurrentThread()) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 111 TRACE_EVENT0(tracing_category_, "ThrottlingHelper::PumpThrottledTasks"); | 113 TRACE_EVENT0(tracing_category_, "ThrottlingHelper::PumpThrottledTasks"); |
| 112 pending_pump_throttled_tasks_runtime_ = base::TimeTicks(); | 114 pending_pump_throttled_tasks_runtime_ = base::TimeTicks(); |
| 113 | 115 |
| 114 base::TimeTicks now = tick_clock_->NowTicks(); | 116 base::TimeTicks now = tick_clock_->NowTicks(); |
| 115 time_domain_->AdvanceTo(now); | 117 time_domain_->AdvanceTo(now); |
| 116 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { | 118 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { |
| 117 TaskQueue* task_queue = map_entry.first; | 119 TaskQueue* task_queue = map_entry.first; |
| 118 if (task_queue->IsEmpty()) | 120 if (task_queue->IsEmpty()) |
| 119 continue; | 121 continue; |
| 120 | 122 |
| 123 task_queue->SetQueueEnabled(true); |
| 121 task_queue->PumpQueue(false); | 124 task_queue->PumpQueue(false); |
| 122 } | 125 } |
| 123 // Make sure NextScheduledRunTime gives us an up-to date result. | 126 // Make sure NextScheduledRunTime gives us an up-to date result. |
| 124 time_domain_->ClearExpiredWakeups(); | 127 time_domain_->ClearExpiredWakeups(); |
| 125 | 128 |
| 126 base::TimeTicks next_scheduled_delayed_task; | 129 base::TimeTicks next_scheduled_delayed_task; |
| 127 // Maybe schedule a call to ThrottlingHelper::PumpThrottledTasks if there is | 130 // Maybe schedule a call to ThrottlingHelper::PumpThrottledTasks if there is |
| 128 // a pending delayed task. NOTE posting a non-delayed task in the future will | 131 // a pending delayed task. NOTE posting a non-delayed task in the future will |
| 129 // result in ThrottlingHelper::OnTimeDomainHasImmediateWork being called. | 132 // result in ThrottlingHelper::OnTimeDomainHasImmediateWork being called. |
| 130 if (time_domain_->NextScheduledRunTime(&next_scheduled_delayed_task)) { | 133 if (time_domain_->NextScheduledRunTime(&next_scheduled_delayed_task)) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 160 | 163 |
| 161 base::TimeDelta delay = pending_pump_throttled_tasks_runtime_ - now; | 164 base::TimeDelta delay = pending_pump_throttled_tasks_runtime_ - now; |
| 162 TRACE_EVENT1(tracing_category_, | 165 TRACE_EVENT1(tracing_category_, |
| 163 "ThrottlingHelper::MaybeSchedulePumpThrottledTasksLocked", | 166 "ThrottlingHelper::MaybeSchedulePumpThrottledTasksLocked", |
| 164 "delay_till_next_pump_ms", delay.InMilliseconds()); | 167 "delay_till_next_pump_ms", delay.InMilliseconds()); |
| 165 task_runner_->PostDelayedTask( | 168 task_runner_->PostDelayedTask( |
| 166 from_here, suspend_timers_when_backgrounded_closure_.callback(), delay); | 169 from_here, suspend_timers_when_backgrounded_closure_.callback(), delay); |
| 167 } | 170 } |
| 168 | 171 |
| 169 } // namespace scheduler | 172 } // namespace scheduler |
| OLD | NEW |