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

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: Use double instead of base::TimeTicks 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 void CreateTraceEventObjectSnapshot() const;
alex clarke (OOO till 29th) 2016/09/12 17:45:26 Please add a comment explaining what this does.
altimin 2016/09/14 11:23:15 Done.
157
154 // Test helpers. 158 // Test helpers.
155 SchedulerHelper* GetSchedulerHelperForTesting(); 159 SchedulerHelper* GetSchedulerHelperForTesting();
156 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); 160 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting();
157 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); 161 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting();
158 IdleTimeEstimator* GetIdleTimeEstimatorForTesting(); 162 IdleTimeEstimator* GetIdleTimeEstimatorForTesting();
159 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; 163 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const;
160 void RunIdleTasksForTesting(const base::Closure& callback); 164 void RunIdleTasksForTesting(const base::Closure& callback);
161 void EndIdlePeriodForTesting(const base::Closure& callback, 165 void EndIdlePeriodForTesting(const base::Closure& callback,
162 base::TimeTicks time_remaining); 166 base::TimeTicks time_remaining);
163 bool PolicyNeedsUpdateForTesting(); 167 bool PolicyNeedsUpdateForTesting();
164 168
165 base::TickClock* tick_clock() const; 169 base::TickClock* tick_clock() const;
166 170
167 RealTimeDomain* real_time_domain() const { 171 RealTimeDomain* real_time_domain() const {
168 return helper_.real_time_domain(); 172 return helper_.real_time_domain();
169 } 173 }
170 174
171 AutoAdvancingVirtualTimeDomain* GetVirtualTimeDomain(); 175 AutoAdvancingVirtualTimeDomain* GetVirtualTimeDomain();
172 176
173 ThrottlingHelper* throttling_helper() { return throttling_helper_.get(); } 177 TaskQueueThrottler* task_queue_throttler() {
178 return task_queue_throttler_.get();
179 }
174 180
175 private: 181 private:
176 friend class RendererSchedulerImplTest; 182 friend class RendererSchedulerImplTest;
177 friend class RendererSchedulerImplForTest; 183 friend class RendererSchedulerImplForTest;
178 friend class RenderWidgetSchedulingState; 184 friend class RenderWidgetSchedulingState;
179 185
180 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE }; 186 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE };
181 187
182 enum class TimeDomainType { 188 enum class TimeDomainType {
183 REAL, 189 REAL,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 void OnIdlePeriodStarted() override; 249 void OnIdlePeriodStarted() override;
244 void OnIdlePeriodEnded() override; 250 void OnIdlePeriodEnded() override;
245 251
246 void EndIdlePeriod(); 252 void EndIdlePeriod();
247 253
248 // Returns the serialized scheduler state for tracing. 254 // Returns the serialized scheduler state for tracing.
249 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( 255 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue(
250 base::TimeTicks optional_now) const; 256 base::TimeTicks optional_now) const;
251 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 257 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
252 base::TimeTicks optional_now) const; 258 base::TimeTicks optional_now) const;
259 void CreateTraceEventObjectSnapshotLocked() const;
253 260
254 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event); 261 static bool ShouldPrioritizeInputEvent(const WebInputEvent& web_input_event);
255 262
256 // The amount of time which idle periods can continue being scheduled when the 263 // The amount of time which idle periods can continue being scheduled when the
257 // renderer has been hidden, before going to sleep for good. 264 // renderer has been hidden, before going to sleep for good.
258 static const int kEndIdleWhenHiddenDelayMillis = 10000; 265 static const int kEndIdleWhenHiddenDelayMillis = 10000;
259 266
260 // The amount of time for which loading tasks will be prioritized over 267 // The amount of time for which loading tasks will be prioritized over
261 // other tasks during the initial page load. 268 // other tasks during the initial page load.
262 static const int kRailsInitialLoadingPrioritizationMillis = 1000; 269 static const int kRailsInitialLoadingPrioritizationMillis = 1000;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 338
332 void ApplyTaskQueuePolicy(TaskQueue* task_queue, 339 void ApplyTaskQueuePolicy(TaskQueue* task_queue,
333 const TaskQueuePolicy& old_task_queue_policy, 340 const TaskQueuePolicy& old_task_queue_policy,
334 const TaskQueuePolicy& new_task_queue_policy) const; 341 const TaskQueuePolicy& new_task_queue_policy) const;
335 342
336 static const char* ExpensiveTaskPolicyToString( 343 static const char* ExpensiveTaskPolicyToString(
337 ExpensiveTaskPolicy expensive_task_policy); 344 ExpensiveTaskPolicy expensive_task_policy);
338 345
339 SchedulerHelper helper_; 346 SchedulerHelper helper_;
340 IdleHelper idle_helper_; 347 IdleHelper idle_helper_;
341 std::unique_ptr<ThrottlingHelper> throttling_helper_; 348 std::unique_ptr<TaskQueueThrottler> task_queue_throttler_;
342 RenderWidgetSignals render_widget_scheduler_signals_; 349 RenderWidgetSignals render_widget_scheduler_signals_;
343 350
344 const scoped_refptr<TaskQueue> control_task_runner_; 351 const scoped_refptr<TaskQueue> control_task_runner_;
345 const scoped_refptr<TaskQueue> compositor_task_runner_; 352 const scoped_refptr<TaskQueue> compositor_task_runner_;
346 std::set<scoped_refptr<TaskQueue>> loading_task_runners_; 353 std::set<scoped_refptr<TaskQueue>> loading_task_runners_;
347 std::set<scoped_refptr<TaskQueue>> timer_task_runners_; 354 std::set<scoped_refptr<TaskQueue>> timer_task_runners_;
348 std::set<scoped_refptr<TaskQueue>> unthrottled_task_runners_; 355 std::set<scoped_refptr<TaskQueue>> unthrottled_task_runners_;
349 scoped_refptr<TaskQueue> default_loading_task_runner_; 356 scoped_refptr<TaskQueue> default_loading_task_runner_;
350 scoped_refptr<TaskQueue> default_timer_task_runner_; 357 scoped_refptr<TaskQueue> default_timer_task_runner_;
351 358
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 PollableThreadSafeFlag policy_may_need_update_; 476 PollableThreadSafeFlag policy_may_need_update_;
470 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 477 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
471 478
472 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 479 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
473 }; 480 };
474 481
475 } // namespace scheduler 482 } // namespace scheduler
476 } // namespace blink 483 } // namespace blink
477 484
478 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU LER_IMPL_H_ 485 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_RENDERER_SCHEDU LER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698