Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.h

Issue 2778123003: [scheduler] Add WakeupBudgetPool. (Closed)
Patch Set: Rebased & addressed comments from skyostil@ and alexclarke@ Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/optional.h" 13 #include "base/optional.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "platform/PlatformExport.h" 15 #include "platform/PlatformExport.h"
16 #include "platform/scheduler/base/cancelable_closure_holder.h" 16 #include "platform/scheduler/base/cancelable_closure_holder.h"
17 #include "platform/scheduler/base/time_domain.h" 17 #include "platform/scheduler/base/time_domain.h"
18 #include "platform/scheduler/renderer/budget_pool.h" 18 #include "platform/scheduler/renderer/budget_pool.h"
19 #include "platform/scheduler/renderer/cpu_time_budget_pool.h"
20 #include "platform/scheduler/renderer/wake_up_budget_pool.h"
19 #include "platform/scheduler/renderer/web_view_scheduler.h" 21 #include "platform/scheduler/renderer/web_view_scheduler.h"
20 22
21 namespace base { 23 namespace base {
22 namespace trace_event { 24 namespace trace_event {
23 class TracedValue; 25 class TracedValue;
24 } 26 }
25 } 27 }
26 28
27 namespace blink { 29 namespace blink {
28 namespace scheduler { 30 namespace scheduler {
29 31
30 class BudgetPool; 32 class BudgetPool;
31 class RendererSchedulerImpl; 33 class RendererSchedulerImpl;
32 class ThrottledTimeDomain; 34 class ThrottledTimeDomain;
33 class CPUTimeBudgetPool; 35 class CPUTimeBudgetPool;
36 class WakeUpBudgetPool;
37
38 // kNewTasksOnly prevents new tasks from running (old tasks can run normally),
39 // kAllTasks block queue completely.
40 // kAllTasks-type block always blocks the queue completely.
41 // kNewTasksOnly-type block does nothing when queue is already blocked by
42 // kAllTasks, and overrides previous kNewTasksOnly block if any, which may
43 // unblock some tasks.
44 enum class QueueBlockType { kAllTasks, kNewTasksOnly };
34 45
35 // Interface for BudgetPool to interact with TaskQueueThrottler. 46 // Interface for BudgetPool to interact with TaskQueueThrottler.
36 class PLATFORM_EXPORT BudgetPoolController { 47 class PLATFORM_EXPORT BudgetPoolController {
37 public: 48 public:
38 virtual ~BudgetPoolController() {} 49 virtual ~BudgetPoolController() {}
39 50
40 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue 51 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue
41 // methods instead. 52 // methods instead.
42 virtual void AddQueueToBudgetPool(TaskQueue* queue, 53 virtual void AddQueueToBudgetPool(TaskQueue* queue,
43 BudgetPool* budget_pool) = 0; 54 BudgetPool* budget_pool) = 0;
44 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue, 55 virtual void RemoveQueueFromBudgetPool(TaskQueue* queue,
45 BudgetPool* budget_pool) = 0; 56 BudgetPool* budget_pool) = 0;
46 57
47 // Deletes the budget pool. 58 // Deletes the budget pool.
48 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0; 59 virtual void UnregisterBudgetPool(BudgetPool* budget_pool) = 0;
49 60
50 // Insert a fence to prevent tasks from running and schedule a wake-up at 61 // Ensure that an appropriate type of the fence is installed and schedule
51 // an appropriate time. 62 // a pump for this queue when needed.
52 virtual void BlockQueue(base::TimeTicks now, TaskQueue* queue) = 0; 63 virtual void UpdateQueueThrottlingState(base::TimeTicks now,
53 64 TaskQueue* queue) = 0;
54 // Schedule a call to unblock queue at an appropriate moment.
55 virtual void UnblockQueue(base::TimeTicks now, TaskQueue* queue) = 0;
56 65
57 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler 66 // Returns true if the |queue| is throttled (i.e. added to TaskQueueThrottler
58 // and throttling is not disabled). 67 // and throttling is not disabled).
59 virtual bool IsThrottled(TaskQueue* queue) const = 0; 68 virtual bool IsThrottled(TaskQueue* queue) const = 0;
60 }; 69 };
61 70
62 // The job of the TaskQueueThrottler is to control when tasks posted on 71 // The job of the TaskQueueThrottler is to control when tasks posted on
63 // throttled queues get run. The TaskQueueThrottler: 72 // throttled queues get run. The TaskQueueThrottler:
64 // - runs throttled tasks once per second, 73 // - runs throttled tasks once per second,
65 // - controls time budget for task queues grouped in CPUTimeBudgetPools. 74 // - controls time budget for task queues grouped in CPUTimeBudgetPools.
(...skipping 24 matching lines...) Expand all
90 99
91 // TaskQueue::Observer implementation: 100 // TaskQueue::Observer implementation:
92 void OnQueueNextWakeUpChanged(TaskQueue* queue, 101 void OnQueueNextWakeUpChanged(TaskQueue* queue,
93 base::TimeTicks wake_up) override; 102 base::TimeTicks wake_up) override;
94 103
95 // BudgetPoolController implementation: 104 // BudgetPoolController implementation:
96 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; 105 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override;
97 void RemoveQueueFromBudgetPool(TaskQueue* queue, 106 void RemoveQueueFromBudgetPool(TaskQueue* queue,
98 BudgetPool* budget_pool) override; 107 BudgetPool* budget_pool) override;
99 void UnregisterBudgetPool(BudgetPool* budget_pool) override; 108 void UnregisterBudgetPool(BudgetPool* budget_pool) override;
100 void BlockQueue(base::TimeTicks now, TaskQueue* queue) override; 109 void UpdateQueueThrottlingState(base::TimeTicks now,
101 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; 110 TaskQueue* queue) override;
102 bool IsThrottled(TaskQueue* queue) const override; 111 bool IsThrottled(TaskQueue* queue) const override;
103 112
104 // Increments the throttled refcount and causes |task_queue| to be throttled 113 // Increments the throttled refcount and causes |task_queue| to be throttled
105 // if its not already throttled. 114 // if its not already throttled.
106 void IncreaseThrottleRefCount(TaskQueue* task_queue); 115 void IncreaseThrottleRefCount(TaskQueue* task_queue);
107 116
108 // 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
109 // 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
110 // zero this function does nothing. 119 // zero this function does nothing.
111 void DecreaseThrottleRefCount(TaskQueue* task_queue); 120 void DecreaseThrottleRefCount(TaskQueue* task_queue);
(...skipping 13 matching lines...) Expand all
125 134
126 static base::TimeTicks AlignedThrottledRunTime( 135 static base::TimeTicks AlignedThrottledRunTime(
127 base::TimeTicks unthrottled_runtime); 136 base::TimeTicks unthrottled_runtime);
128 137
129 const scoped_refptr<TaskQueue>& task_queue() const { 138 const scoped_refptr<TaskQueue>& task_queue() const {
130 return control_task_queue_; 139 return control_task_queue_;
131 } 140 }
132 141
133 // Returned object is owned by |TaskQueueThrottler|. 142 // Returned object is owned by |TaskQueueThrottler|.
134 CPUTimeBudgetPool* CreateCPUTimeBudgetPool(const char* name); 143 CPUTimeBudgetPool* CreateCPUTimeBudgetPool(const char* name);
144 WakeUpBudgetPool* CreateWakeUpBudgetPool(const char* name);
135 145
136 // Accounts for given task for cpu-based throttling needs. 146 // Accounts for given task for cpu-based throttling needs.
137 void OnTaskRunTimeReported(TaskQueue* task_queue, 147 void OnTaskRunTimeReported(TaskQueue* task_queue,
138 base::TimeTicks start_time, 148 base::TimeTicks start_time,
139 base::TimeTicks end_time); 149 base::TimeTicks end_time);
140 150
141 void AsValueInto(base::trace_event::TracedValue* state, 151 void AsValueInto(base::trace_event::TracedValue* state,
142 base::TimeTicks now) const; 152 base::TimeTicks now) const;
143 private: 153 private:
144 struct Metadata { 154 struct Metadata {
(...skipping 10 matching lines...) Expand all
155 // Note |unthrottled_runtime| might be in the past. When this happens we 165 // 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 166 // compute the delay to the next runtime based on now rather than
157 // unthrottled_runtime. 167 // unthrottled_runtime.
158 void MaybeSchedulePumpThrottledTasks( 168 void MaybeSchedulePumpThrottledTasks(
159 const tracked_objects::Location& from_here, 169 const tracked_objects::Location& from_here,
160 base::TimeTicks now, 170 base::TimeTicks now,
161 base::TimeTicks runtime); 171 base::TimeTicks runtime);
162 172
163 // Return next possible time when queue is allowed to run in accordance 173 // Return next possible time when queue is allowed to run in accordance
164 // with throttling policy. 174 // with throttling policy.
165 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue); 175 base::TimeTicks GetNextAllowedRunTime(TaskQueue* queue,
176 base::TimeTicks desired_run_time);
177
178 bool CanRunTasksAt(TaskQueue* queue, base::TimeTicks moment, bool is_wakeup);
166 179
167 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); 180 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it);
168 181
169 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. 182 void UpdateQueueThrottlingStateInternal(base::TimeTicks now,
170 void SchedulePumpQueue(const tracked_objects::Location& from_here, 183 TaskQueue* queue,
171 base::TimeTicks now, 184 bool is_wake_up);
172 TaskQueue* queue); 185
186 base::Optional<QueueBlockType> GetQueueBlockType(base::TimeTicks now,
187 TaskQueue* queue);
173 188
174 TaskQueueMap queue_details_; 189 TaskQueueMap queue_details_;
175 base::Callback<void(TaskQueue*, base::TimeTicks)> 190 base::Callback<void(TaskQueue*, base::TimeTicks)>
176 forward_immediate_work_callback_; 191 forward_immediate_work_callback_;
177 scoped_refptr<TaskQueue> control_task_queue_; 192 scoped_refptr<TaskQueue> control_task_queue_;
178 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED 193 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED
179 base::TickClock* tick_clock_; // NOT OWNED 194 base::TickClock* tick_clock_; // NOT OWNED
180 std::unique_ptr<ThrottledTimeDomain> time_domain_; 195 std::unique_ptr<ThrottledTimeDomain> time_domain_;
181 196
182 CancelableClosureHolder pump_throttled_tasks_closure_; 197 CancelableClosureHolder pump_throttled_tasks_closure_;
183 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; 198 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_;
184 bool allow_throttling_; 199 bool allow_throttling_;
185 200
186 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; 201 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_;
187 202
188 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; 203 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_;
189 204
190 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); 205 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler);
191 }; 206 };
192 207
193 } // namespace scheduler 208 } // namespace scheduler
194 } // namespace blink 209 } // namespace blink
195 210
196 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_ 211 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698