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

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_impl.h

Issue 968073003: [content]: Add support for long idle times in the Blink Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@long_idle_4
Patch Set: Enable for testing Created 5 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
« no previous file with comments | « no previous file | content/renderer/scheduler/renderer_scheduler_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 void DidAnimateForInputOnCompositorThread() override; 45 void DidAnimateForInputOnCompositorThread() override;
46 bool IsHighPriorityWorkAnticipated() override; 46 bool IsHighPriorityWorkAnticipated() override;
47 bool ShouldYieldForHighPriorityWork() override; 47 bool ShouldYieldForHighPriorityWork() override;
48 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; 48 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override;
49 void RemoveTaskObserver( 49 void RemoveTaskObserver(
50 base::MessageLoop::TaskObserver* task_observer) override; 50 base::MessageLoop::TaskObserver* task_observer) override;
51 void Shutdown() override; 51 void Shutdown() override;
52 52
53 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); 53 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source);
54 void SetWorkBatchSizeForTesting(size_t work_batch_size); 54 void SetWorkBatchSizeForTesting(size_t work_batch_size);
55 // TODO(rmcilroy): Remove this when http://crbug.com/467655 is fixed.
56 void SetLongIdlePeriodsEnabledForTesting(bool long_idle_periods_enabled);
55 57
56 private: 58 private:
57 friend class RendererSchedulerImplTest; 59 friend class RendererSchedulerImplTest;
58 friend class RendererSchedulerImplForTest; 60 friend class RendererSchedulerImplForTest;
59 61
60 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum. 62 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum.
61 enum QueueId { 63 enum QueueId {
62 DEFAULT_TASK_QUEUE, 64 DEFAULT_TASK_QUEUE,
63 COMPOSITOR_TASK_QUEUE, 65 COMPOSITOR_TASK_QUEUE,
64 LOADING_TASK_QUEUE, 66 LOADING_TASK_QUEUE,
65 IDLE_TASK_QUEUE, 67 IDLE_TASK_QUEUE,
66 CONTROL_TASK_QUEUE, 68 CONTROL_TASK_QUEUE,
67 CONTROL_TASK_AFTER_WAKEUP_QUEUE, 69 CONTROL_TASK_AFTER_WAKEUP_QUEUE,
68 // Must be the last entry. 70 // Must be the last entry.
69 TASK_QUEUE_COUNT, 71 TASK_QUEUE_COUNT,
70 }; 72 };
71 73
74 // Keep RendererSchedulerImpl::PolicyToString in sync with this enum.
72 enum class Policy { 75 enum class Policy {
73 NORMAL, 76 NORMAL,
74 COMPOSITOR_PRIORITY, 77 COMPOSITOR_PRIORITY,
75 TOUCHSTART_PRIORITY, 78 TOUCHSTART_PRIORITY,
76 }; 79 };
77 80
81 // Keep RendererSchedulerImpl::InputStreamStateToString in sync with this
82 // enum.
78 enum class InputStreamState { 83 enum class InputStreamState {
79 INACTIVE, 84 INACTIVE,
80 ACTIVE, 85 ACTIVE,
81 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE 86 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
82 }; 87 };
83 88
89 // Keep RendererSchedulerImpl::IdlePeriodStateToString in sync with this enum.
90 enum class IdlePeriodState {
91 NOT_IN_IDLE_PERIOD,
92 IN_SHORT_IDLE_PERIOD,
93 IN_LONG_IDLE_PERIOD,
94 IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE,
95 ENDING_LONG_IDLE_PERIOD
96 };
97
84 class PollableNeedsUpdateFlag { 98 class PollableNeedsUpdateFlag {
85 public: 99 public:
86 PollableNeedsUpdateFlag(base::Lock* write_lock); 100 PollableNeedsUpdateFlag(base::Lock* write_lock);
87 ~PollableNeedsUpdateFlag(); 101 ~PollableNeedsUpdateFlag();
88 102
89 // Set the flag. May only be called if |write_lock| is held. 103 // Set the flag. May only be called if |write_lock| is held.
90 void SetWhileLocked(bool value); 104 void SetWhileLocked(bool value);
91 105
92 // Returns true iff the flag is set to true. 106 // Returns true iff the flag is set to true.
93 bool IsSet() const; 107 bool IsSet() const;
94 108
95 private: 109 private:
96 base::subtle::Atomic32 flag_; 110 base::subtle::Atomic32 flag_;
97 base::Lock* write_lock_; // Not owned. 111 base::Lock* write_lock_; // Not owned.
98 112
99 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag); 113 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag);
100 }; 114 };
101 115
102 // Returns the serialized scheduler state for tracing. 116 // Returns the serialized scheduler state for tracing.
103 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 117 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
104 base::TimeTicks optional_now) const; 118 base::TimeTicks optional_now) const;
105 static const char* TaskQueueIdToString(QueueId queue_id); 119 static const char* TaskQueueIdToString(QueueId queue_id);
106 static const char* PolicyToString(Policy policy); 120 static const char* PolicyToString(Policy policy);
107 static const char* InputStreamStateToString(InputStreamState state); 121 static const char* InputStreamStateToString(InputStreamState state);
122 static const char* IdlePeriodStateToString(IdlePeriodState state);
108 123
109 static InputStreamState ComputeNewInputStreamState( 124 static InputStreamState ComputeNewInputStreamState(
110 InputStreamState current_state, 125 InputStreamState current_state,
111 blink::WebInputEvent::Type new_input_event, 126 blink::WebInputEvent::Type new_input_event,
112 blink::WebInputEvent::Type last_input_event); 127 blink::WebInputEvent::Type last_input_event);
113 128
114 // The time we should stay in a priority-escalated mode after an input event. 129 // The time we should stay in a priority-escalated mode after an input event.
115 static const int kPriorityEscalationAfterInputMillis = 100; 130 static const int kPriorityEscalationAfterInputMillis = 100;
116 131
132 // The maximum length of an idle period.
133 static const int kMaximumIdlePeriodMillis = 50;
134
135 // The minimum delay to wait between retrying to initiate a long idle time.
136 static const int kRetryInitiateLongIdlePeriodDelayMillis = 1;
137
117 // IdleTaskDeadlineSupplier Implementation: 138 // IdleTaskDeadlineSupplier Implementation:
118 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; 139 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
119 140
120 // Returns the current scheduler policy. Must be called from the main thread. 141 // Returns the current scheduler policy. Must be called from the main thread.
121 Policy SchedulerPolicy() const; 142 Policy SchedulerPolicy() const;
122 143
123 // Schedules an immediate PolicyUpdate, if there isn't one already pending and 144 // Schedules an immediate PolicyUpdate, if there isn't one already pending and
124 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be 145 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be
125 // locked. 146 // locked.
126 void EnsureUrgentPolicyUpdatePostedOnMainThread( 147 void EnsureUrgentPolicyUpdatePostedOnMainThread(
127 const tracked_objects::Location& from_here); 148 const tracked_objects::Location& from_here);
128 149
129 // Update the policy if a new signal has arrived. Must be called from the main 150 // Update the policy if a new signal has arrived. Must be called from the main
130 // thread. 151 // thread.
131 void MaybeUpdatePolicy(); 152 void MaybeUpdatePolicy();
132 153
133 // Locks |incoming_signals_lock_| and updates the scheduler policy. 154 // Locks |incoming_signals_lock_| and updates the scheduler policy.
134 // Must be called from the main thread. 155 // Must be called from the main thread.
135 void UpdatePolicy(); 156 void UpdatePolicy();
136 virtual void UpdatePolicyLocked(); 157 virtual void UpdatePolicyLocked();
137 158
159 // Returns the amount of time left in the current input escalated priority
160 // policy.
161 base::TimeDelta TimeLeftInInputEscalatedPolicy(base::TimeTicks now) const;
162
138 // Helper for computing the new policy. |new_policy_duration| will be filled 163 // Helper for computing the new policy. |new_policy_duration| will be filled
139 // with the amount of time after which the policy should be updated again. If 164 // with the amount of time after which the policy should be updated again. If
140 // the duration is zero, a new policy update will not be scheduled. Must be 165 // the duration is zero, a new policy update will not be scheduled. Must be
141 // called with |incoming_signals_lock_| held. 166 // called with |incoming_signals_lock_| held.
142 Policy ComputeNewPolicy(base::TimeTicks now, 167 Policy ComputeNewPolicy(base::TimeTicks now,
143 base::TimeDelta* new_policy_duration); 168 base::TimeDelta* new_policy_duration);
144 169
145 // An input event of some sort happened, the policy may need updating. 170 // An input event of some sort happened, the policy may need updating.
146 void UpdateForInputEvent(blink::WebInputEvent::Type type); 171 void UpdateForInputEvent(blink::WebInputEvent::Type type);
147 172
148 // Called when a previously queued input event was processed. 173 // Called when a previously queued input event was processed.
149 // |begin_frame_time|, if non-zero, identifies the frame time at which the 174 // |begin_frame_time|, if non-zero, identifies the frame time at which the
150 // input was processed. 175 // input was processed.
151 void DidProcessInputEvent(base::TimeTicks begin_frame_time); 176 void DidProcessInputEvent(base::TimeTicks begin_frame_time);
152 177
178 // Returns the new idle period state for the next long idle period. Fills in
179 // |next_long_idle_period_delay_out| with the next time we should try to
180 // initiate the next idle period.
181 IdlePeriodState ComputeNewLongIdlePeriodState(
182 const base::TimeTicks now,
183 base::TimeDelta* next_long_idle_period_delay_out);
184
185 // Initiate a long idle period.
186 void InitiateLongIdlePeriod();
187 void InitiateLongIdlePeriodAfterWakeup();
188
153 // Start and end an idle period. 189 // Start and end an idle period.
154 void StartIdlePeriod(); 190 void StartIdlePeriod(IdlePeriodState new_idle_period_state);
155 void EndIdlePeriod(); 191 void EndIdlePeriod();
156 192
193 // Returns true if |state| represents being within an idle period state.
194 static bool IsInIdlePeriod(IdlePeriodState state);
195
157 base::TimeTicks Now() const; 196 base::TimeTicks Now() const;
158 197
159 base::ThreadChecker main_thread_checker_; 198 base::ThreadChecker main_thread_checker_;
160 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; 199 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
161 scoped_ptr<TaskQueueManager> task_queue_manager_; 200 scoped_ptr<TaskQueueManager> task_queue_manager_;
162 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 201 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
163 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; 202 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
164 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 203 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
165 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 204 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
166 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 205 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
167 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 206 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
168 207
169 base::Closure update_policy_closure_; 208 base::Closure update_policy_closure_;
170 DeadlineTaskRunner delayed_update_policy_runner_; 209 DeadlineTaskRunner delayed_update_policy_runner_;
171 CancelableClosureHolder end_idle_period_closure_; 210 CancelableClosureHolder end_idle_period_closure_;
211 CancelableClosureHolder initiate_next_long_idle_period_closure_;
212 CancelableClosureHolder initiate_next_long_idle_period_after_wakeup_closure_;
172 213
173 // Don't access current_policy_ directly, instead use SchedulerPolicy(). 214 // Don't access current_policy_ directly, instead use SchedulerPolicy().
174 Policy current_policy_; 215 Policy current_policy_;
216 IdlePeriodState idle_period_state_;
217
218 // TODO(rmcilroy): Remove this when http://crbug.com/467655 is fixed.
219 bool long_idle_periods_enabled_;
175 220
176 base::TimeTicks estimated_next_frame_begin_; 221 base::TimeTicks estimated_next_frame_begin_;
222 base::TimeTicks current_policy_expiration_time_;
177 223
178 // The incoming_signals_lock_ mutex protects access to all variables in the 224 // The incoming_signals_lock_ mutex protects access to all variables in the
179 // (contiguous) block below. 225 // (contiguous) block below.
180 base::Lock incoming_signals_lock_; 226 base::Lock incoming_signals_lock_;
181 base::TimeTicks last_input_receipt_time_on_compositor_; 227 base::TimeTicks last_input_receipt_time_on_compositor_;
182 base::TimeTicks last_input_process_time_on_main_; 228 base::TimeTicks last_input_process_time_on_main_;
183 blink::WebInputEvent::Type last_input_type_; 229 blink::WebInputEvent::Type last_input_type_;
184 InputStreamState input_stream_state_; 230 InputStreamState input_stream_state_;
185 PollableNeedsUpdateFlag policy_may_need_update_; 231 PollableNeedsUpdateFlag policy_may_need_update_;
186 232
187 scoped_refptr<cc::TestNowSource> time_source_; 233 scoped_refptr<cc::TestNowSource> time_source_;
188 234
189 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; 235 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
190 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 236 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
191 237
192 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 238 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
193 }; 239 };
194 240
195 } // namespace content 241 } // namespace content
196 242
197 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 243 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/scheduler/renderer_scheduler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698