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

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: Include IdlePeriodState changes and ENDING_IDLE_PERIOD state. 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
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 DEFAULT_TASK_QUEUE, 59 DEFAULT_TASK_QUEUE,
60 COMPOSITOR_TASK_QUEUE, 60 COMPOSITOR_TASK_QUEUE,
61 LOADING_TASK_QUEUE, 61 LOADING_TASK_QUEUE,
62 IDLE_TASK_QUEUE, 62 IDLE_TASK_QUEUE,
63 CONTROL_TASK_QUEUE, 63 CONTROL_TASK_QUEUE,
64 CONTROL_TASK_AFTER_WAKEUP_QUEUE, 64 CONTROL_TASK_AFTER_WAKEUP_QUEUE,
65 // Must be the last entry. 65 // Must be the last entry.
66 TASK_QUEUE_COUNT, 66 TASK_QUEUE_COUNT,
67 }; 67 };
68 68
69 // Keep RendererSchedulerImpl::PolicyToString in sync with this enum.
Sami 2015/03/05 16:22:32 Thanks for adding these reminders.
rmcilroy 2015/03/05 16:42:38 Acknowledged.
69 enum class Policy { 70 enum class Policy {
70 NORMAL, 71 NORMAL,
71 COMPOSITOR_PRIORITY, 72 COMPOSITOR_PRIORITY,
72 TOUCHSTART_PRIORITY, 73 TOUCHSTART_PRIORITY,
73 }; 74 };
74 75
76 // Keep RendererSchedulerImpl::InputStreamStateToString in sync with this
77 // enum.
75 enum class InputStreamState { 78 enum class InputStreamState {
76 INACTIVE, 79 INACTIVE,
77 ACTIVE, 80 ACTIVE,
78 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE 81 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
79 }; 82 };
80 83
84 // Keep RendererSchedulerImpl::IdlePeriodStateToString in sync with this enum.
85 enum class IdlePeriodState {
86 NOT_IN_IDLE_PERIOD,
87 IN_SHORT_IDLE_PERIOD,
88 IN_LONG_IDLE_PERIOD,
89 IN_LONG_IDLE_WITH_MAX_DEADLINE_PERIOD,
Sami 2015/03/05 16:22:32 nit: IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE reads a
rmcilroy 2015/03/05 16:42:38 Done.
90 ENDING_LONG_IDLE_PERIOD
91 };
92
81 class PollableNeedsUpdateFlag { 93 class PollableNeedsUpdateFlag {
82 public: 94 public:
83 PollableNeedsUpdateFlag(base::Lock* write_lock); 95 PollableNeedsUpdateFlag(base::Lock* write_lock);
84 ~PollableNeedsUpdateFlag(); 96 ~PollableNeedsUpdateFlag();
85 97
86 // Set the flag. May only be called if |write_lock| is held. 98 // Set the flag. May only be called if |write_lock| is held.
87 void SetWhileLocked(bool value); 99 void SetWhileLocked(bool value);
88 100
89 // Returns true iff the flag is set to true. 101 // Returns true iff the flag is set to true.
90 bool IsSet() const; 102 bool IsSet() const;
91 103
92 private: 104 private:
93 base::subtle::Atomic32 flag_; 105 base::subtle::Atomic32 flag_;
94 base::Lock* write_lock_; // Not owned. 106 base::Lock* write_lock_; // Not owned.
95 107
96 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag); 108 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag);
97 }; 109 };
98 110
99 // Returns the serialized scheduler state for tracing. 111 // Returns the serialized scheduler state for tracing.
100 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 112 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
101 base::TimeTicks optional_now) const; 113 base::TimeTicks optional_now) const;
102 static const char* TaskQueueIdToString(QueueId queue_id); 114 static const char* TaskQueueIdToString(QueueId queue_id);
103 static const char* PolicyToString(Policy policy); 115 static const char* PolicyToString(Policy policy);
104 static const char* InputStreamStateToString(InputStreamState state); 116 static const char* InputStreamStateToString(InputStreamState state);
117 static const char* IdlePeriodStateToString(IdlePeriodState state);
105 118
106 static InputStreamState ComputeNewInputStreamState( 119 static InputStreamState ComputeNewInputStreamState(
107 InputStreamState current_state, 120 InputStreamState current_state,
108 blink::WebInputEvent::Type new_input_event, 121 blink::WebInputEvent::Type new_input_event,
109 blink::WebInputEvent::Type last_input_event); 122 blink::WebInputEvent::Type last_input_event);
110 123
111 // The time we should stay in a priority-escalated mode after an input event. 124 // The time we should stay in a priority-escalated mode after an input event.
112 static const int kPriorityEscalationAfterInputMillis = 100; 125 static const int kPriorityEscalationAfterInputMillis = 100;
113 126
127 // The maximum length of an idle period.
128 static const int kMaximumIdlePeriodMillis = 50;
129
130 // The minimum delay to wait between retrying to initiate a long idle time.
131 static const int kRetryInitiateLongIdlePeriodDelayMillis = 1;
132
114 // IdleTaskDeadlineSupplier Implementation: 133 // IdleTaskDeadlineSupplier Implementation:
115 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; 134 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
116 135
117 // Returns the current scheduler policy. Must be called from the main thread. 136 // Returns the current scheduler policy. Must be called from the main thread.
118 Policy SchedulerPolicy() const; 137 Policy SchedulerPolicy() const;
119 138
120 // Posts a call to UpdatePolicy on the control runner to be run after |delay| 139 // Posts a call to UpdatePolicy on the control runner to be run after |delay|
121 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); 140 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay);
122 141
123 // Update the policy if a new signal has arrived. Must be called from the main 142 // Update the policy if a new signal has arrived. Must be called from the main
124 // thread. 143 // thread.
125 void MaybeUpdatePolicy(); 144 void MaybeUpdatePolicy();
126 145
127 // Updates the scheduler policy. Must be called from the main thread. 146 // Updates the scheduler policy. Must be called from the main thread.
128 void UpdatePolicy(); 147 void UpdatePolicy();
129 148
149 // Returns the amount of time left in the current input escalated priority
150 // policy.
151 base::TimeDelta TimeLeftInInputEscalatedPolicy() const;
152
130 // Helper for computing the new policy. |new_policy_duration| will be filled 153 // Helper for computing the new policy. |new_policy_duration| will be filled
131 // with the amount of time after which the policy should be updated again. If 154 // with the amount of time after which the policy should be updated again. If
132 // the duration is zero, a new policy update will not be scheduled. Must be 155 // the duration is zero, a new policy update will not be scheduled. Must be
133 // called with |incoming_signals_lock_| held. 156 // called with |incoming_signals_lock_| held.
134 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration); 157 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration);
135 158
136 // An input event of some sort happened, the policy may need updating. 159 // An input event of some sort happened, the policy may need updating.
137 void UpdateForInputEvent(blink::WebInputEvent::Type type); 160 void UpdateForInputEvent(blink::WebInputEvent::Type type);
138 161
139 // Called when a previously queued input event was processed. 162 // Called when a previously queued input event was processed.
140 // |begin_frame_time|, if non-zero, identifies the frame time at which the 163 // |begin_frame_time|, if non-zero, identifies the frame time at which the
141 // input was processed. 164 // input was processed.
142 void DidProcessInputEvent(base::TimeTicks begin_frame_time); 165 void DidProcessInputEvent(base::TimeTicks begin_frame_time);
143 166
167 // Returns the new idle period state for the next long idle period. Fills in
168 // |next_long_idle_period_delay_out| with the next time we should try to
169 // initiate the next idle period.
170 IdlePeriodState ComputeNewLongIdlePeriodState(
171 const base::TimeTicks now,
172 base::TimeDelta* next_long_idle_period_delay_out);
173
174 // Initiate a long idle period.
175 void InitiateLongIdlePeriod();
176 void InitiateLongIdlePeriodAfterWakeup();
177
144 // Start and end an idle period. 178 // Start and end an idle period.
145 void StartIdlePeriod(); 179 void StartIdlePeriod(IdlePeriodState new_idle_period_state);
146 void EndIdlePeriod(); 180 void EndIdlePeriod();
147 181
182 // Returns true if |state| represents being within an idle period state.
183 static bool IsInIdlePeriod(IdlePeriodState state);
184
148 base::TimeTicks Now() const; 185 base::TimeTicks Now() const;
149 186
150 base::ThreadChecker main_thread_checker_; 187 base::ThreadChecker main_thread_checker_;
151 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; 188 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
152 scoped_ptr<TaskQueueManager> task_queue_manager_; 189 scoped_ptr<TaskQueueManager> task_queue_manager_;
153 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 190 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
154 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; 191 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
155 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 192 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
156 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 193 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
157 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 194 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
158 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 195 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
159 196
160 base::Closure update_policy_closure_; 197 base::Closure update_policy_closure_;
161 CancelableClosureHolder end_idle_period_closure_; 198 CancelableClosureHolder end_idle_period_closure_;
199 CancelableClosureHolder initiate_next_long_idle_period_closure_;
200 CancelableClosureHolder initiate_next_long_idle_period_after_wakeup_closure_;
162 201
163 // Don't access current_policy_ directly, instead use SchedulerPolicy(). 202 // Don't access current_policy_ directly, instead use SchedulerPolicy().
164 Policy current_policy_; 203 Policy current_policy_;
204 IdlePeriodState idle_period_state_;
165 205
166 base::TimeTicks estimated_next_frame_begin_; 206 base::TimeTicks estimated_next_frame_begin_;
207 base::TimeTicks current_policy_expiration_time_;
167 208
168 // The incoming_signals_lock_ mutex protects access to all variables in the 209 // The incoming_signals_lock_ mutex protects access to all variables in the
169 // (contiguous) block below. 210 // (contiguous) block below.
170 base::Lock incoming_signals_lock_; 211 base::Lock incoming_signals_lock_;
171 base::TimeTicks last_input_receipt_time_on_compositor_; 212 base::TimeTicks last_input_receipt_time_on_compositor_;
172 base::TimeTicks last_input_process_time_on_main_; 213 base::TimeTicks last_input_process_time_on_main_;
173 blink::WebInputEvent::Type last_input_type_; 214 blink::WebInputEvent::Type last_input_type_;
174 InputStreamState input_stream_state_; 215 InputStreamState input_stream_state_;
175 PollableNeedsUpdateFlag policy_may_need_update_; 216 PollableNeedsUpdateFlag policy_may_need_update_;
176 217
177 scoped_refptr<cc::TestNowSource> time_source_; 218 scoped_refptr<cc::TestNowSource> time_source_;
178 219
179 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; 220 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
180 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 221 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
181 222
182 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 223 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
183 }; 224 };
184 225
185 } // namespace content 226 } // namespace content
186 227
187 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 228 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698