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 // kNewTasksOnly prevents new tasks from running (old tasks can run normally), |
| 36 // kAllTasks block queue completely. |
| 37 // kAllTasks-type block always blocks the queue completely. |
| 38 // kNewTasksOnly-type block does nothing when queue is already blocked by |
| 39 // kAllTasks, and overrides previous kNewTasksOnly block if any, which may |
| 40 // unblock some tasks. |
| 41 enum class QueueBlockType { kAllTasks, kNewTasksOnly }; |
33 | 42 |
34 // Interface for BudgetPool to interact with TaskQueueThrottler. | 43 // Interface for BudgetPool to interact with TaskQueueThrottler. |
35 class BLINK_PLATFORM_EXPORT BudgetPoolController { | 44 class BLINK_PLATFORM_EXPORT BudgetPoolController { |
36 public: | 45 public: |
37 virtual ~BudgetPoolController() {} | 46 virtual ~BudgetPoolController() {} |
38 | 47 |
39 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue | 48 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue |
40 // methods instead. | 49 // methods instead. |
41 virtual void AddQueueToBudgetPool(TaskQueue* queue, | 50 virtual void AddQueueToBudgetPool(TaskQueue* queue, |
42 BudgetPool* budget_pool) = 0; | 51 BudgetPool* budget_pool) = 0; |
43 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue, | 52 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue, |
44 BudgetPool* budget_pool) = 0; | 53 BudgetPool* budget_pool) = 0; |
45 | 54 |
46 // Deletes the budget pool. | 55 // Deletes the budget pool. |
47 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0; | 56 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0; |
48 | 57 |
49 // Insert a fence to prevent tasks from running and schedule a wake-up at | 58 // Ensure that an appropriate type of the fence is installed and schedule |
50 // an appropriate time. | 59 // a pump for this queue when needed. |
51 virtual void BlockQueue(base::TimeTicks now, TaskQueue* queue) = 0; | 60 virtual void UpdateQueueThrottlingState(base::TimeTicks now, |
52 | 61 TaskQueue* queue) = 0; |
53 // Schedule a call to unblock queue at an appropriate moment. | |
54 virtual void UnblockQueue(base::TimeTicks now, TaskQueue* queue) = 0; | |
55 | 62 |
56 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler | 63 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler |
57 // and throttling is not disabled). | 64 // and throttling is not disabled). |
58 virtual bool IsThrottled(TaskQueue* queue) const = 0; | 65 virtual bool IsThrottled(TaskQueue* queue) const = 0; |
59 }; | 66 }; |
60 | 67 |
61 // The job of the TaskQueueThrottler is to control when tasks posted on | 68 // The job of the TaskQueueThrottler is to control when tasks posted on |
62 // throttled queues get run. The TaskQueueThrottler: | 69 // throttled queues get run. The TaskQueueThrottler: |
63 // - runs throttled tasks once per second, | 70 // - runs throttled tasks once per second, |
64 // - controls time budget for task queues grouped in CPUTimeBudgetPools. | 71 // - controls time budget for task queues grouped in CPUTimeBudgetPools. |
(...skipping 27 matching lines...) Expand all Loading... |
92 | 99 |
93 // TaskQueue::Observer implementation: | 100 // TaskQueue::Observer implementation: |
94 void OnQueueNextWakeUpChanged(TaskQueue* queue, | 101 void OnQueueNextWakeUpChanged(TaskQueue* queue, |
95 base::TimeTicks wake_up) override; | 102 base::TimeTicks wake_up) override; |
96 | 103 |
97 // BudgetPoolController implementation: | 104 // BudgetPoolController implementation: |
98 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; | 105 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; |
99 void RemoveQueueFromBudgetPool(TaskQueue* queue, | 106 void RemoveQueueFromBudgetPool(TaskQueue* queue, |
100 BudgetPool* budget_pool) override; | 107 BudgetPool* budget_pool) override; |
101 void UnregisterBudgetPool(BudgetPool* budget_pool) override; | 108 void UnregisterBudgetPool(BudgetPool* budget_pool) override; |
102 void BlockQueue(base::TimeTicks now, TaskQueue* queue) override; | 109 void UpdateQueueThrottlingState(base::TimeTicks now, |
103 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; | 110 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. |
113 void DecreaseThrottleRefCount(TaskQueue* task_queue); | 120 void DecreaseThrottleRefCount(TaskQueue* task_queue); |
(...skipping 11 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 desired_run_time); |
| 175 |
| 176 bool CanRunTasksAt(TaskQueue* queue, base::TimeTicks moment, bool is_wakeup); |
| 177 |
| 178 bool CanRunTasksUntil(TaskQueue* queue, |
| 179 base::TimeTicks now, |
| 180 base::TimeTicks moment); |
166 | 181 |
167 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); | 182 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); |
168 | 183 |
169 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. | 184 void UpdateQueueThrottlingStateInternal(base::TimeTicks now, |
170 void SchedulePumpQueue(const tracked_objects::Location& from_here, | 185 TaskQueue* queue, |
171 base::TimeTicks now, | 186 bool is_wake_up); |
172 TaskQueue* queue); | 187 |
| 188 base::Optional<QueueBlockType> GetQueueBlockType(base::TimeTicks now, |
| 189 TaskQueue* queue); |
173 | 190 |
174 TaskQueueMap queue_details_; | 191 TaskQueueMap queue_details_; |
175 base::Callback<void(TaskQueue*, base::TimeTicks)> | 192 base::Callback<void(TaskQueue*, base::TimeTicks)> |
176 forward_immediate_work_callback_; | 193 forward_immediate_work_callback_; |
177 scoped_refptr<TaskQueue> task_runner_; | 194 scoped_refptr<TaskQueue> task_runner_; |
178 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 195 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
179 base::TickClock* tick_clock_; // NOT OWNED | 196 base::TickClock* tick_clock_; // NOT OWNED |
180 const char* tracing_category_; // NOT OWNED | 197 const char* tracing_category_; // NOT OWNED |
181 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 198 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
182 | 199 |
183 CancelableClosureHolder pump_throttled_tasks_closure_; | 200 CancelableClosureHolder pump_throttled_tasks_closure_; |
184 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; | 201 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
185 bool allow_throttling_; | 202 bool allow_throttling_; |
186 | 203 |
187 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; | 204 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; |
188 | 205 |
189 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; | 206 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
190 | 207 |
191 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); | 208 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); |
192 }; | 209 }; |
193 | 210 |
194 } // namespace scheduler | 211 } // namespace scheduler |
195 } // namespace blink | 212 } // namespace blink |
196 | 213 |
197 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO
TTLER_H_ | 214 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO
TTLER_H_ |
OLD | NEW |