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

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

Issue 2742383005: [scheduler] Untangle BudgetPool from TaskQueueThrottler. (Closed)
Patch Set: Created 3 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 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // will be scheduled to enable this queues back again and respect 54 // will be scheduled to enable this queues back again and respect
55 // timer alignment. Internal budget level will not regenerate with time. 55 // timer alignment. Internal budget level will not regenerate with time.
56 virtual void DisableThrottling(LazyNow* now) = 0; 56 virtual void DisableThrottling(LazyNow* now) = 0;
57 57
58 virtual bool IsThrottlingEnabled() const = 0; 58 virtual bool IsThrottlingEnabled() const = 0;
59 59
60 // Report task run time to the budget pool. 60 // Report task run time to the budget pool.
61 virtual void RecordTaskRunTime(base::TimeTicks start_time, 61 virtual void RecordTaskRunTime(base::TimeTicks start_time,
62 base::TimeTicks end_time) = 0; 62 base::TimeTicks end_time) = 0;
63 63
64 // Call TaskQueueThrottler::BlockThrottledQueue for all relevant queues.
Sami 2017/03/14 18:43:00 This is an abstract interface with no obvious ties
altimin 2017/03/14 20:04:28 Done.
65 virtual void BlockThrottledQueues(base::TimeTicks now) = 0;
66
64 // All queues should be removed before calling Close(). 67 // All queues should be removed before calling Close().
65 virtual void Close() = 0; 68 virtual void Close() = 0;
66 69
67 // Retuns earliest time (can be in the past) when the next task can run. 70 // Retuns earliest time (can be in the past) when the next task can run.
68 virtual base::TimeTicks GetNextAllowedRunTime() = 0; 71 virtual base::TimeTicks GetNextAllowedRunTime() = 0;
69 72
70 // Returns true at a task can be run immediately at the given time. 73 // Returns true at a task can be run immediately at the given time.
71 virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0; 74 virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0;
72 75
73 // Returns state for tracing. 76 // Returns state for tracing.
74 virtual void AsValueInto(base::trace_event::TracedValue* state, 77 virtual void AsValueInto(base::trace_event::TracedValue* state,
75 base::TimeTicks now) const = 0; 78 base::TimeTicks now) const = 0;
76 }; 79 };
77 80
78 // CPUTimeBudgetPool represents a collection of task queues which share a limit 81 // CPUTimeBudgetPool represents a collection of task queues which share a limit
79 // on total cpu time. 82 // on total cpu time.
80 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool { 83 class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool {
81 public: 84 public:
85 CPUTimeBudgetPool(const char* name,
86 TaskQueueThrottler* task_queue_throttler,
87 base::TimeTicks now,
88 base::Optional<base::TimeDelta> max_budget_level,
89 base::Optional<base::TimeDelta> max_throttling_duration);
90
82 ~CPUTimeBudgetPool(); 91 ~CPUTimeBudgetPool();
83 92
84 // Throttle task queues from this time budget pool if tasks are running 93 // Throttle task queues from this time budget pool if tasks are running
85 // for more than |cpu_percentage| per cent of wall time. 94 // for more than |cpu_percentage| per cent of wall time.
86 // This function does not affect internal time budget level. 95 // This function does not affect internal time budget level.
87 void SetTimeBudgetRecoveryRate(base::TimeTicks now, double cpu_percentage); 96 void SetTimeBudgetRecoveryRate(base::TimeTicks now, double cpu_percentage);
88 97
89 // Increase budget level by given value. This function DOES NOT unblock 98 // Increase budget level by given value. This function DOES NOT unblock
90 // queues even if they are allowed to run with increased budget level. 99 // queues even if they are allowed to run with increased budget level.
91 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level); 100 void GrantAdditionalBudget(base::TimeTicks now, base::TimeDelta budget_level);
92 101
93 // Set callback which will be called every time when this budget pool 102 // Set callback which will be called every time when this budget pool
94 // is throttled. Throttling duration (time until the queue is allowed 103 // is throttled. Throttling duration (time until the queue is allowed
95 // to run again) is passed as a parameter to callback. 104 // to run again) is passed as a parameter to callback.
96 void SetReportingCallback( 105 void SetReportingCallback(
97 base::Callback<void(base::TimeDelta)> reporting_callback); 106 base::Callback<void(base::TimeDelta)> reporting_callback);
98 107
99 // BudgetPool implementation: 108 // BudgetPool implementation:
100 const char* Name() const override; 109 const char* Name() const override;
101 void AddQueue(base::TimeTicks now, TaskQueue* queue) override; 110 void AddQueue(base::TimeTicks now, TaskQueue* queue) override;
102 void RemoveQueue(base::TimeTicks now, TaskQueue* queue) override; 111 void RemoveQueue(base::TimeTicks now, TaskQueue* queue) override;
103 void EnableThrottling(LazyNow* now) override; 112 void EnableThrottling(LazyNow* now) override;
104 void DisableThrottling(LazyNow* now) override; 113 void DisableThrottling(LazyNow* now) override;
105 bool IsThrottlingEnabled() const override; 114 bool IsThrottlingEnabled() const override;
106 void RecordTaskRunTime(base::TimeTicks start_time, 115 void RecordTaskRunTime(base::TimeTicks start_time,
107 base::TimeTicks end_time) override; 116 base::TimeTicks end_time) override;
117 void BlockThrottledQueues(base::TimeTicks now) override;
108 void Close() override; 118 void Close() override;
109 bool HasEnoughBudgetToRun(base::TimeTicks now) override; 119 bool HasEnoughBudgetToRun(base::TimeTicks now) override;
110 base::TimeTicks GetNextAllowedRunTime() override; 120 base::TimeTicks GetNextAllowedRunTime() override;
111 void AsValueInto(base::trace_event::TracedValue* state, 121 void AsValueInto(base::trace_event::TracedValue* state,
112 base::TimeTicks now) const override; 122 base::TimeTicks now) const override;
113 123
114 private: 124 private:
115 friend class TaskQueueThrottler;
116
117 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool); 125 FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool);
118 126
119 CPUTimeBudgetPool(const char* name,
120 TaskQueueThrottler* task_queue_throttler,
121 base::TimeTicks now,
122 base::Optional<base::TimeDelta> max_budget_level,
123 base::Optional<base::TimeDelta> max_throttling_duration);
124
125 // Advances |last_checkpoint_| to |now| if needed and recalculates 127 // Advances |last_checkpoint_| to |now| if needed and recalculates
126 // budget level. 128 // budget level.
127 void Advance(base::TimeTicks now); 129 void Advance(base::TimeTicks now);
128 130
129 // Disable all associated throttled queues.
130 void BlockThrottledQueues(base::TimeTicks now);
131
132 // Increase |current_budget_level_| to satisfy max throttling duration 131 // Increase |current_budget_level_| to satisfy max throttling duration
133 // condition if necessary. 132 // condition if necessary.
134 // Decrease |current_budget_level_| to satisfy max budget level 133 // Decrease |current_budget_level_| to satisfy max budget level
135 // condition if necessary. 134 // condition if necessary.
136 void EnforceBudgetLevelRestrictions(); 135 void EnforceBudgetLevelRestrictions();
137 136
138 const char* name_; // NOT OWNED 137 const char* name_; // NOT OWNED
139 138
140 TaskQueueThrottler* task_queue_throttler_; 139 TaskQueueThrottler* task_queue_throttler_;
141 140
(...skipping 17 matching lines...) Expand all
159 158
160 base::Callback<void(base::TimeDelta)> reporting_callback_; 159 base::Callback<void(base::TimeDelta)> reporting_callback_;
161 160
162 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool); 161 DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool);
163 }; 162 };
164 163
165 } // namespace scheduler 164 } // namespace scheduler
166 } // namespace blink 165 } // namespace blink
167 166
168 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_ 167 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_BUDGET_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698