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

Unified Diff: components/scheduler/child/idle_helper.h

Issue 1151353003: [scheduler]: Avoid waking up the scheduler to end long idle periods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@end_idle_sync_2
Patch Set: Review comments. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: components/scheduler/child/idle_helper.h
diff --git a/components/scheduler/child/idle_helper.h b/components/scheduler/child/idle_helper.h
index 0994063d4a08e75ca620efd1cb2a7323b61e2b05..46b7a330f7d3ffa6b472137b56b5a52c25ac5591 100644
--- a/components/scheduler/child/idle_helper.h
+++ b/components/scheduler/child/idle_helper.h
@@ -5,7 +5,9 @@
#ifndef COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_
#define COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_
+#include "base/message_loop/message_loop.h"
#include "components/scheduler/child/cancelable_closure_holder.h"
+#include "components/scheduler/child/pollable_thread_safe_flag.h"
#include "components/scheduler/child/prioritizing_task_queue_selector.h"
#include "components/scheduler/child/single_thread_idle_task_runner.h"
#include "components/scheduler/scheduler_export.h"
@@ -15,7 +17,9 @@ namespace scheduler {
class SchedulerHelper;
// Common scheduler functionality for Idle tasks.
-class SCHEDULER_EXPORT IdleHelper {
+class SCHEDULER_EXPORT IdleHelper
+ : public base::MessageLoop::TaskObserver,
+ public SingleThreadIdleTaskRunner::Delegate {
public:
// Used to by scheduler implementations to customize idle behaviour.
class SCHEDULER_EXPORT Delegate {
@@ -44,7 +48,7 @@ class SCHEDULER_EXPORT IdleHelper {
IN_SHORT_IDLE_PERIOD,
IN_LONG_IDLE_PERIOD,
IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE,
- ENDING_LONG_IDLE_PERIOD,
+ IN_LONG_IDLE_PERIOD_PAUSED,
// Must be the last entry.
IDLE_PERIOD_STATE_COUNT,
FIRST_IDLE_PERIOD_STATE = NOT_IN_IDLE_PERIOD,
@@ -63,7 +67,7 @@ class SCHEDULER_EXPORT IdleHelper {
const char* disabled_by_default_tracing_category,
const char* idle_period_tracing_name,
base::TimeDelta required_quiescence_duration_before_long_idle_period);
- ~IdleHelper();
+ ~IdleHelper() override;
// Returns the idle task runner. Tasks posted to this runner may be reordered
// relative to other task types and may be starved for an arbitrarily long
@@ -80,12 +84,10 @@ class SCHEDULER_EXPORT IdleHelper {
// NOTE EndIdlePeriod will disable the long idle periods.
void EnableLongIdlePeriod();
- // Start and end an idle period. If |post_end_idle_period| is true, it will
- // post a delayed EndIdlePeriod scheduled to occur at |idle_period_deadline|.
+ // Start an idle period with a given idle period deadline.
void StartIdlePeriod(IdlePeriodState new_idle_period_state,
base::TimeTicks now,
- base::TimeTicks idle_period_deadline,
- bool post_end_idle_period);
+ base::TimeTicks idle_period_deadline);
// This will end an idle period either started with StartIdlePeriod or
// EnableLongIdlePeriod.
@@ -101,16 +103,71 @@ class SCHEDULER_EXPORT IdleHelper {
// Must be called from the thread this class was created on.
bool CanExceedIdleDeadlineIfRequired() const;
- IdlePeriodState SchedulerIdlePeriodState() const;
+ // Returns the deadline for the current idle task.
+ base::TimeTicks CurrentIdleTaskDeadline() const;
+
+ // SingleThreadIdleTaskRunner::Delegate implementation:
+ void OnIdleTaskPosted() override;
+ base::TimeTicks WillProcessIdleTask() const override;
+ void DidProcessIdleTask() override;
- // IdleTaskDeadlineSupplier Implementation:
- void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
+ // base::MessageLoop::TaskObserver implementation:
+ void WillProcessTask(const base::PendingTask& pending_task) override;
+ void DidProcessTask(const base::PendingTask& pending_task) override;
+ IdlePeriodState SchedulerIdlePeriodState() const;
static const char* IdlePeriodStateToString(IdlePeriodState state);
private:
friend class IdleHelperTest;
+ class State {
+ public:
+ State(SchedulerHelper* helper,
+ const char* tracing_category,
+ const char* disabled_by_default_tracing_category,
+ const char* idle_period_tracing_name);
+ virtual ~State();
+
+ void WillProcessIdleTask() const;
+ void DidProcessIdleTask() const;
+ void UpdateState(IdlePeriodState new_state,
+ base::TimeTicks new_deadline,
+ base::TimeTicks optional_now);
+ void TraceEventIdlePeriodStateChange(IdlePeriodState new_state,
+ base::TimeTicks new_deadline,
+ base::TimeTicks optional_now) const;
+
+ IdlePeriodState idle_period_state() const {
+ helper_->CheckOnValidThread();
alex clarke (OOO till 29th) 2015/05/29 13:24:49 If you're going to define this inline, you should
rmcilroy 2015/06/01 15:33:22 I moved it out-of-line.
+ return idle_period_state_;
+ }
+ base::TimeTicks idle_period_deadline() const {
+ helper_->CheckOnValidThread();
+ return idle_period_deadline_;
+ }
+ bool idle_period_paused_flag() const {
+ return idle_period_paused_flag_.IsSet();
+ }
+
+ private:
+ SchedulerHelper* helper_; // NOT OWNED
+
+ base::Lock write_lock_;
+ IdlePeriodState idle_period_state_;
+ base::TimeTicks idle_period_deadline_;
+ PollableThreadSafeFlag idle_period_paused_flag_;
+
+ base::TimeTicks idle_period_deadline_for_tracing_;
+ mutable base::TimeTicks last_traced_start_running_idle_task_;
Sami 2015/05/29 09:38:06 I'm having trouble parsing this name. last_idle_ta
rmcilroy 2015/06/01 15:33:22 Done.
+ mutable bool nestable_events_started_;
+ const char* tracing_category_;
+ const char* disabled_by_default_tracing_category_;
+ const char* idle_period_tracing_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(State);
+ };
+
// The minimum delay to wait between retrying to initiate a long idle time.
static const int kRetryEnableLongIdlePeriodDelayMillis = 1;
@@ -122,32 +179,32 @@ class SCHEDULER_EXPORT IdleHelper {
base::TimeDelta* next_long_idle_period_delay_out);
bool ShouldWaitForQuiescence();
- void EnableLongIdlePeriodAfterWakeup();
+ void UpdateLongIdlePeriodStateAfterIdleTask();
+
+ void SetIdlePeriodState(IdlePeriodState new_state,
+ base::TimeTicks new_deadline,
+ base::TimeTicks optional_now);
// Returns true if |state| represents being within an idle period state.
static bool IsInIdlePeriod(IdlePeriodState state);
+ // Returns true if |state| represents being within a long idle period state.
+ static bool IsInLongIdlePeriod(IdlePeriodState state);
SchedulerHelper* helper_; // NOT OWNED
Delegate* delegate_; // NOT OWNED
size_t idle_queue_index_;
scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
- CancelableClosureHolder end_idle_period_closure_;
CancelableClosureHolder enable_next_long_idle_period_closure_;
- CancelableClosureHolder enable_next_long_idle_period_after_wakeup_closure_;
- IdlePeriodState idle_period_state_;
+ State state_;
// A bitmap which controls the set of queues that are checked for quiescence
// before triggering a long idle period.
uint64 quiescence_monitored_task_queue_mask_;
base::TimeDelta required_quiescence_duration_before_long_idle_period_;
- base::TimeTicks idle_period_deadline_;
-
- const char* tracing_category_;
const char* disabled_by_default_tracing_category_;
- const char* idle_period_tracing_name_;
base::WeakPtr<IdleHelper> weak_idle_helper_ptr_;
base::WeakPtrFactory<IdleHelper> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698