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

Side by Side Diff: Source/platform/scheduler/Scheduler.h

Issue 439923006: Prioritizing input and compositor tasks in the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed a couple of changes I didn't intend to be in this patch. Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 Scheduler_h 5 #ifndef Scheduler_h
6 #define Scheduler_h 6 #define Scheduler_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/TraceLocation.h"
10 #include "wtf/DoubleBufferedDeque.h"
9 #include "wtf/Functional.h" 11 #include "wtf/Functional.h"
10 #include "wtf/Noncopyable.h" 12 #include "wtf/Noncopyable.h"
13 #include "wtf/ThreadingPrimitives.h"
11 14
12 namespace blink { 15 namespace blink {
13 class WebThread; 16 class WebThread;
14 } 17 }
15 18
16 namespace blink { 19 namespace blink {
17 20
18 class TraceLocation;
19
20 // The scheduler is an opinionated gateway for arranging work to be run on the 21 // The scheduler is an opinionated gateway for arranging work to be run on the
21 // main thread. It decides which tasks get priority over others based on a 22 // main thread. It decides which tasks get priority over others based on a
22 // scheduling policy and the overall system state. 23 // scheduling policy and the overall system state.
23 class PLATFORM_EXPORT Scheduler { 24 class PLATFORM_EXPORT Scheduler {
24 WTF_MAKE_NONCOPYABLE(Scheduler); 25 WTF_MAKE_NONCOPYABLE(Scheduler);
25 public: 26 public:
26 typedef Function<void()> Task; 27 typedef Function<void()> Task;
27 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an d is expected to complete within this timeframe. 28 // An IdleTask is passed an allotted time in CLOCK_MONOTONIC milliseconds an d is expected to complete within this timeframe.
28 typedef Function<void(double allottedTimeMs)> IdleTask; 29 typedef Function<void(double allottedTimeMs)> IdleTask;
29 30
30 static Scheduler* shared(); 31 static Scheduler* shared();
31 static void initializeOnMainThread(); 32 static void initializeOnMainThread();
32 static void shutdown(); 33 static void shutdown();
33 34
34 // The following entrypoints are used to schedule different types of tasks 35 // The following entrypoints are used to schedule different types of tasks
35 // to be run on the main thread. They can be called from any thread. 36 // to be run on the main thread. They can be called from any thread.
36 void postInputTask(const TraceLocation&, const Task&); 37 void postInputTask(const TraceLocation&, const Task&);
37 void postCompositorTask(const TraceLocation&, const Task&); 38 void postCompositorTask(const TraceLocation&, const Task&);
38 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks. 39 void postTask(const TraceLocation&, const Task&); // For generic (low priori ty) tasks.
39 void postIdleTask(const IdleTask&); // For non-critical tasks which may be r eordered relative to other task types. 40 void postIdleTask(const TraceLocation&, const IdleTask&); // For non-critica l tasks which may be reordered relative to other task types.
40 41
41 // Returns true if there is high priority work pending on the main thread 42 // Returns true if there is high priority work pending on the main thread
42 // and the caller should yield to let the scheduler service that work. 43 // and the caller should yield to let the scheduler service that work.
43 // Can be called on the main thread. 44 // Can be called on any thread.
44 bool shouldYieldForHighPriorityWork(); 45 bool shouldYieldForHighPriorityWork();
45 46
46 // The shared timer can be used to schedule a periodic callback which may 47 // The shared timer can be used to schedule a periodic callback which may
47 // get preempted by higher priority work. 48 // get preempted by higher priority work.
48 void setSharedTimerFiredFunction(void (*function)()); 49 void setSharedTimerFiredFunction(void (*function)());
49 void setSharedTimerFireInterval(double); 50 void setSharedTimerFireInterval(double);
50 void stopSharedTimer(); 51 void stopSharedTimer();
51 52
52 private: 53 private:
54 class MainThreadPendingTaskRunner;
55 class MainThreadPendingHighPriorityTaskRunner;
56 friend class MainThreadPendingTaskRunner;
57 friend class MainThreadPendingHighPriorityTaskRunner;
58
53 Scheduler(); 59 Scheduler();
54 ~Scheduler(); 60 ~Scheduler();
55 61
56 void scheduleTask(const TraceLocation&, const Task&); 62 void scheduleIdleTask(const TraceLocation&, const IdleTask&);
57 void scheduleIdleTask(const IdleTask&);
58 63
59 static void sharedTimerAdapter(); 64 static void sharedTimerAdapter();
60 void tickSharedTimer(); 65 void tickSharedTimer();
61 66
62 static Scheduler* s_sharedScheduler; 67 static Scheduler* s_sharedScheduler;
63 blink::WebThread* m_mainThread;
64 68
69 class TracedTask {
70 public:
71 TracedTask(const Task& task, const TraceLocation& location)
72 : m_task(task)
73 , m_location(location) { }
74
75 void run();
76
77 private:
78 Task m_task;
79 TraceLocation m_location;
80 };
81
82 bool hasPendingHighPriorityWork();
Sami 2014/08/12 15:05:31 Could you move these two functions above the data
alexclarke 2014/08/12 15:21:38 Done.
83 void runHighPriorityTasks();
84
85 // Should only be accessed from the main thread.
65 void (*m_sharedTimerFunction)(); 86 void (*m_sharedTimerFunction)();
87
88 // These members can be accessed from any thread.
89 WebThread* m_mainThread;
90
91 // This mutex protects calls to the pending task queues.
92 Mutex m_pendingTasksMutex;
93 DoubleBufferedDeque<TracedTask> m_pendingInputTasks;
94 DoubleBufferedDeque<TracedTask> m_pendingCompositorTasks;
95
96 volatile int m_highPriorityTaskCount;
66 }; 97 };
67 98
68 } // namespace blink 99 } // namespace blink
69 100
70 #endif // Scheduler_h 101 #endif // Scheduler_h
OLDNEW
« 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