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 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL ER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL ER_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL ER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL ER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 namespace blink { | 26 namespace blink { |
27 namespace scheduler { | 27 namespace scheduler { |
28 | 28 |
29 class BudgetPool; | 29 class BudgetPool; |
30 class RendererSchedulerImpl; | 30 class RendererSchedulerImpl; |
31 class ThrottledTimeDomain; | 31 class ThrottledTimeDomain; |
32 class CPUTimeBudgetPool; | 32 class CPUTimeBudgetPool; |
33 class WakeupBudgetPool; | |
34 | |
35 enum class QueueBlockType { FULL, NEW_TASKS_ONLY }; | |
alex clarke (OOO till 29th)
2017/04/21 09:14:19
These could do with some more documentation. I w
alex clarke (OOO till 29th)
2017/04/21 09:14:19
Are you thinking of adding more blocking types? C
altimin
2017/04/25 13:22:36
ALL_TASKS is a good idea, done.
I hoped that it w
| |
33 | 36 |
34 // Interface for BudgetPool to interact with TaskQueueThrottler. | 37 // Interface for BudgetPool to interact with TaskQueueThrottler. |
35 class BLINK_PLATFORM_EXPORT BudgetPoolController { | 38 class BLINK_PLATFORM_EXPORT BudgetPoolController { |
36 public: | 39 public: |
37 virtual ~BudgetPoolController() {} | 40 virtual ~BudgetPoolController() {} |
38 | 41 |
39 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue | 42 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue |
40 // methods instead. | 43 // methods instead. |
41 virtual void AddQueueToBudgetPool(TaskQueue* queue, | 44 virtual void AddQueueToBudgetPool(TaskQueue* queue, |
42 BudgetPool* budget_pool) = 0; | 45 BudgetPool* budget_pool) = 0; |
43 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue, | 46 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue, |
44 BudgetPool* budget_pool) = 0; | 47 BudgetPool* budget_pool) = 0; |
45 | 48 |
46 // Deletes the budget pool. | 49 // Deletes the budget pool. |
47 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0; | 50 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0; |
48 | 51 |
49 // Insert a fence to prevent tasks from running and schedule a wake-up at | 52 // Insert a fence to prevent tasks from running and schedule a wake-up at |
50 // an appropriate time. | 53 // an appropriate time. |
51 virtual void BlockQueue(base::TimeTicks now, TaskQueue* queue) = 0; | 54 virtual void BlockQueue(QueueBlockType block_type, |
55 base::TimeTicks now, | |
56 TaskQueue* queue) = 0; | |
52 | 57 |
53 // Schedule a call to unblock queue at an appropriate moment. | 58 // Schedule a call to unblock queue at an appropriate moment. |
54 virtual void UnblockQueue(base::TimeTicks now, TaskQueue* queue) = 0; | 59 virtual void UnblockQueue(base::TimeTicks now, TaskQueue* queue) = 0; |
55 | 60 |
56 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler | 61 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler |
57 // and throttling is not disabled). | 62 // and throttling is not disabled). |
58 virtual bool IsThrottled(TaskQueue* queue) const = 0; | 63 virtual bool IsThrottled(TaskQueue* queue) const = 0; |
59 }; | 64 }; |
60 | 65 |
61 // The job of the TaskQueueThrottler is to control when tasks posted on | 66 // The job of the TaskQueueThrottler is to control when tasks posted on |
(...skipping 30 matching lines...) Expand all Loading... | |
92 | 97 |
93 // TaskQueue::Observer implementation: | 98 // TaskQueue::Observer implementation: |
94 void OnQueueNextWakeUpChanged(TaskQueue* queue, | 99 void OnQueueNextWakeUpChanged(TaskQueue* queue, |
95 base::TimeTicks wake_up) override; | 100 base::TimeTicks wake_up) override; |
96 | 101 |
97 // BudgetPoolController implementation: | 102 // BudgetPoolController implementation: |
98 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; | 103 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; |
99 void RemoveQueueFromBudgetPool(TaskQueue* queue, | 104 void RemoveQueueFromBudgetPool(TaskQueue* queue, |
100 BudgetPool* budget_pool) override; | 105 BudgetPool* budget_pool) override; |
101 void UnregisterBudgetPool(BudgetPool* budget_pool) override; | 106 void UnregisterBudgetPool(BudgetPool* budget_pool) override; |
102 void BlockQueue(base::TimeTicks now, TaskQueue* queue) override; | 107 void BlockQueue(QueueBlockType block_type, |
108 base::TimeTicks now, | |
109 TaskQueue* queue) override; | |
103 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; | 110 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; |
104 bool IsThrottled(TaskQueue* queue) const override; | 111 bool IsThrottled(TaskQueue* queue) const override; |
105 | 112 |
106 // Increments the throttled refcount and causes |task_queue| to be throttled | 113 // Increments the throttled refcount and causes |task_queue| to be throttled |
107 // if its not already throttled. | 114 // if its not already throttled. |
108 void IncreaseThrottleRefCount(TaskQueue* task_queue); | 115 void IncreaseThrottleRefCount(TaskQueue* task_queue); |
109 | 116 |
110 // If the refcouint is non-zero it's decremented. If the throttled refcount | 117 // If the refcouint is non-zero it's decremented. If the throttled refcount |
111 // becomes zero then |task_queue| is unthrottled. If the refcount was already | 118 // becomes zero then |task_queue| is unthrottled. If the refcount was already |
112 // zero this function does nothing. | 119 // zero this function does nothing. |
(...skipping 12 matching lines...) Expand all Loading... | |
125 | 132 |
126 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } | 133 const ThrottledTimeDomain* time_domain() const { return time_domain_.get(); } |
127 | 134 |
128 static base::TimeTicks AlignedThrottledRunTime( | 135 static base::TimeTicks AlignedThrottledRunTime( |
129 base::TimeTicks unthrottled_runtime); | 136 base::TimeTicks unthrottled_runtime); |
130 | 137 |
131 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } | 138 const scoped_refptr<TaskQueue>& task_runner() const { return task_runner_; } |
132 | 139 |
133 // Returned object is owned by |TaskQueueThrottler|. | 140 // Returned object is owned by |TaskQueueThrottler|. |
134 CPUTimeBudgetPool* CreateCPUTimeBudgetPool(const char* name); | 141 CPUTimeBudgetPool* CreateCPUTimeBudgetPool(const char* name); |
142 WakeupBudgetPool* CreateWakeupBudgetPool(const char* name); | |
135 | 143 |
136 // Accounts for given task for cpu-based throttling needs. | 144 // Accounts for given task for cpu-based throttling needs. |
137 void OnTaskRunTimeReported(TaskQueue* task_queue, | 145 void OnTaskRunTimeReported(TaskQueue* task_queue, |
138 base::TimeTicks start_time, | 146 base::TimeTicks start_time, |
139 base::TimeTicks end_time); | 147 base::TimeTicks end_time); |
140 | 148 |
141 void AsValueInto(base::trace_event::TracedValue* state, | 149 void AsValueInto(base::trace_event::TracedValue* state, |
142 base::TimeTicks now) const; | 150 base::TimeTicks now) const; |
143 private: | 151 private: |
144 struct Metadata { | 152 struct Metadata { |
(...skipping 10 matching lines...) Expand all Loading... | |
155 // Note |unthrottled_runtime| might be in the past. When this happens we | 163 // Note |unthrottled_runtime| might be in the past. When this happens we |
156 // compute the delay to the next runtime based on now rather than | 164 // compute the delay to the next runtime based on now rather than |
157 // unthrottled_runtime. | 165 // unthrottled_runtime. |
158 void MaybeSchedulePumpThrottledTasks( | 166 void MaybeSchedulePumpThrottledTasks( |
159 const tracked_objects::Location& from_here, | 167 const tracked_objects::Location& from_here, |
160 base::TimeTicks now, | 168 base::TimeTicks now, |
161 base::TimeTicks runtime); | 169 base::TimeTicks runtime); |
162 | 170 |
163 // Return next possible time when queue is allowed to run in accordance | 171 // Return next possible time when queue is allowed to run in accordance |
164 // with throttling policy. | 172 // with throttling policy. |
165 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue); | 173 base::TimeTicks GetNextAllowedRunTime(TaskQueue* queue, |
174 base::TimeTicks now, | |
175 base::TimeTicks desired_run_time); | |
176 | |
177 bool CanRunTasksAt(TaskQueue* queue, base::TimeTicks moment); | |
178 | |
179 bool CanRunTasksUntil(TaskQueue* queue, | |
180 base::TimeTicks now, | |
181 base::TimeTicks moment); | |
166 | 182 |
167 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); | 183 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); |
168 | 184 |
169 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. | 185 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. |
170 void SchedulePumpQueue(const tracked_objects::Location& from_here, | 186 void SchedulePumpQueue(const tracked_objects::Location& from_here, |
171 base::TimeTicks now, | 187 base::TimeTicks now, |
172 TaskQueue* queue); | 188 TaskQueue* queue); |
173 | 189 |
190 void OnTaskQueueHasWork(TaskQueue* queue, | |
191 base::TimeTicks now, | |
192 base::TimeTicks next_task_run_time); | |
193 | |
174 TaskQueueMap queue_details_; | 194 TaskQueueMap queue_details_; |
175 base::Callback<void(TaskQueue*, base::TimeTicks)> | 195 base::Callback<void(TaskQueue*, base::TimeTicks)> |
176 forward_immediate_work_callback_; | 196 forward_immediate_work_callback_; |
177 scoped_refptr<TaskQueue> task_runner_; | 197 scoped_refptr<TaskQueue> task_runner_; |
178 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 198 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
179 base::TickClock* tick_clock_; // NOT OWNED | 199 base::TickClock* tick_clock_; // NOT OWNED |
180 const char* tracing_category_; // NOT OWNED | 200 const char* tracing_category_; // NOT OWNED |
181 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 201 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
182 | 202 |
183 CancelableClosureHolder pump_throttled_tasks_closure_; | 203 CancelableClosureHolder pump_throttled_tasks_closure_; |
184 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; | 204 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
185 bool allow_throttling_; | 205 bool allow_throttling_; |
186 | 206 |
187 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; | 207 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; |
188 | 208 |
189 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; | 209 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
190 | 210 |
191 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); | 211 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); |
192 }; | 212 }; |
193 | 213 |
194 } // namespace scheduler | 214 } // namespace scheduler |
195 } // namespace blink | 215 } // namespace blink |
196 | 216 |
197 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_ | 217 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_ |
OLD | NEW |