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

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

Issue 2258133002: [scheduler] Implement time-based cpu throttling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed Enable/Disable to Enable/DisableThrottling. Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_RENDERER_SCHEDULER _IMPL_H_ 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDULER _IMPL_H_
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDULER _IMPL_H_ 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDULER _IMPL_H_
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "platform/scheduler/base/pollable_thread_safe_flag.h" 11 #include "platform/scheduler/base/pollable_thread_safe_flag.h"
12 #include "platform/scheduler/base/queueing_time_estimator.h" 12 #include "platform/scheduler/base/queueing_time_estimator.h"
13 #include "platform/scheduler/base/thread_load_tracker.h" 13 #include "platform/scheduler/base/thread_load_tracker.h"
14 #include "platform/scheduler/child/idle_helper.h" 14 #include "platform/scheduler/child/idle_helper.h"
15 #include "platform/scheduler/child/scheduler_helper.h" 15 #include "platform/scheduler/child/scheduler_helper.h"
16 #include "platform/scheduler/renderer/deadline_task_runner.h" 16 #include "platform/scheduler/renderer/deadline_task_runner.h"
17 #include "platform/scheduler/renderer/idle_time_estimator.h" 17 #include "platform/scheduler/renderer/idle_time_estimator.h"
18 #include "platform/scheduler/renderer/render_widget_signals.h" 18 #include "platform/scheduler/renderer/render_widget_signals.h"
19 #include "platform/scheduler/renderer/task_cost_estimator.h" 19 #include "platform/scheduler/renderer/task_cost_estimator.h"
20 #include "platform/scheduler/renderer/throttling_helper.h" 20 #include "platform/scheduler/renderer/task_queue_throttler.h"
21 #include "platform/scheduler/renderer/user_model.h" 21 #include "platform/scheduler/renderer/user_model.h"
22 #include "platform/scheduler/renderer/web_view_scheduler_impl.h" 22 #include "platform/scheduler/renderer/web_view_scheduler_impl.h"
23 #include "public/platform/scheduler/renderer/renderer_scheduler.h" 23 #include "public/platform/scheduler/renderer/renderer_scheduler.h"
24 #include "public/platform/scheduler/base/task_time_observer.h" 24 #include "public/platform/scheduler/base/task_time_observer.h"
25 25
26 namespace base { 26 namespace base {
27 namespace trace_event { 27 namespace trace_event {
28 class ConvertableToTraceFormat; 28 class ConvertableToTraceFormat;
29 } 29 }
30 } 30 }
31 31
32 namespace blink { 32 namespace blink {
33 namespace scheduler { 33 namespace scheduler {
34 class AutoAdvancingVirtualTimeDomain; 34 class AutoAdvancingVirtualTimeDomain;
35 class RenderWidgetSchedulingState; 35 class RenderWidgetSchedulingState;
36 class WebViewSchedulerImpl; 36 class WebViewSchedulerImpl;
37 class ThrottlingHelper; 37 class TaskQueueThrottler;
38 38
39 class BLINK_PLATFORM_EXPORT RendererSchedulerImpl 39 class BLINK_PLATFORM_EXPORT RendererSchedulerImpl
40 : public RendererScheduler, 40 : public RendererScheduler,
41 public IdleHelper::Delegate, 41 public IdleHelper::Delegate,
42 public SchedulerHelper::Observer, 42 public SchedulerHelper::Observer,
43 public RenderWidgetSignals::Observer, 43 public RenderWidgetSignals::Observer,
44 public TaskTimeObserver, 44 public TaskTimeObserver,
45 public QueueingTimeEstimator::Client { 45 public QueueingTimeEstimator::Client {
46 public: 46 public:
47 // Keep RendererScheduler::UseCaseToString in sync with this enum. 47 // Keep RendererScheduler::UseCaseToString in sync with this enum.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void SetAllRenderWidgetsHidden(bool hidden) override; 124 void SetAllRenderWidgetsHidden(bool hidden) override;
125 void SetHasVisibleRenderWidgetWithTouchHandler( 125 void SetHasVisibleRenderWidgetWithTouchHandler(
126 bool has_visible_render_widget_with_touch_handler) override; 126 bool has_visible_render_widget_with_touch_handler) override;
127 127
128 // SchedulerHelper::Observer implementation: 128 // SchedulerHelper::Observer implementation:
129 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override; 129 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override;
130 void OnTriedToExecuteBlockedTask(const TaskQueue& queue, 130 void OnTriedToExecuteBlockedTask(const TaskQueue& queue,
131 const base::PendingTask& task) override; 131 const base::PendingTask& task) override;
132 132
133 // TaskTimeObserver implementation: 133 // TaskTimeObserver implementation:
134 void ReportTaskTime(double start_time, double end_time) override; 134 void ReportTaskTime(TaskQueue* task_queue,
135 double start_time,
136 double end_time) override;
135 137
136 // QueueingTimeEstimator::Client implementation: 138 // QueueingTimeEstimator::Client implementation:
137 void OnQueueingTimeForWindowEstimated(base::TimeDelta queueing_time) override; 139 void OnQueueingTimeForWindowEstimated(base::TimeDelta queueing_time) override;
138 140
139 // Returns a task runner where tasks run at the highest possible priority. 141 // Returns a task runner where tasks run at the highest possible priority.
140 scoped_refptr<TaskQueue> ControlTaskRunner(); 142 scoped_refptr<TaskQueue> ControlTaskRunner();
141 143
142 void RegisterTimeDomain(TimeDomain* time_domain); 144 void RegisterTimeDomain(TimeDomain* time_domain);
143 void UnregisterTimeDomain(TimeDomain* time_domain); 145 void UnregisterTimeDomain(TimeDomain* time_domain);
144 146
145 // Tells the scheduler that all TaskQueues should use virtual time. 147 // Tells the scheduler that all TaskQueues should use virtual time.
146 void EnableVirtualTime(); 148 void EnableVirtualTime();
147 149
148 void AddWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); 150 void AddWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler);
149 void RemoveWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); 151 void RemoveWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler);
150 152
151 void AddTaskTimeObserver(TaskTimeObserver* task_time_observer); 153 void AddTaskTimeObserver(TaskTimeObserver* task_time_observer);
152 void RemoveTaskTimeObserver(TaskTimeObserver* task_time_observer); 154 void RemoveTaskTimeObserver(TaskTimeObserver* task_time_observer);
153 155
156 // Snapshots this RendererScheduler for tracing.
157 void CreateTraceEventObjectSnapshot() const;
158
154 // Test helpers. 159 // Test helpers.
155 SchedulerHelper* GetSchedulerHelperForTesting(); 160 SchedulerHelper* GetSchedulerHelperForTesting();
156 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); 161 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting();
157 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); 162 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting();
158 IdleTimeEstimator* GetIdleTimeEstimatorForTesting(); 163 IdleTimeEstimator* GetIdleTimeEstimatorForTesting();
159 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; 164 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const;
160 void RunIdleTasksForTesting(const base::Closure& callback); 165 void RunIdleTasksForTesting(const base::Closure& callback);
161 void EndIdlePeriodForTesting(const base::Closure& callback, 166 void EndIdlePeriodForTesting(const base::Closure& callback,
162 base::TimeTicks time_remaining); 167 base::TimeTicks time_remaining);
163 bool PolicyNeedsUpdateForTesting(); 168 bool PolicyNeedsUpdateForTesting();
164 169
165 base::TickClock* tick_clock() const; 170 base::TickClock* tick_clock() const;
166 171
167 RealTimeDomain* real_time_domain() const { 172 RealTimeDomain* real_time_domain() const {
168 return helper_.real_time_domain(); 173 return helper_.real_time_domain();
169 } 174 }
170 175
171 AutoAdvancingVirtualTimeDomain* GetVirtualTimeDomain(); 176 AutoAdvancingVirtualTimeDomain* GetVirtualTimeDomain();
172 177
173 ThrottlingHelper* throttling_helper() { return throttling_helper_.get(); } 178 TaskQueueThrottler* task_queue_throttler() {
Sami 2016/09/15 16:30:29 const?
altimin 2016/09/16 13:38:48 Done.
179 return task_queue_throttler_.get();
180 }
174 181
175 private: 182 private:
176 friend class RendererSchedulerImplTest; 183 friend class RendererSchedulerImplTest;
177 friend class RendererSchedulerImplForTest; 184 friend class RendererSchedulerImplForTest;
178 friend class RenderWidgetSchedulingState; 185 friend class RenderWidgetSchedulingState;
179 186
180 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE }; 187 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE };
181 188
182 enum class TimeDomainType { 189 enum class TimeDomainType {
183 REAL, 190 REAL,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void OnIdlePeriodStarted() override; 250 void OnIdlePeriodStarted() override;
244 void OnIdlePeriodEnded() override; 251 void OnIdlePeriodEnded() override;
245 252
246 void EndIdlePeriod(); 253 void EndIdlePeriod();
247 254
248 // Returns the serialized scheduler state for tracing. 255 // Returns the serialized scheduler state for tracing.
249 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( 256 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue(
250 base::TimeTicks optional_now) const; 257 base::TimeTicks optional_now) const;
251 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 258 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
252 base::TimeTicks optional_now) const; 259 base::TimeTicks optional_now) const;
260 void CreateTraceEventObjectSnapshotLocked() const;
253 261
254 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event); 262 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event);
255 263
256 // The amount of time which idle periods can continue being scheduled when the 264 // The amount of time which idle periods can continue being scheduled when the
257 // renderer has been hidden, before going to sleep for good. 265 // renderer has been hidden, before going to sleep for good.
258 static const int kEndIdleWhenHiddenDelayMillis = 10000; 266 static const int kEndIdleWhenHiddenDelayMillis = 10000;
259 267
260 // The amount of time for which loading tasks will be prioritized over 268 // The amount of time for which loading tasks will be prioritized over
261 // other tasks during the initial page load. 269 // other tasks during the initial page load.
262 static const int kRailsInitialLoadingPrioritizationMillis = 1000; 270 static const int kRailsInitialLoadingPrioritizationMillis = 1000;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 339
332 void ApplyTaskQueuePolicy(TaskQueue* task_queue, 340 void ApplyTaskQueuePolicy(TaskQueue* task_queue,
333 const TaskQueuePolicy& old_task_queue_policy, 341 const TaskQueuePolicy& old_task_queue_policy,
334 const TaskQueuePolicy& new_task_queue_policy) const; 342 const TaskQueuePolicy& new_task_queue_policy) const;
335 343
336 static const char* ExpensiveTaskPolicyToString( 344 static const char* ExpensiveTaskPolicyToString(
337 ExpensiveTaskPolicy expensive_task_policy); 345 ExpensiveTaskPolicy expensive_task_policy);
338 346
339 SchedulerHelper helper_; 347 SchedulerHelper helper_;
340 IdleHelper idle_helper_; 348 IdleHelper idle_helper_;
341 std::unique_ptr<ThrottlingHelper> throttling_helper_; 349 std::unique_ptr<TaskQueueThrottler> task_queue_throttler_;
342 RenderWidgetSignals render_widget_scheduler_signals_; 350 RenderWidgetSignals render_widget_scheduler_signals_;
343 351
344 const scoped_refptr<TaskQueue> control_task_runner_; 352 const scoped_refptr<TaskQueue> control_task_runner_;
345 const scoped_refptr<TaskQueue> compositor_task_runner_; 353 const scoped_refptr<TaskQueue> compositor_task_runner_;
346 std::set<scoped_refptr<TaskQueue>> loading_task_runners_; 354 std::set<scoped_refptr<TaskQueue>> loading_task_runners_;
347 std::set<scoped_refptr<TaskQueue>> timer_task_runners_; 355 std::set<scoped_refptr<TaskQueue>> timer_task_runners_;
348 std::set<scoped_refptr<TaskQueue>> unthrottled_task_runners_; 356 std::set<scoped_refptr<TaskQueue>> unthrottled_task_runners_;
349 scoped_refptr<TaskQueue> default_loading_task_runner_; 357 scoped_refptr<TaskQueue> default_loading_task_runner_;
350 scoped_refptr<TaskQueue> default_timer_task_runner_; 358 scoped_refptr<TaskQueue> default_timer_task_runner_;
351 359
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 PollableThreadSafeFlag policy_may_need_update_; 477 PollableThreadSafeFlag policy_may_need_update_;
470 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 478 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
471 479
472 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 480 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
473 }; 481 };
474 482
475 } // namespace scheduler 483 } // namespace scheduler
476 } // namespace blink 484 } // namespace blink
477 485
478 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU LER_IMPL_H_ 486 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU LER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698