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

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

Issue 2778743004: [scheduler] Refactor common code into BudgetPool. (Closed)
Patch Set: Created 3 years, 8 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/budget_pool.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_BUDGET_POOL_H_ 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_ 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_
7 7
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 15 matching lines...) Expand all
26 class TaskQueue; 26 class TaskQueue;
27 class BudgetPoolController; 27 class BudgetPoolController;
28 28
29 // BudgetPool represents a group of task queues which share a limit 29 // BudgetPool represents a group of task queues which share a limit
30 // on a resource. This limit applies when task queues are already throttled 30 // on a resource. This limit applies when task queues are already throttled
31 // by TaskQueueThrottler. 31 // by TaskQueueThrottler.
32 class BLINK_PLATFORM_EXPORT BudgetPool { 32 class BLINK_PLATFORM_EXPORT BudgetPool {
33 public: 33 public:
34 virtual ~BudgetPool(); 34 virtual ~BudgetPool();
35 35
36 virtual const char* Name() const = 0; 36 const char* Name() const;
37
38 // Adds |queue| to given pool. If the pool restriction does not allow
39 // a task to be run immediately and |queue| is throttled, |queue| becomes
40 // disabled.
41 virtual void AddQueue(base::TimeTicks now, TaskQueue* queue) = 0;
42
43 // Removes |queue| from given pool. If it is throttled, it does not
44 // become enabled immediately, but a call to |PumpThrottledTasks|
45 // is scheduled.
46 virtual void RemoveQueue(base::TimeTicks now, TaskQueue* queue) = 0;
47
48 // Enables this time budget pool. Queues from this pool will be
49 // throttled based on their run time.
50 virtual void EnableThrottling(LazyNow* now) = 0;
51
52 // Disables with time budget pool. Queues from this pool will not be
53 // throttled based on their run time. A call to |PumpThrottledTasks|
54 // will be scheduled to enable this queues back again and respect
55 // timer alignment. Internal budget level will not regenerate with time.
56 virtual void DisableThrottling(LazyNow* now) = 0;
57
58 virtual bool IsThrottlingEnabled() const = 0;
59 37
60 // Report task run time to the budget pool. 38 // Report task run time to the budget pool.
61 virtual void RecordTaskRunTime(base::TimeTicks start_time, 39 virtual void RecordTaskRunTime(base::TimeTicks start_time,
62 base::TimeTicks end_time) = 0; 40 base::TimeTicks end_time) = 0;
63 41
64 // Block all associated queues and schedule them to run when appropriate.
65 virtual void BlockThrottledQueues(base::TimeTicks now) = 0;
66
67 // All queues should be removed before calling Close().
68 virtual void Close() = 0;
69
70 // Retuns earliest time (can be in the past) when the next task can run. 42 // Retuns earliest time (can be in the past) when the next task can run.
71 virtual base::TimeTicks GetNextAllowedRunTime() = 0; 43 virtual base::TimeTicks GetNextAllowedRunTime() = 0;
72 44
73 // Returns true at a task can be run immediately at the given time. 45 // Returns true at a task can be run immediately at the given time.
74 virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0; 46 virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0;
75 47
76 // Returns state for tracing. 48 // Returns state for tracing.
77 virtual void AsValueInto(base::trace_event::TracedValue* state, 49 virtual void AsValueInto(base::trace_event::TracedValue* state,
78 base::TimeTicks now) const = 0; 50 base::TimeTicks now) const = 0;
51
52 // Adds |queue| to given pool. If the pool restriction does not allow
53 // a task to be run immediately and |queue| is throttled, |queue| becomes
54 // disabled.
55 void AddQueue(base::TimeTicks now, TaskQueue* queue);
56
57 // Removes |queue| from given pool. If it is throttled, it does not
58 // become enabled immediately, but a call to |PumpThrottledTasks|
59 // is scheduled.
60 void RemoveQueue(base::TimeTicks now, TaskQueue* queue);
61
62 // Enables this time budget pool. Queues from this pool will be
63 // throttled based on their run time.
64 void EnableThrottling(LazyNow* now);
65
66 // Disables with time budget pool. Queues from this pool will not be
67 // throttled based on their run time. A call to |PumpThrottledTasks|
68 // will be scheduled to enable this queues back again and respect
69 // timer alignment. Internal budget level will not regenerate with time.
70 void DisableThrottling(LazyNow* now);
71
72 bool IsThrottlingEnabled() const;
73
74 // All queues should be removed before calling Close().
75 void Close();
76
77 // Block all associated queues and schedule them to run when appropriate.
78 void BlockThrottledQueues(base::TimeTicks now);
79
80 protected:
81 BudgetPool(const char* name, BudgetPoolController* budget_pool_controller);
82
83 const char* name_; // NOT OWNED
84
85 BudgetPoolController* budget_pool_controller_;
86
87 std::unordered_set<TaskQueue*> associated_task_queues_;
88 bool is_enabled_;
79 }; 89 };
80 90
81 // CPUTimeBudgetPool represents a collection of task queues which share a limit 91 // CPUTimeBudgetPool represents a collection of task queues which share a limit
82 // on total cpu time. 92 // on total cpu time.
83 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool { 93 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool {
84 public: 94 public:
85 CPUTimeBudgetPool(const char* name, 95 CPUTimeBudgetPool(const char* name,
86 BudgetPoolController* budget_pool_controller, 96 BudgetPoolController* budget_pool_controller,
87 base::TimeTicks now); 97 base::TimeTicks now);
88 98
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // queues even if they are allowed to run with increased budget level. 135 // queues even if they are allowed to run with increased budget level.
126 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level); 136 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level);
127 137
128 // Set callback which will be called every time when this budget pool 138 // Set callback which will be called every time when this budget pool
129 // is throttled. Throttling duration (time until the queue is allowed 139 // is throttled. Throttling duration (time until the queue is allowed
130 // to run again) is passed as a parameter to callback. 140 // to run again) is passed as a parameter to callback.
131 void SetReportingCallback( 141 void SetReportingCallback(
132 base::Callback<void(base::TimeDelta)> reporting_callback); 142 base::Callback<void(base::TimeDelta)> reporting_callback);
133 143
134 // BudgetPool implementation: 144 // BudgetPool implementation:
135 const char* Name() const override;
136 void AddQueue(base::TimeTicks now, TaskQueue* queue) override;
137 void RemoveQueue(base::TimeTicks now, TaskQueue* queue) override;
138 void EnableThrottling(LazyNow* now) override;
139 void DisableThrottling(LazyNow* now) override;
140 bool IsThrottlingEnabled() const override;
141 void RecordTaskRunTime(base::TimeTicks start_time, 145 void RecordTaskRunTime(base::TimeTicks start_time,
142 base::TimeTicks end_time) override; 146 base::TimeTicks end_time) final;
143 void BlockThrottledQueues(base::TimeTicks now) override; 147 bool HasEnoughBudgetToRun(base::TimeTicks now) final;
144 void Close() override; 148 base::TimeTicks GetNextAllowedRunTime() final;
145 bool HasEnoughBudgetToRun(base::TimeTicks now) override;
146 base::TimeTicks GetNextAllowedRunTime() override;
147 void AsValueInto(base::trace_event::TracedValue* state, 149 void AsValueInto(base::trace_event::TracedValue* state,
148 base::TimeTicks now) const override; 150 base::TimeTicks now) const final;
149 151
150 private: 152 private:
151 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool); 153 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool);
152 154
153 // Advances |last_checkpoint_| to |now| if needed and recalculates 155 // Advances |last_checkpoint_| to |now| if needed and recalculates
154 // budget level. 156 // budget level.
155 void Advance(base::TimeTicks now); 157 void Advance(base::TimeTicks now);
156 158
157 // Increase |current_budget_level_| to satisfy max throttling duration 159 // Increase |current_budget_level_| to satisfy max throttling duration
158 // condition if necessary. 160 // condition if necessary.
159 // Decrease |current_budget_level_| to satisfy max budget level 161 // Decrease |current_budget_level_| to satisfy max budget level
160 // condition if necessary. 162 // condition if necessary.
161 void EnforceBudgetLevelRestrictions(); 163 void EnforceBudgetLevelRestrictions();
162 164
163 const char* name_; // NOT OWNED
164
165 BudgetPoolController* budget_pool_controller_;
166
167 // Max budget level which we can accrue. 165 // Max budget level which we can accrue.
168 // Tasks will be allowed to run for this time before being throttled 166 // Tasks will be allowed to run for this time before being throttled
169 // after a very long period of inactivity. 167 // after a very long period of inactivity.
170 base::Optional<base::TimeDelta> max_budget_level_; 168 base::Optional<base::TimeDelta> max_budget_level_;
171 // Max throttling delay places a lower limit on time budget level, 169 // Max throttling delay places a lower limit on time budget level,
172 // ensuring that one long task does not cause extremely long throttling. 170 // ensuring that one long task does not cause extremely long throttling.
173 // Note that this is not a guarantee that every task will run 171 // Note that this is not a guarantee that every task will run
174 // after desired run time + max throttling duration, but a guarantee 172 // after desired run time + max throttling duration, but a guarantee
175 // that at least one task will be run every max_throttling_delay. 173 // that at least one task will be run every max_throttling_delay.
176 base::Optional<base::TimeDelta> max_throttling_delay_; 174 base::Optional<base::TimeDelta> max_throttling_delay_;
177 // See CPUTimeBudgetPool::SetMinBudgetLevelToRun. 175 // See CPUTimeBudgetPool::SetMinBudgetLevelToRun.
178 base::TimeDelta min_budget_level_to_run_; 176 base::TimeDelta min_budget_level_to_run_;
179 177
180 base::TimeDelta current_budget_level_; 178 base::TimeDelta current_budget_level_;
181 base::TimeTicks last_checkpoint_; 179 base::TimeTicks last_checkpoint_;
182 double cpu_percentage_; 180 double cpu_percentage_;
183 bool is_enabled_;
184
185 std::unordered_set<TaskQueue*> associated_task_queues_;
186 181
187 base::Callback<void(base::TimeDelta)> reporting_callback_; 182 base::Callback<void(base::TimeDelta)> reporting_callback_;
188 183
189 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool); 184 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool);
190 }; 185 };
191 186
192 } // namespace scheduler 187 } // namespace scheduler
193 } // namespace blink 188 } // namespace blink
194 189
195 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_ 190 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698