Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.h |
| diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.h b/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.h |
| index 9bcb72a6d65560b974d1c9330cd3a7d01a79cff8..dba8fe3954f2b2f447bf7f365dd7dfabfc1dd8aa 100644 |
| --- a/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.h |
| +++ b/third_party/WebKit/Source/platform/scheduler/renderer/budget_pool.h |
| @@ -25,6 +25,7 @@ namespace scheduler { |
| class TaskQueue; |
| class BudgetPoolController; |
| +enum class QueueBlockType; |
| // BudgetPool represents a group of task queues which share a limit |
| // on a resource. This limit applies when task queues are already throttled |
| @@ -36,14 +37,32 @@ class BLINK_PLATFORM_EXPORT BudgetPool { |
| const char* Name() const; |
| // Report task run time to the budget pool. |
| - virtual void RecordTaskRunTime(base::TimeTicks start_time, |
| + virtual void RecordTaskRunTime(TaskQueue* queue, |
| + base::TimeTicks start_time, |
| base::TimeTicks end_time) = 0; |
| - // Retuns earliest time (can be in the past) when the next task can run. |
| - virtual base::TimeTicks GetNextAllowedRunTime() = 0; |
| + // Returns the earliest time when the next pump can be scheduled to run |
| + // new tasks. |
| + virtual base::TimeTicks GetNextAllowedRunTime( |
| + base::TimeTicks desired_run_time) const = 0; |
| // Returns true at a task can be run immediately at the given time. |
|
Sami
2017/04/26 13:09:08
s/at/if/, also "immediately at the given time" see
altimin
2017/04/26 14:31:29
Done.
|
| - virtual bool HasEnoughBudgetToRun(base::TimeTicks now) = 0; |
| + virtual bool CanRunTasksAt(base::TimeTicks moment, bool is_wake_up) const = 0; |
| + |
| + // Returns true if tasks can run at any time up to |moment|. |
| + virtual bool CanRunTasksUntil(base::TimeTicks now, |
| + base::TimeTicks moment) const = 0; |
| + |
| + // Notifies budget pool that queue has work with desired run time. |
| + virtual void OnTaskQueueHasWork(TaskQueue* queue, |
| + base::TimeTicks now, |
| + base::TimeTicks desired_run_time) = 0; |
| + |
| + // Notifies budget pool that wakeup has happened. |
| + virtual void OnWakeUp(base::TimeTicks now) = 0; |
| + |
| + // Specify how this budget pool should block affected queues. |
| + virtual QueueBlockType GetBlockType() const = 0; |
| // Returns state for tracing. |
| virtual void AsValueInto(base::trace_event::TracedValue* state, |
| @@ -55,10 +74,12 @@ class BLINK_PLATFORM_EXPORT BudgetPool { |
| void AddQueue(base::TimeTicks now, TaskQueue* queue); |
| // Removes |queue| from given pool. If it is throttled, it does not |
| - // become enabled immediately, but a call to |PumpThrottledTasks| |
| - // is scheduled. |
| + // become enabled immediately, but schedules a wakeup if needed. |
|
Sami
2017/04/26 13:09:08
nit: "a wake up is scheduled if needed" (also let'
altimin
2017/04/26 14:31:29
I'm thinking about a presubmit check actually...
|
| void RemoveQueue(base::TimeTicks now, TaskQueue* queue); |
| + // Unlike RemoveQueue, does not schedule a new wakeup for the queue. |
| + void UnregisterQueue(TaskQueue* queue); |
| + |
| // Enables this time budget pool. Queues from this pool will be |
| // throttled based on their run time. |
| void EnableThrottling(LazyNow* now); |
| @@ -86,6 +107,9 @@ class BLINK_PLATFORM_EXPORT BudgetPool { |
| std::unordered_set<TaskQueue*> associated_task_queues_; |
| bool is_enabled_; |
| + |
| + private: |
| + void DissociateQueue(TaskQueue* queue); |
| }; |
| // CPUTimeBudgetPool represents a collection of task queues which share a limit |
| @@ -142,13 +166,23 @@ class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool { |
| base::Callback<void(base::TimeDelta)> reporting_callback); |
| // BudgetPool implementation: |
| - void RecordTaskRunTime(base::TimeTicks start_time, |
| + void RecordTaskRunTime(TaskQueue* queue, |
| + base::TimeTicks start_time, |
| base::TimeTicks end_time) final; |
| - bool HasEnoughBudgetToRun(base::TimeTicks now) final; |
| - base::TimeTicks GetNextAllowedRunTime() final; |
| + bool CanRunTasksUntil(base::TimeTicks now, base::TimeTicks until) const final; |
| + bool CanRunTasksAt(base::TimeTicks now, bool is_wake_up) const final; |
| + base::TimeTicks GetNextAllowedRunTime( |
| + base::TimeTicks desired_run_time) const final; |
| + void OnTaskQueueHasWork(TaskQueue* queue, |
| + base::TimeTicks now, |
| + base::TimeTicks desired_run_time) final; |
| + void OnWakeUp(base::TimeTicks now) final; |
| void AsValueInto(base::trace_event::TracedValue* state, |
| base::TimeTicks now) const final; |
| + protected: |
| + QueueBlockType GetBlockType() const final; |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(TaskQueueThrottlerTest, CPUTimeBudgetPool); |
| @@ -184,6 +218,53 @@ class BLINK_PLATFORM_EXPORT CPUTimeBudgetPool : public BudgetPool { |
| DISALLOW_COPY_AND_ASSIGN(CPUTimeBudgetPool); |
| }; |
| +// WakeUpBudgetPool represents a collection of task queues which share a limit |
| +// on total cpu time. |
| +class BLINK_PLATFORM_EXPORT WakeUpBudgetPool : public BudgetPool { |
| + public: |
| + WakeUpBudgetPool(const char* name, |
| + BudgetPoolController* budget_pool_controller, |
| + base::TimeTicks now); |
| + ~WakeUpBudgetPool() override; |
| + |
| + // Note: this does not have an immediate effect and should be called only |
| + // during initialization of a WakeUpBudgetPool. |
| + void SetWakeUpRate(double wakeups_per_second); |
| + |
| + // Note: this does not have an immediate effect and should be called only |
| + // during initialization of a WakeUpBudgetPool. |
| + void SetWakeUpDuration(base::TimeDelta duration); |
| + |
| + // BudgetPool implementation: |
| + void RecordTaskRunTime(TaskQueue* queue, |
| + base::TimeTicks start_time, |
| + base::TimeTicks end_time) final; |
| + bool CanRunTasksUntil(base::TimeTicks now, |
| + base::TimeTicks moment) const final; |
| + bool CanRunTasksAt(base::TimeTicks now, bool is_wake_up) const final; |
| + base::TimeTicks GetNextAllowedRunTime( |
| + base::TimeTicks desired_run_time) const final; |
| + void OnTaskQueueHasWork(TaskQueue* queue, |
| + base::TimeTicks now, |
| + base::TimeTicks desired_run_time) final; |
| + void OnWakeUp(base::TimeTicks now) final; |
| + void AsValueInto(base::trace_event::TracedValue* state, |
| + base::TimeTicks now) const final; |
| + |
| + protected: |
| + QueueBlockType GetBlockType() const final; |
| + |
| + private: |
| + base::Optional<base::TimeTicks> NextWakeUp() const; |
| + |
| + double wakeups_per_second_; |
| + base::TimeDelta wakeup_duration_; |
| + |
| + base::Optional<base::TimeTicks> last_wakeup_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WakeUpBudgetPool); |
| +}; |
| + |
| } // namespace scheduler |
| } // namespace blink |