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

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

Issue 2778123003: [scheduler] Add WakeupBudgetPool. (Closed)
Patch Set: Addressed comments from alexclarke@ Created 3 years, 7 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 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_CPU_TIME_BUDGET_PO OL_H_
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_ 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_CPU_TIME_BUDGET_PO OL_H_
7 7
8 #include <unordered_set> 8 #include "platform/scheduler/renderer/budget_pool.h"
9 9
10 #include "base/callback.h"
11 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "base/optional.h" 12 #include "base/optional.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "platform/scheduler/base/lazy_now.h" 14 #include "platform/scheduler/base/lazy_now.h"
16 15
17 namespace base {
18 namespace trace_event {
19 class TracedValue;
20 }
21 }
22
23 namespace blink { 16 namespace blink {
24 namespace scheduler { 17 namespace scheduler {
25 18
26 class TaskQueue;
27 class BudgetPoolController;
28
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
31 // by TaskQueueThrottler.
32 class BLINK_PLATFORM_EXPORT BudgetPool {
33 public:
34 virtual ~BudgetPool();
35
36 const char* Name() const;
37
38 // Report task run time to the budget pool.
39 virtual void RecordTaskRunTime(base::TimeTicks start_time,
40 base::TimeTicks end_time) = 0;
41
42 // Retuns earliest time (can be in the past) when the next task can run.
43 virtual base::TimeTicks GetNextAllowedRunTime() = 0;
44
45 // Returns true at a task can be run immediately at the given time.
46 virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0;
47
48 // Returns state for tracing.
49 virtual void AsValueInto(base::trace_event::TracedValue* state,
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_;
89 };
90
91 // CPUTimeBudgetPool represents a collection of task queues which share a limit 19 // CPUTimeBudgetPool represents a collection of task queues which share a limit
92 // on total cpu time. 20 // on total cpu time.
93 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool { 21 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool {
94 public: 22 public:
95 CPUTimeBudgetPool(const char* name, 23 CPUTimeBudgetPool(const char* name,
96 BudgetPoolController* budget_pool_controller, 24 BudgetPoolController* budget_pool_controller,
97 base::TimeTicks now); 25 base::TimeTicks now);
98 26
99 ~CPUTimeBudgetPool(); 27 ~CPUTimeBudgetPool();
100 28
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // queues even if they are allowed to run with increased budget level. 63 // queues even if they are allowed to run with increased budget level.
136 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level); 64 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level);
137 65
138 // Set callback which will be called every time when this budget pool 66 // Set callback which will be called every time when this budget pool
139 // is throttled. Throttling duration (time until the queue is allowed 67 // is throttled. Throttling duration (time until the queue is allowed
140 // to run again) is passed as a parameter to callback. 68 // to run again) is passed as a parameter to callback.
141 void SetReportingCallback( 69 void SetReportingCallback(
142 base::Callback<void(base::TimeDelta)> reporting_callback); 70 base::Callback<void(base::TimeDelta)> reporting_callback);
143 71
144 // BudgetPool implementation: 72 // BudgetPool implementation:
145 void RecordTaskRunTime(base::TimeTicks start_time, 73 void RecordTaskRunTime(TaskQueue* queue,
74 base::TimeTicks start_time,
146 base::TimeTicks end_time) final; 75 base::TimeTicks end_time) final;
147 bool HasEnoughBudgetToRun(base::TimeTicks now) final; 76 bool CanRunTasksUntil(base::TimeTicks now, base::TimeTicks until) const final;
148 base::TimeTicks GetNextAllowedRunTime() final; 77 bool CanRunTasksAt(base::TimeTicks now, bool is_wake_up) const final;
78 base::TimeTicks GetNextAllowedRunTime(
79 base::TimeTicks desired_run_time) const final;
80 void OnQueueNextWakeUpChanged(TaskQueue* queue,
81 base::TimeTicks now,
82 base::TimeTicks desired_run_time) final;
83 void OnWakeUp(base::TimeTicks now) final;
149 void AsValueInto(base::trace_event::TracedValue* state, 84 void AsValueInto(base::trace_event::TracedValue* state,
150 base::TimeTicks now) const final; 85 base::TimeTicks now) const final;
151 86
87 protected:
88 QueueBlockType GetBlockType() const final;
89
152 private: 90 private:
153 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool); 91 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool);
154 92
155 // Advances |last_checkpoint_| to |now| if needed and recalculates 93 // Advances |last_checkpoint_| to |now| if needed and recalculates
156 // budget level. 94 // budget level.
157 void Advance(base::TimeTicks now); 95 void Advance(base::TimeTicks now);
158 96
159 // Increase |current_budget_level_| to satisfy max throttling duration 97 // Increase |current_budget_level_| to satisfy max throttling duration
160 // condition if necessary. 98 // condition if necessary.
161 // Decrease |current_budget_level_| to satisfy max budget level 99 // Decrease |current_budget_level_| to satisfy max budget level
(...skipping 18 matching lines...) Expand all
180 double cpu_percentage_; 118 double cpu_percentage_;
181 119
182 base::Callback<void(base::TimeDelta)> reporting_callback_; 120 base::Callback<void(base::TimeDelta)> reporting_callback_;
183 121
184 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool); 122 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool);
185 }; 123 };
186 124
187 } // namespace scheduler 125 } // namespace scheduler
188 } // namespace blink 126 } // namespace blink
189 127
190 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_ 128 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_CPU_TIME_BUDGET _POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698