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/throttling_helper.h" | 5 #include "platform/scheduler/renderer/throttling_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "platform/scheduler/base/real_time_domain.h" | 8 #include "platform/scheduler/base/real_time_domain.h" |
9 #include "platform/scheduler/child/scheduler_tqm_delegate.h" | 9 #include "platform/scheduler/child/scheduler_tqm_delegate.h" |
10 #include "platform/scheduler/renderer/auto_advancing_virtual_time_domain.h" | 10 #include "platform/scheduler/renderer/auto_advancing_virtual_time_domain.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 renderer_scheduler_->RegisterTimeDomain(time_domain_.get()); | 34 renderer_scheduler_->RegisterTimeDomain(time_domain_.get()); |
35 } | 35 } |
36 | 36 |
37 ThrottlingHelper::~ThrottlingHelper() { | 37 ThrottlingHelper::~ThrottlingHelper() { |
38 // It's possible for queues to be still throttled, so we need to tidy up | 38 // It's possible for queues to be still throttled, so we need to tidy up |
39 // before unregistering the time domain. | 39 // before unregistering the time domain. |
40 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { | 40 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { |
41 TaskQueue* task_queue = map_entry.first; | 41 TaskQueue* task_queue = map_entry.first; |
42 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); | 42 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); |
43 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::AUTO); | 43 task_queue->RemoveFence(); |
44 } | 44 } |
45 | 45 |
46 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); | 46 renderer_scheduler_->UnregisterTimeDomain(time_domain_.get()); |
47 } | 47 } |
48 | 48 |
49 void ThrottlingHelper::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { | 49 void ThrottlingHelper::SetQueueEnabled(TaskQueue* task_queue, bool enabled) { |
50 TaskQueueMap::iterator find_it = throttled_queues_.find(task_queue); | 50 TaskQueueMap::iterator find_it = throttled_queues_.find(task_queue); |
51 | 51 |
52 if (find_it == throttled_queues_.end()) { | 52 if (find_it == throttled_queues_.end()) { |
53 task_queue->SetQueueEnabled(enabled); | 53 task_queue->SetQueueEnabled(enabled); |
(...skipping 15 matching lines...) Expand all Loading... |
69 if (virtual_time_) | 69 if (virtual_time_) |
70 return; | 70 return; |
71 | 71 |
72 std::pair<TaskQueueMap::iterator, bool> insert_result = | 72 std::pair<TaskQueueMap::iterator, bool> insert_result = |
73 throttled_queues_.insert(std::make_pair( | 73 throttled_queues_.insert(std::make_pair( |
74 task_queue, Metadata(1, task_queue->IsQueueEnabled()))); | 74 task_queue, Metadata(1, task_queue->IsQueueEnabled()))); |
75 | 75 |
76 if (insert_result.second) { | 76 if (insert_result.second) { |
77 // The insert was succesful so we need to throttle the queue. | 77 // The insert was succesful so we need to throttle the queue. |
78 task_queue->SetTimeDomain(time_domain_.get()); | 78 task_queue->SetTimeDomain(time_domain_.get()); |
79 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::MANUAL); | 79 task_queue->RemoveFence(); |
80 task_queue->SetQueueEnabled(false); | 80 task_queue->SetQueueEnabled(false); |
81 | 81 |
82 if (!task_queue->IsEmpty()) { | 82 if (!task_queue->IsEmpty()) { |
83 if (task_queue->HasPendingImmediateWork()) { | 83 if (task_queue->HasPendingImmediateWork()) { |
84 OnTimeDomainHasImmediateWork(); | 84 OnTimeDomainHasImmediateWork(); |
85 } else { | 85 } else { |
86 OnTimeDomainHasDelayedWork(); | 86 OnTimeDomainHasDelayedWork(); |
87 } | 87 } |
88 } | 88 } |
89 } else { | 89 } else { |
90 // An entry already existed in the map so we need to increment the refcount. | 90 // An entry already existed in the map so we need to increment the refcount. |
91 insert_result.first->second.throttling_ref_count++; | 91 insert_result.first->second.throttling_ref_count++; |
92 } | 92 } |
93 } | 93 } |
94 | 94 |
95 void ThrottlingHelper::DecreaseThrottleRefCount(TaskQueue* task_queue) { | 95 void ThrottlingHelper::DecreaseThrottleRefCount(TaskQueue* task_queue) { |
96 if (virtual_time_) | 96 if (virtual_time_) |
97 return; | 97 return; |
98 | 98 |
99 TaskQueueMap::iterator iter = throttled_queues_.find(task_queue); | 99 TaskQueueMap::iterator iter = throttled_queues_.find(task_queue); |
100 | 100 |
101 if (iter != throttled_queues_.end() && | 101 if (iter != throttled_queues_.end() && |
102 --iter->second.throttling_ref_count == 0) { | 102 --iter->second.throttling_ref_count == 0) { |
103 bool enabled = iter->second.enabled; | 103 bool enabled = iter->second.enabled; |
104 // The refcount has become zero, we need to unthrottle the queue. | 104 // The refcount has become zero, we need to unthrottle the queue. |
105 throttled_queues_.erase(iter); | 105 throttled_queues_.erase(iter); |
106 | 106 |
107 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); | 107 task_queue->SetTimeDomain(renderer_scheduler_->real_time_domain()); |
108 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::AUTO); | 108 task_queue->RemoveFence(); |
109 task_queue->SetQueueEnabled(enabled); | 109 task_queue->SetQueueEnabled(enabled); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
| 113 bool ThrottlingHelper::IsThrottled(TaskQueue* task_queue) const { |
| 114 return throttled_queues_.find(task_queue) != throttled_queues_.end(); |
| 115 } |
| 116 |
113 void ThrottlingHelper::UnregisterTaskQueue(TaskQueue* task_queue) { | 117 void ThrottlingHelper::UnregisterTaskQueue(TaskQueue* task_queue) { |
114 throttled_queues_.erase(task_queue); | 118 throttled_queues_.erase(task_queue); |
115 } | 119 } |
116 | 120 |
117 void ThrottlingHelper::OnTimeDomainHasImmediateWork() { | 121 void ThrottlingHelper::OnTimeDomainHasImmediateWork() { |
118 // Forward to the main thread if called from another thread. | 122 // Forward to the main thread if called from another thread. |
119 if (!task_runner_->RunsTasksOnCurrentThread()) { | 123 if (!task_runner_->RunsTasksOnCurrentThread()) { |
120 task_runner_->PostTask(FROM_HERE, forward_immediate_work_closure_); | 124 task_runner_->PostTask(FROM_HERE, forward_immediate_work_closure_); |
121 return; | 125 return; |
122 } | 126 } |
(...skipping 15 matching lines...) Expand all Loading... |
138 next_scheduled_delayed_task); | 142 next_scheduled_delayed_task); |
139 } | 143 } |
140 | 144 |
141 void ThrottlingHelper::PumpThrottledTasks() { | 145 void ThrottlingHelper::PumpThrottledTasks() { |
142 TRACE_EVENT0(tracing_category_, "ThrottlingHelper::PumpThrottledTasks"); | 146 TRACE_EVENT0(tracing_category_, "ThrottlingHelper::PumpThrottledTasks"); |
143 pending_pump_throttled_tasks_runtime_ = base::TimeTicks(); | 147 pending_pump_throttled_tasks_runtime_ = base::TimeTicks(); |
144 | 148 |
145 LazyNow lazy_low(tick_clock_); | 149 LazyNow lazy_low(tick_clock_); |
146 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { | 150 for (const TaskQueueMap::value_type& map_entry : throttled_queues_) { |
147 TaskQueue* task_queue = map_entry.first; | 151 TaskQueue* task_queue = map_entry.first; |
148 if (task_queue->IsEmpty()) | 152 if (!map_entry.second.enabled || task_queue->IsEmpty()) |
149 continue; | 153 continue; |
150 | 154 |
151 task_queue->SetQueueEnabled(map_entry.second.enabled); | 155 task_queue->SetQueueEnabled(true); |
152 task_queue->PumpQueue(&lazy_low, false); | 156 task_queue->InsertFence(); |
153 } | 157 } |
154 // Make sure NextScheduledRunTime gives us an up-to date result. | 158 // Make sure NextScheduledRunTime gives us an up-to date result. |
155 time_domain_->ClearExpiredWakeups(); | 159 time_domain_->ClearExpiredWakeups(); |
156 | 160 |
157 base::TimeTicks next_scheduled_delayed_task; | 161 base::TimeTicks next_scheduled_delayed_task; |
158 // Maybe schedule a call to ThrottlingHelper::PumpThrottledTasks if there is | 162 // Maybe schedule a call to ThrottlingHelper::PumpThrottledTasks if there is |
159 // a pending delayed task. NOTE posting a non-delayed task in the future will | 163 // a pending delayed task. NOTE posting a non-delayed task in the future will |
160 // result in ThrottlingHelper::OnTimeDomainHasImmediateWork being called. | 164 // result in ThrottlingHelper::OnTimeDomainHasImmediateWork being called. |
161 if (time_domain_->NextScheduledRunTime(&next_scheduled_delayed_task)) { | 165 if (time_domain_->NextScheduledRunTime(&next_scheduled_delayed_task)) { |
162 MaybeSchedulePumpThrottledTasksLocked(FROM_HERE, lazy_low.Now(), | 166 MaybeSchedulePumpThrottledTasksLocked(FROM_HERE, lazy_low.Now(), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 209 |
206 pump_throttled_tasks_closure_.Cancel(); | 210 pump_throttled_tasks_closure_.Cancel(); |
207 | 211 |
208 while (!throttled_queues_.empty()) { | 212 while (!throttled_queues_.empty()) { |
209 TaskQueue* task_queue = throttled_queues_.begin()->first; | 213 TaskQueue* task_queue = throttled_queues_.begin()->first; |
210 bool enabled = throttled_queues_.begin()->second.enabled; | 214 bool enabled = throttled_queues_.begin()->second.enabled; |
211 | 215 |
212 throttled_queues_.erase(throttled_queues_.begin()); | 216 throttled_queues_.erase(throttled_queues_.begin()); |
213 | 217 |
214 task_queue->SetTimeDomain(renderer_scheduler_->GetVirtualTimeDomain()); | 218 task_queue->SetTimeDomain(renderer_scheduler_->GetVirtualTimeDomain()); |
215 task_queue->SetPumpPolicy(TaskQueue::PumpPolicy::AUTO); | 219 task_queue->RemoveFence(); |
216 task_queue->SetQueueEnabled(enabled); | 220 task_queue->SetQueueEnabled(enabled); |
217 } | 221 } |
218 } | 222 } |
219 | 223 |
220 } // namespace scheduler | 224 } // namespace scheduler |
221 } // namespace blink | 225 } // namespace blink |
OLD | NEW |