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

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

Issue 2412323003: [scheduler] Support setting maximal throttling duration (Closed)
Patch Set: Created 4 years, 2 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 | third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.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 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_THROTTLING_HELPER_ H_ 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_ H_
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_ H_ 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELPER_ H_
7 7
8 #include <set> 8 #include <set>
9 #include <unordered_map> 9 #include <unordered_map>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // Adds |queue| to given pool. If the pool restriction does not allow 62 // Adds |queue| to given pool. If the pool restriction does not allow
63 // a task to be run immediately and |queue| is throttled, |queue| becomes 63 // a task to be run immediately and |queue| is throttled, |queue| becomes
64 // disabled. 64 // disabled.
65 void AddQueue(base::TimeTicks now, TaskQueue* queue); 65 void AddQueue(base::TimeTicks now, TaskQueue* queue);
66 66
67 // Removes |queue| from given pool. If it is throttled, it does not 67 // Removes |queue| from given pool. If it is throttled, it does not
68 // become enabled immediately, but a call to |PumpThrottledTasks| 68 // become enabled immediately, but a call to |PumpThrottledTasks|
69 // is scheduled. 69 // is scheduled.
70 void RemoveQueue(base::TimeTicks now, TaskQueue* queue); 70 void RemoveQueue(base::TimeTicks now, TaskQueue* queue);
71 71
72 void RecordTaskRunTime(base::TimeDelta task_run_time); 72 void RecordTaskRunTime(base::TimeTicks start_time,
73 base::TimeTicks end_time);
73 74
74 // Enables this time budget pool. Queues from this pool will be 75 // Enables this time budget pool. Queues from this pool will be
75 // throttled based on their run time. 76 // throttled based on their run time.
76 void EnableThrottling(LazyNow* now); 77 void EnableThrottling(LazyNow* now);
77 78
78 // Disables with time budget pool. Queues from this pool will not be 79 // Disables with time budget pool. Queues from this pool will not be
79 // throttled based on their run time. A call to |PumpThrottledTasks| 80 // throttled based on their run time. A call to |PumpThrottledTasks|
80 // will be scheduled to enable this queues back again and respect 81 // will be scheduled to enable this queues back again and respect
81 // timer alignment. Internal budget level will not regenerate with time. 82 // timer alignment. Internal budget level will not regenerate with time.
82 void DisableThrottling(LazyNow* now); 83 void DisableThrottling(LazyNow* now);
83 84
84 bool IsThrottlingEnabled() const; 85 bool IsThrottlingEnabled() const;
85 86
86 const char* Name() const; 87 const char* Name() const;
87 88
88 // All queues should be removed before calling Close(). 89 // All queues should be removed before calling Close().
89 void Close(); 90 void Close();
90 91
91 private: 92 private:
92 friend class TaskQueueThrottler; 93 friend class TaskQueueThrottler;
93 94
94 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, TimeBudgetPool); 95 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, TimeBudgetPool);
95 96
96 TimeBudgetPool(const char* name, 97 TimeBudgetPool(const char* name,
97 TaskQueueThrottler* task_queue_throttler, 98 TaskQueueThrottler* task_queue_throttler,
98 base::TimeTicks now); 99 base::TimeTicks now,
100 base::Optional<base::TimeDelta> max_budget_level,
101 base::Optional<base::TimeDelta> max_throttling_duration);
99 102
100 bool HasEnoughBudgetToRun(base::TimeTicks now); 103 bool HasEnoughBudgetToRun(base::TimeTicks now);
101 base::TimeTicks GetNextAllowedRunTime(); 104 base::TimeTicks GetNextAllowedRunTime();
102 105
103 // Advances |last_checkpoint_| to |now| if needed and recalculates 106 // Advances |last_checkpoint_| to |now| if needed and recalculates
104 // budget level. 107 // budget level.
105 void Advance(base::TimeTicks now); 108 void Advance(base::TimeTicks now);
106 109
107 // Returns state for tracing. 110 // Returns state for tracing.
108 void AsValueInto(base::trace_event::TracedValue* state, 111 void AsValueInto(base::trace_event::TracedValue* state,
109 base::TimeTicks now) const; 112 base::TimeTicks now) const;
110 113
111 // Disable all associated throttled queues. 114 // Disable all associated throttled queues.
112 void BlockThrottledQueues(base::TimeTicks now); 115 void BlockThrottledQueues(base::TimeTicks now);
113 116
117 // Increase current_budget_level_ to satisfy max throttling duration
118 // condition if necessary.
119 void EnforceMaximalThrottlingDuration();
120
114 const char* name_; // NOT OWNED 121 const char* name_; // NOT OWNED
115 122
116 TaskQueueThrottler* task_queue_throttler_; 123 TaskQueueThrottler* task_queue_throttler_;
117 124
125 // Max budget level is the maximal amount of time which the time budget pool
126 // is allowed to run for after a very long period of inactivity.
Sami 2016/10/14 00:33:02 Hmm, is this the maximum budget we can accrue? Thi
altimin 2016/10/14 16:18:55 Rephrased.
127 base::Optional<base::TimeDelta> max_budget_level_;
128 // Max throttling duration is the amount of time after which the task will
Sami 2016/10/14 00:33:02 Would it be simpler to say this is the maximum del
altimin 2016/10/14 16:18:55 No. In fact, it's just a lower bound on time budge
129 // be run after a very long period of full activity.
130 base::Optional<base::TimeDelta> max_throttling_duration_;
131
118 base::TimeDelta current_budget_level_; 132 base::TimeDelta current_budget_level_;
119 base::TimeDelta max_budget_level_;
120 base::TimeTicks last_checkpoint_; 133 base::TimeTicks last_checkpoint_;
121 double cpu_percentage_; 134 double cpu_percentage_;
122 bool is_enabled_; 135 bool is_enabled_;
123 136
124 std::unordered_set<TaskQueue*> associated_task_queues_; 137 std::unordered_set<TaskQueue*> associated_task_queues_;
125 138
126 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); 139 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool);
127 }; 140 };
128 141
129 // TODO(altimin): Do not pass tracing category as const char*, 142 // TODO(altimin): Do not pass tracing category as const char*,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); 242 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it);
230 243
231 TaskQueueMap queue_details_; 244 TaskQueueMap queue_details_;
232 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; 245 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_;
233 scoped_refptr<TaskQueue> task_runner_; 246 scoped_refptr<TaskQueue> task_runner_;
234 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED 247 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED
235 base::TickClock* tick_clock_; // NOT OWNED 248 base::TickClock* tick_clock_; // NOT OWNED
236 const char* tracing_category_; // NOT OWNED 249 const char* tracing_category_; // NOT OWNED
237 std::unique_ptr<ThrottledTimeDomain> time_domain_; 250 std::unique_ptr<ThrottledTimeDomain> time_domain_;
238 251
252 base::Optional<base::TimeDelta> max_budget_level_;
253 base::Optional<base::TimeDelta> max_throttling_duration_;
254
239 CancelableClosureHolder pump_throttled_tasks_closure_; 255 CancelableClosureHolder pump_throttled_tasks_closure_;
240 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; 256 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_;
241 bool virtual_time_; 257 bool virtual_time_;
242 258
243 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> 259 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>>
244 time_budget_pools_; 260 time_budget_pools_;
245 261
246 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; 262 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_;
247 263
248 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); 264 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler);
249 }; 265 };
250 266
251 } // namespace scheduler 267 } // namespace scheduler
252 } // namespace blink 268 } // namespace blink
253 269
254 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_ 270 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP ER_H_
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/scheduler/renderer/task_queue_throttler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698