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

Unified Diff: Source/platform/scheduler/Scheduler.h

Issue 595023002: Implement idle task scheduling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comment Created 6 years, 2 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
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | Source/platform/scheduler/Scheduler.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/Scheduler.h
diff --git a/Source/platform/scheduler/Scheduler.h b/Source/platform/scheduler/Scheduler.h
index 7f7835abcf76d6ac90c6780e6fdad520e3808d80..6cf752c988aa03279af476548429e7ab30bec717 100644
--- a/Source/platform/scheduler/Scheduler.h
+++ b/Source/platform/scheduler/Scheduler.h
@@ -23,15 +23,15 @@ class PLATFORM_EXPORT Scheduler {
WTF_MAKE_NONCOPYABLE(Scheduler);
public:
typedef Function<void()> Task;
- // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds and is expected to complete within this timeframe.
- typedef Function<void(double allottedTimeMs)> IdleTask;
+ // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expected to complete before this deadline.
+ typedef Function<void(double deadlineSeconds)> IdleTask;
static Scheduler* shared();
static void initializeOnMainThread();
static void shutdown();
// Called to notify about the start of a new frame.
- void willBeginFrame(const WebBeginFrameArgs&);
+ void willBeginFrame(double frameDeadlineSeconds);
// Called to notify that a previously begun frame was committed.
void didCommitFrameToCompositor();
@@ -42,7 +42,9 @@ public:
void postCompositorTask(const TraceLocation&, const Task&);
void postIpcTask(const TraceLocation&, const Task&);
void postTask(const TraceLocation&, const Task&); // For generic (low priority) tasks.
- void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critical tasks which may be reordered relative to other task types.
+ // For non-critical tasks which may be reordered relative to other task types and may be starved
+ // for an arbitrarily long time if no idle time is available.
+ void postIdleTask(const TraceLocation&, const IdleTask&);
// Tells the scheduler that the system received an input event. This causes the scheduler to go into
// Compositor Priority mode for a short duration.
@@ -59,9 +61,14 @@ public:
void setSharedTimerFireInterval(double);
void stopSharedTimer();
+ // Returns the time in CLOCK_MONOTONIC seconds until the deadline for running idle tasks during
+ // the current frame expires.
+ double currentFrameDeadlineForIdleTasks() const;
Sami 2014/10/06 09:48:30 The name makes it sound like this is a deadline bu
rmcilroy 2014/10/06 11:29:42 Comment was unclear - fixed, thanks.
+
protected:
class MainThreadPendingTaskRunner;
class MainThreadPendingHighPriorityTaskRunner;
+ class MainThreadPendingIdleTaskRunner;
friend class MainThreadPendingTaskRunner;
friend class MainThreadPendingHighPriorityTaskRunner;
@@ -73,8 +80,8 @@ protected:
Scheduler();
virtual ~Scheduler();
- void scheduleIdleTask(const TraceLocation&, const IdleTask&);
void postHighPriorityTaskInternal(const TraceLocation&, const Task&, const char* traceName);
+ void postIdleTaskInternal(const TraceLocation&, const IdleTask&, const char* traceName);
static void sharedTimerAdapter();
@@ -83,13 +90,21 @@ protected:
// Only does work in CompositorPriority mode. Returns true if any work was done.
bool runPendingHighPriorityTasksIfInCompositorPriority();
+ // Only does work if canRunIdleTask. Returns true if any work was done.
+ bool maybeRunPendingIdleTask();
+
+ TracedIdleTask takeFirstPendingIdleTask();
+
// Returns true if any work was done.
bool swapQueuesAndRunPendingTasks();
void swapQueuesRunPendingTasksAndAllowHighPriorityTaskRunnerPosting();
// Returns true if any work was done.
- bool executeHighPriorityTasks(Deque<TracedTask>&);
+ bool executeHighPriorityTasks(Deque<TracedStandardTask>&);
+
+ // Returns true if the scheduler can run idle tasks at this time.
+ bool canRunIdleTask() const;
// Return the current SchedulerPolicy.
SchedulerPolicy schedulerPolicy() const;
@@ -99,6 +114,9 @@ protected:
// Must be called while m_pendingTasksMutex is locked.
void maybePostMainThreadPendingHighPriorityTaskRunner();
+ // Returns true if an idle task was posted to the main thread for execution.
+ bool maybePostMainThreadPendingIdleTask();
+
void tickSharedTimer();
void (*m_sharedTimerFunction)();
@@ -118,9 +136,13 @@ protected:
// This mutex protects calls to the pending task queue, m_highPriorityTaskRunnerPosted and
// m_compositorPriorityPolicyEndTimeSeconds.
Mutex m_pendingTasksMutex;
- DoubleBufferedDeque<TracedTask> m_pendingHighPriorityTasks;
+ DoubleBufferedDeque<TracedStandardTask> m_pendingHighPriorityTasks;
+ Deque<TracedIdleTask> m_pendingIdleTasks;
double m_compositorPriorityPolicyEndTimeSeconds;
+ bool m_currentFrameCommitted;
+ double m_currentFrameDeadlineSeconds;
+
// Declared volatile as it is atomically incremented.
volatile int m_highPriorityTaskCount;
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.cpp » ('j') | Source/platform/scheduler/Scheduler.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698