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

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

Issue 2742383005: [scheduler] Untangle BudgetPool from TaskQueueThrottler. (Closed)
Patch Set: Created 3 years, 9 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
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 base::Optional<base::TimeDelta> max_throttling_duration); 102 base::Optional<base::TimeDelta> max_throttling_duration);
103 103
104 // Accounts for given task for cpu-based throttling needs. 104 // Accounts for given task for cpu-based throttling needs.
105 void OnTaskRunTimeReported(TaskQueue* task_queue, 105 void OnTaskRunTimeReported(TaskQueue* task_queue,
106 base::TimeTicks start_time, 106 base::TimeTicks start_time,
107 base::TimeTicks end_time); 107 base::TimeTicks end_time);
108 108
109 void AsValueInto(base::trace_event::TracedValue* state, 109 void AsValueInto(base::trace_event::TracedValue* state,
110 base::TimeTicks now) const; 110 base::TimeTicks now) const;
111 111
112 // Methods for BudgetPools to interact with TaskQueueThrottler.
113
114 // To be used by BudgetPool only, use BudgetPool::{Add,Remove}Queue
115 // methods instead.
116 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool);
alex clarke (OOO till 29th) 2017/03/14 18:22:39 bike-shed: Should we try to decouple even further
altimin 2017/03/14 18:26:44 I like the idea in general, but that I think that'
Sami 2017/03/14 18:43:01 I think I'd also like to suggest turning these met
altimin 2017/03/14 20:04:28 Done.
117 void RemoveQueueFromBudgetPool(TaskQueue* queue, BudgetPool* budget_pool);
118
119 // Deletes the budget pool.
120 void UnregisterBudgetPool(BudgetPool* budget_pool);
121
122 // Schedule a call to PumpThrottledTasks to unblock a queue at an appropriate
123 // moment.
124 void SchedulePumpQueue(const tracked_objects::Location& from_here,
125 base::TimeTicks now,
126 TaskQueue* queue);
127
128 // Insert a fence to prevent tasks from running and schedule a wakeup at
129 // an appropriate time.
130 void BlockThrottledQueue(base::TimeTicks now, TaskQueue* queue);
131
112 private: 132 private:
113 friend class BudgetPool;
114 friend class CPUTimeBudgetPool;
115
116 struct Metadata { 133 struct Metadata {
117 Metadata() : throttling_ref_count(0), time_budget_pool(nullptr) {} 134 Metadata() : throttling_ref_count(0), budget_pool(nullptr) {}
118 135
119 size_t throttling_ref_count; 136 size_t throttling_ref_count;
120 137
121 CPUTimeBudgetPool* time_budget_pool; 138 BudgetPool* budget_pool;
122 }; 139 };
123 using TaskQueueMap = std::unordered_map<TaskQueue*, Metadata>; 140 using TaskQueueMap = std::unordered_map<TaskQueue*, Metadata>;
124 141
125 void PumpThrottledTasks(); 142 void PumpThrottledTasks();
126 143
127 // Note |unthrottled_runtime| might be in the past. When this happens we 144 // Note |unthrottled_runtime| might be in the past. When this happens we
128 // compute the delay to the next runtime based on now rather than 145 // compute the delay to the next runtime based on now rather than
129 // unthrottled_runtime. 146 // unthrottled_runtime.
130 void MaybeSchedulePumpThrottledTasks( 147 void MaybeSchedulePumpThrottledTasks(
131 const tracked_objects::Location& from_here, 148 const tracked_objects::Location& from_here,
132 base::TimeTicks now, 149 base::TimeTicks now,
133 base::TimeTicks runtime); 150 base::TimeTicks runtime);
134 151
135 CPUTimeBudgetPool* GetTimeBudgetPoolForQueue(TaskQueue* queue); 152 BudgetPool* GetBudgetPoolForQueue(TaskQueue* queue);
136
137 // Schedule pumping because of given task queue.
138 void MaybeSchedulePumpQueue(
139 const tracked_objects::Location& from_here,
140 base::TimeTicks now,
141 TaskQueue* queue,
142 base::Optional<base::TimeTicks> next_possible_run_time);
143 153
144 // Return next possible time when queue is allowed to run in accordance 154 // Return next possible time when queue is allowed to run in accordance
145 // with throttling policy. 155 // with throttling policy.
146 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue); 156 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue);
147 157
148 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); 158 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it);
149 159
150 TaskQueueMap queue_details_; 160 TaskQueueMap queue_details_;
151 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; 161 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_;
152 scoped_refptr<TaskQueue> task_runner_; 162 scoped_refptr<TaskQueue> task_runner_;
153 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED 163 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED
154 base::TickClock* tick_clock_; // NOT OWNED 164 base::TickClock* tick_clock_; // NOT OWNED
155 const char* tracing_category_; // NOT OWNED 165 const char* tracing_category_; // NOT OWNED
156 std::unique_ptr<ThrottledTimeDomain> time_domain_; 166 std::unique_ptr<ThrottledTimeDomain> time_domain_;
157 167
158 CancelableClosureHolder pump_throttled_tasks_closure_; 168 CancelableClosureHolder pump_throttled_tasks_closure_;
159 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; 169 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_;
160 bool allow_throttling_; 170 bool allow_throttling_;
161 171
162 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> 172 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_;
163 time_budget_pools_;
164 173
165 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; 174 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_;
166 175
167 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); 176 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler);
168 }; 177 };
169 178
170 } // namespace scheduler 179 } // namespace scheduler
171 } // namespace blink 180 } // namespace blink
172 181
173 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_ 182 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO TTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698