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

Side by Side Diff: gpu/command_buffer/service/scheduler.h

Issue 2814843002: gpu: GPU service scheduler. (Closed)
Patch Set: rebase Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_
7
8 #include <map>
9 #include <queue>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "base/threading/thread_checker.h"
17 #include "gpu/command_buffer/common/gpu_stream_constants.h"
18 #include "gpu/command_buffer/common/sync_token.h"
19 #include "gpu/command_buffer/service/sequence_id.h"
20 #include "gpu/gpu_export.h"
21
22 namespace base {
23 class SingleThreadTaskRunner;
24 namespace trace_event {
25 class ConvertableToTraceFormat;
26 }
27 }
28
29 namespace gpu {
30 class SyncPointManager;
31
32 class GPU_EXPORT Scheduler {
33 public:
34 Scheduler(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
35 SyncPointManager* sync_point_manager);
36
37 virtual ~Scheduler();
38
39 // Create a sequence with given priority. Returns an identifier for the
40 // sequence that can be used with SyncPonintManager for creating sync point
41 // release clients. Sequences start off as enabled (see |EnableSequence|).
42 SequenceId CreateSequence(GpuStreamPriority priority);
43
44 // Destroy the sequence and run any scheduled tasks immediately.
45 void DestroySequence(SequenceId sequence_id);
46
47 // Enables the sequence so that its tasks may be scheduled.
48 void EnableSequence(SequenceId sequence_id);
49
50 // Disables the sequence.
51 void DisableSequence(SequenceId sequence_id);
52
53 // Schedules task (closure) to run on the sequence. The task is blocked until
54 // the sync token fences are released or determined to be invalid. Tasks are
55 // run in the order in which they are submitted.
56 void ScheduleTask(SequenceId sequence_id,
57 base::OnceClosure closure,
58 const std::vector<SyncToken>& sync_token_fences);
59
60 // Continue running task on the sequence with the closure. This must be called
61 // while running a previously scheduled task.
62 void ContinueTask(SequenceId sequence_id, base::OnceClosure closure);
63
64 // If the sequence should yield so that a higher priority sequence may run.
65 bool ShouldYield(SequenceId sequence_id);
66
67 private:
68 class Sequence;
69
70 struct SchedulingState {
71 SequenceId sequence_id;
72 GpuStreamPriority priority = GpuStreamPriority::LAST;
73 uint32_t order_num = 0;
74
75 SchedulingState();
76 SchedulingState(const SchedulingState& other);
77 ~SchedulingState();
78
79 bool operator<(const SchedulingState& other) const {
80 return std::tie(priority, order_num) >
81 std::tie(other.priority, other.order_num);
82 }
83
84 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue()
85 const;
86 };
87
88 using SchedulingQueue = std::priority_queue<SchedulingState>;
89
90 void SyncTokenFenceReleased(const SyncToken& sync_token,
91 uint32_t order_num,
92 SequenceId release_sequence_id,
93 SequenceId waiting_sequence_id);
94
95 void TryScheduleSequence(Sequence* sequence);
96
97 void RebuildSchedulingQueue();
98
99 Sequence* GetSequence(SequenceId sequence_id);
100
101 void RunNextTask();
102
103 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
104
105 SyncPointManager* const sync_point_manager_;
106
107 // The following are protected by |lock_|.
108 bool running_ = false;
109
110 std::map<SequenceId, std::unique_ptr<Sequence>> sequences_;
piman 2017/05/10 00:38:50 nit: flat_map may work well here.
sunnyps 2017/05/10 23:15:15 Done.
111
112 SchedulingQueue scheduling_queue_;
113
114 // If the running sequence should yield so that a higher priority sequence can
115 // run.
116 bool should_yield_ = false;
117
118 // If the scheduling queue needs to be rebuild because a sequence changed
119 // priority.
120 bool rebuild_scheduling_queue_ = false;
121
122 // Protects the above variables.
123 mutable base::Lock lock_;
vmiura 2017/05/04 21:27:37 The lock should be declared before the variables i
sunnyps 2017/05/10 23:15:15 Done.
124
125 base::ThreadChecker thread_checker_;
126
127 base::WeakPtrFactory<Scheduler> weak_factory_;
128
129 DISALLOW_COPY_AND_ASSIGN(Scheduler);
130 };
131
132 } // namespace gpu
133
134 #endif // GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698