| OLD | NEW |
| 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 Loading... |
| 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 // Decrease |current_budget_level_| to satisfy max budget level |
| 120 // condition if necessary. |
| 121 void EnforceBudgetLevelRestrictions(); |
| 122 |
| 114 const char* name_; // NOT OWNED | 123 const char* name_; // NOT OWNED |
| 115 | 124 |
| 116 TaskQueueThrottler* task_queue_throttler_; | 125 TaskQueueThrottler* task_queue_throttler_; |
| 117 | 126 |
| 127 // Max budget level which we can accrue. |
| 128 // Tasks will be allowed to run for this time before being throttled |
| 129 // after a very long period of inactivity. |
| 130 base::Optional<base::TimeDelta> max_budget_level_; |
| 131 // Max throttling duration places a lower limit on time budget level, |
| 132 // ensuring that one long task does not cause extremely long throttling. |
| 133 // Note that this is not the guarantee that every task will run |
| 134 // after desired run time + max throttling duration, but a guarantee |
| 135 // that at least one task will be run every max_throttling_duration. |
| 136 base::Optional<base::TimeDelta> max_throttling_duration_; |
| 137 |
| 118 base::TimeDelta current_budget_level_; | 138 base::TimeDelta current_budget_level_; |
| 119 base::TimeDelta max_budget_level_; | |
| 120 base::TimeTicks last_checkpoint_; | 139 base::TimeTicks last_checkpoint_; |
| 121 double cpu_percentage_; | 140 double cpu_percentage_; |
| 122 bool is_enabled_; | 141 bool is_enabled_; |
| 123 | 142 |
| 124 std::unordered_set<TaskQueue*> associated_task_queues_; | 143 std::unordered_set<TaskQueue*> associated_task_queues_; |
| 125 | 144 |
| 126 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); | 145 DISALLOW_COPY_AND_ASSIGN(TimeBudgetPool); |
| 127 }; | 146 }; |
| 128 | 147 |
| 129 // TODO(altimin): Do not pass tracing category as const char*, | 148 // TODO(altimin): Do not pass tracing category as const char*, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); | 248 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); |
| 230 | 249 |
| 231 TaskQueueMap queue_details_; | 250 TaskQueueMap queue_details_; |
| 232 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; | 251 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; |
| 233 scoped_refptr<TaskQueue> task_runner_; | 252 scoped_refptr<TaskQueue> task_runner_; |
| 234 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 253 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
| 235 base::TickClock* tick_clock_; // NOT OWNED | 254 base::TickClock* tick_clock_; // NOT OWNED |
| 236 const char* tracing_category_; // NOT OWNED | 255 const char* tracing_category_; // NOT OWNED |
| 237 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 256 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
| 238 | 257 |
| 258 base::Optional<base::TimeDelta> max_budget_level_; |
| 259 base::Optional<base::TimeDelta> max_throttling_duration_; |
| 260 |
| 239 CancelableClosureHolder pump_throttled_tasks_closure_; | 261 CancelableClosureHolder pump_throttled_tasks_closure_; |
| 240 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; | 262 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
| 241 bool virtual_time_; | 263 bool virtual_time_; |
| 242 | 264 |
| 243 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> | 265 std::unordered_map<TimeBudgetPool*, std::unique_ptr<TimeBudgetPool>> |
| 244 time_budget_pools_; | 266 time_budget_pools_; |
| 245 | 267 |
| 246 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; | 268 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
| 247 | 269 |
| 248 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); | 270 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); |
| 249 }; | 271 }; |
| 250 | 272 |
| 251 } // namespace scheduler | 273 } // namespace scheduler |
| 252 } // namespace blink | 274 } // namespace blink |
| 253 | 275 |
| 254 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP
ER_H_ | 276 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_THROTTLING_HELP
ER_H_ |
| OLD | NEW |