blob: 3b5ae60a46d6a212363aba5b49f32f8d5b8f6aa0 [file] [log] [blame]
Yuzhu Shen84ee8572024-09-06 01:30:471// Copyright 2022 The Chromium Authors
sunnyps8f9139e2017-05-12 17:53:252// 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
sunnyps8f9139e2017-05-12 17:53:258#include <vector>
9
sunnyps8f9139e2017-05-12 17:53:2510#include "base/containers/flat_map.h"
Victor Miura651b0c32017-11-18 05:03:4311#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5212#include "base/memory/raw_ptr.h"
François Doray53020332023-05-03 19:00:3813#include "base/rand_util.h"
sunnyps8f9139e2017-05-12 17:53:2514#include "base/synchronization/lock.h"
Yuzhu Shen84ee8572024-09-06 01:30:4715#include "base/thread_annotations.h"
Lucas Berthou8ab73ae2021-03-17 20:14:5216#include "base/time/time.h"
sunnyps8f9139e2017-05-12 17:53:2517#include "gpu/command_buffer/common/scheduling_priority.h"
18#include "gpu/command_buffer/common/sync_token.h"
Vasiliy Telezhnikovf8bdccb2025-06-18 19:05:3919#include "gpu/command_buffer/service/gpu_command_buffer_service_export.h"
sunnyps8f9139e2017-05-12 17:53:2520#include "gpu/command_buffer/service/sequence_id.h"
Yuzhu Shen52f3e2aa2024-06-18 17:35:4521#include "gpu/command_buffer/service/task_graph.h"
Omar Elmekkawya2c06812021-12-09 18:13:4722#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
sunnyps8f9139e2017-05-12 17:53:2523
24namespace base {
25class SingleThreadTaskRunner;
sunnyps8f9139e2017-05-12 17:53:2526}
27
28namespace gpu {
Ramy El Garawanyb1dedd22022-12-06 02:32:5029
Vasiliy Telezhnikovf8bdccb2025-06-18 19:05:3930class GPU_COMMAND_BUFFER_SERVICE_EXPORT Scheduler {
sunnyps8f9139e2017-05-12 17:53:2531 public:
Vasiliy Telezhnikovf8bdccb2025-06-18 19:05:3932 struct GPU_COMMAND_BUFFER_SERVICE_EXPORT Task {
Yuzhu Shenff6622c2024-08-29 21:18:4433 // Use the signature with TaskCallback if the task needs to determine when
34 // to release fence sync during task execution. Please also see comments of
35 // TaskCallback.
36 // Use the signatures with base::OnceClosure if the task doesn't release
37 // fence sync, or the release can be done automatically after task
38 // execution.
Sunny Sachanandani9b8fb342017-08-26 00:49:5639 Task(SequenceId sequence_id,
Yuzhu Shenff6622c2024-08-29 21:18:4440 TaskCallback task_callback,
Lucas Berthoue2649ff2021-03-25 08:43:0241 std::vector<SyncToken> sync_token_fences,
Yuzhu Shen6a71fb8e2024-06-28 02:39:1542 const SyncToken& release,
Lucas Berthoue2649ff2021-03-25 08:43:0243 ReportingCallback report_callback = ReportingCallback());
Yuzhu Shen6a71fb8e2024-06-28 02:39:1544
Yuzhu Shen6a71fb8e2024-06-28 02:39:1545 Task(SequenceId sequence_id,
Yuzhu Shenff6622c2024-08-29 21:18:4446 base::OnceClosure task_closure,
47 std::vector<SyncToken> sync_token_fences,
48 const SyncToken& release,
49 ReportingCallback report_callback = ReportingCallback());
50
51 Task(SequenceId sequence_id,
52 base::OnceClosure task_closure,
Yuzhu Shen6a71fb8e2024-06-28 02:39:1553 std::vector<SyncToken> sync_token_fences,
54 ReportingCallback report_callback = ReportingCallback());
55
Sunny Sachanandani9b8fb342017-08-26 00:49:5656 Task(Task&& other);
57 ~Task();
58 Task& operator=(Task&& other);
59
60 SequenceId sequence_id;
Yuzhu Shenff6622c2024-08-29 21:18:4461
62 // Only one of the two is used.
63 TaskCallback task_callback;
64 base::OnceClosure task_closure;
65
Sunny Sachanandani9b8fb342017-08-26 00:49:5666 std::vector<SyncToken> sync_token_fences;
Yuzhu Shen6a71fb8e2024-06-28 02:39:1567
68 // The release that is expected to be reached after execution of this task.
Yuzhu Shen6a71fb8e2024-06-28 02:39:1569 SyncToken release;
70
Lucas Berthoue2649ff2021-03-25 08:43:0271 ReportingCallback report_callback;
Sunny Sachanandani9b8fb342017-08-26 00:49:5672 };
73
Vasiliy Telezhnikovf8bdccb2025-06-18 19:05:3974 struct GPU_COMMAND_BUFFER_SERVICE_EXPORT ScopedSetSequencePriority {
Bo Liueca0009f2022-08-25 22:59:3275 public:
Yuzhu Shen84ee8572024-09-06 01:30:4776 ScopedSetSequencePriority(Scheduler* scheduler,
77 SequenceId sequence_id,
78 SchedulingPriority priority);
79 ~ScopedSetSequencePriority();
Bo Liueca0009f2022-08-25 22:59:3280
81 private:
82 const raw_ptr<Scheduler> scheduler_;
83 const SequenceId sequence_id_;
Bo Liueca0009f2022-08-25 22:59:3284 };
85
Maggie Chen0b4389c2024-08-07 21:25:0586 explicit Scheduler(SyncPointManager* sync_point_manager);
sunnyps8f9139e2017-05-12 17:53:2587
Peter BostrÃļmdbacdc22021-09-23 22:11:4688 Scheduler(const Scheduler&) = delete;
89 Scheduler& operator=(const Scheduler&) = delete;
90
Yuzhu Shen84ee8572024-09-06 01:30:4791 ~Scheduler() LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:2592
93 // Create a sequence with given priority. Returns an identifier for the
Vikas Soni4fa4c09a2021-05-14 20:19:1994 // sequence that can be used with SyncPointManager for creating sync point
sunnyps8f9139e2017-05-12 17:53:2595 // release clients. Sequences start off as enabled (see |EnableSequence|).
Vikas Soni1e0503e2021-06-04 01:29:0396 // Sequence is bound to the provided |task_runner|.
97 SequenceId CreateSequence(
98 SchedulingPriority priority,
Yuzhu Shen84ee8572024-09-06 01:30:4799 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
100 LOCKS_EXCLUDED(lock());
Vikas Soni1e0503e2021-06-04 01:29:03101
Yuzhu Shen07b22172024-09-17 22:25:15102 // Similar to the method above, but also creates a SyncPointClientState
103 // associated with the sequence. The SyncPointClientState object is destroyed
104 // when the sequence is destroyed.
105 SequenceId CreateSequence(
106 SchedulingPriority priority,
107 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
108 CommandBufferNamespace namespace_id,
109 CommandBufferId command_buffer_id) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25110
Weiliang Chenaf34b932019-07-18 18:59:17111 // Destroy the sequence and run any scheduled tasks immediately. Sequence
112 // could be destroyed outside of GPU thread.
Yuzhu Shen84ee8572024-09-06 01:30:47113 void DestroySequence(SequenceId sequence_id) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25114
Yuzhu Shen07b22172024-09-17 22:25:15115 [[nodiscard]] ScopedSyncPointClientState CreateSyncPointClientState(
116 SequenceId sequence_id,
117 CommandBufferNamespace namespace_id,
118 CommandBufferId command_buffer_id) LOCKS_EXCLUDED(lock());
Yuzhu Shenff6622c2024-08-29 21:18:44119
sunnyps8f9139e2017-05-12 17:53:25120 // Enables the sequence so that its tasks may be scheduled.
Yuzhu Shen84ee8572024-09-06 01:30:47121 void EnableSequence(SequenceId sequence_id) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25122
123 // Disables the sequence.
Yuzhu Shen84ee8572024-09-06 01:30:47124 void DisableSequence(SequenceId sequence_id) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25125
Yuzhu Shen84ee8572024-09-06 01:30:47126 // Gets the priority that the sequence was created with.
127 SchedulingPriority GetSequenceDefaultPriority(SequenceId sequence_id)
128 LOCKS_EXCLUDED(lock());
Sunny Sachanandanic9859672017-10-11 23:19:16129
Yuzhu Shen84ee8572024-09-06 01:30:47130 // Changes a sequence's priority. Used in WaitForGetOffset/TokenInRange to
131 // temporarily increase a sequence's priority.
132 void SetSequencePriority(SequenceId sequence_id, SchedulingPriority priority)
133 LOCKS_EXCLUDED(lock());
Sunny Sachanandanic9859672017-10-11 23:19:16134
Yuzhu Shenff6622c2024-08-29 21:18:44135 // Schedules task to run on the sequence. The task is blocked until the sync
136 // token fences are released or determined to be invalid. Tasks are run in the
137 // order in which they are submitted.
Yuzhu Shen84ee8572024-09-06 01:30:47138 void ScheduleTask(Scheduler::Task task) LOCKS_EXCLUDED(lock());
Sunny Sachanandani9b8fb342017-08-26 00:49:56139
Yuzhu Shen84ee8572024-09-06 01:30:47140 void ScheduleTasks(std::vector<Scheduler::Task> tasks) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25141
Yuzhu Shenff6622c2024-08-29 21:18:44142 // Continue running task on the sequence with the callback. This must be
143 // called while running a previously scheduled task.
Yuzhu Shen84ee8572024-09-06 01:30:47144 void ContinueTask(SequenceId sequence_id, TaskCallback task_callback)
145 LOCKS_EXCLUDED(lock());
146 void ContinueTask(SequenceId sequence_id, base::OnceClosure task_closure)
147 LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25148
149 // If the sequence should yield so that a higher priority sequence may run.
Yuzhu Shen84ee8572024-09-06 01:30:47150 bool ShouldYield(SequenceId sequence_id) LOCKS_EXCLUDED(lock());
sunnyps8f9139e2017-05-12 17:53:25151
Yuzhu Shen84ee8572024-09-06 01:30:47152 base::SingleThreadTaskRunner* GetTaskRunnerForTesting(SequenceId sequence_id)
153 LOCKS_EXCLUDED(lock());
Minoru Chikamune5c81af12021-04-15 03:30:51154
Yuzhu Shen84ee8572024-09-06 01:30:47155 bool graph_validation_enabled() const {
156 return task_graph_.graph_validation_enabled();
157 }
Ramy El Garawanyb1dedd22022-12-06 02:32:50158
Yuzhu Shen52f3e2aa2024-06-18 17:35:45159 TaskGraph* task_graph() { return &task_graph_; }
160
Vikas Soni4fa4c09a2021-05-14 20:19:19161 private:
sunnyps8f9139e2017-05-12 17:53:25162 struct SchedulingState {
sunnyps8f9139e2017-05-12 17:53:25163 SchedulingState();
164 SchedulingState(const SchedulingState& other);
165 ~SchedulingState();
166
Yuzhu Shen84ee8572024-09-06 01:30:47167 static bool RunsBefore(const SchedulingState& lhs,
168 const SchedulingState& rhs) {
169 return std::tie(lhs.priority, lhs.order_num) <
170 std::tie(rhs.priority, rhs.order_num);
sunnyps8f9139e2017-05-12 17:53:25171 }
172
Omar Elmekkawya2c06812021-12-09 18:13:47173 void WriteIntoTrace(perfetto::TracedValue context) const;
sunnyps8f9139e2017-05-12 17:53:25174
Yuzhu Shen84ee8572024-09-06 01:30:47175 bool operator==(const SchedulingState& rhs) const;
176
sunnyps8f9139e2017-05-12 17:53:25177 SequenceId sequence_id;
Sunny Sachanandanic9859672017-10-11 23:19:16178 SchedulingPriority priority = SchedulingPriority::kLow;
sunnyps8f9139e2017-05-12 17:53:25179 uint32_t order_num = 0;
180 };
181
Yuzhu Shen84ee8572024-09-06 01:30:47182 // All public methods except constructor must be accessed under TaskGraph's
183 // lock. Please see locking annotation of individual methods.
Vasiliy Telezhnikovf8bdccb2025-06-18 19:05:39184 class GPU_COMMAND_BUFFER_SERVICE_EXPORT Sequence
185 : public TaskGraph::Sequence {
Victor Miura651b0c32017-11-18 05:03:43186 public:
Yuzhu Shen07b22172024-09-17 22:25:15187 Sequence(
188 Scheduler* scheduler,
189 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
190 SchedulingPriority priority,
191 CommandBufferNamespace namespace_id = CommandBufferNamespace::INVALID,
192 CommandBufferId command_buffer_id = {});
Victor Miura651b0c32017-11-18 05:03:43193
Peter BostrÃļmdbacdc22021-09-23 22:11:46194 Sequence(const Sequence&) = delete;
195 Sequence& operator=(const Sequence&) = delete;
196
Yuzhu Shen84ee8572024-09-06 01:30:47197 ~Sequence() override EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43198
Vikas Soni1e0503e2021-06-04 01:29:03199 base::SingleThreadTaskRunner* task_runner() const {
200 return task_runner_.get();
201 }
Vikas Soni4fa4c09a2021-05-14 20:19:19202
Yuzhu Shen84ee8572024-09-06 01:30:47203 bool enabled() const EXCLUSIVE_LOCKS_REQUIRED(lock()) { return enabled_; }
Victor Miura651b0c32017-11-18 05:03:43204
Yuzhu Shen84ee8572024-09-06 01:30:47205 bool scheduled() const EXCLUSIVE_LOCKS_REQUIRED(lock()) {
206 return running_state_ == SCHEDULED;
207 }
Victor Miura651b0c32017-11-18 05:03:43208
Yuzhu Shen84ee8572024-09-06 01:30:47209 bool running() const EXCLUSIVE_LOCKS_REQUIRED(lock()) {
210 return running_state_ == RUNNING;
211 }
Victor Miura651b0c32017-11-18 05:03:43212
Yuzhu Shen84ee8572024-09-06 01:30:47213 bool HasTasksAndEnabled() const EXCLUSIVE_LOCKS_REQUIRED(lock()) {
214 return enabled() && HasTasks();
215 }
Victor Miura651b0c32017-11-18 05:03:43216
Yuzhu Shen84ee8572024-09-06 01:30:47217 // A sequence is runnable if it is enabled, is not already running, and has
218 // tasks in its queue. Note that this does *not* necessarily mean that its
219 // first task unblocked.
220 bool IsRunnable() const EXCLUSIVE_LOCKS_REQUIRED(lock()) {
221 return enabled() && !running() && HasTasks();
222 }
Victor Miura651b0c32017-11-18 05:03:43223
224 // Returns true if this sequence should yield to another sequence. Uses the
225 // cached scheduling state for comparison.
Yuzhu Shen84ee8572024-09-06 01:30:47226 bool ShouldYieldTo(const Sequence* other) const
227 EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43228
229 // Enables or disables the sequence.
Yuzhu Shen84ee8572024-09-06 01:30:47230 void SetEnabled(bool enabled) EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43231
232 // Sets running state to SCHEDULED. Returns scheduling state for this
233 // sequence used for inserting in the scheduling queue.
Yuzhu Shen84ee8572024-09-06 01:30:47234 SchedulingState SetScheduled() EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43235
236 // Update cached scheduling priority while running.
Yuzhu Shen84ee8572024-09-06 01:30:47237 void UpdateRunningPriority() EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43238
Yuzhu Shen84ee8572024-09-06 01:30:47239 using TaskGraph::Sequence::AddTask;
Lucas Berthou8ab73ae2021-03-17 20:14:52240
Victor Miura651b0c32017-11-18 05:03:43241 // Returns the next order number and closure. Sets running state to RUNNING.
Yuzhu Shen84ee8572024-09-06 01:30:47242 uint32_t BeginTask(base::OnceClosure* task_closure) override
243 EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43244
245 // Called after running the closure returned by BeginTask. Sets running
Yuzhu Shen84ee8572024-09-06 01:30:47246 // state to SCHEDULED.
247 void FinishTask() override EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43248
Yuzhu Shen84ee8572024-09-06 01:30:47249 using TaskGraph::Sequence::ContinueTask;
Victor Miura651b0c32017-11-18 05:03:43250
251 // Continue running the current task with the given closure. Must be called
252 // in between |BeginTask| and |FinishTask|.
Yuzhu Shen84ee8572024-09-06 01:30:47253 void ContinueTask(base::OnceClosure task_closure) override
254 EXCLUSIVE_LOCKS_REQUIRED(lock());
Victor Miura651b0c32017-11-18 05:03:43255
Sunny Sachanandani0eefabc2025-02-06 21:58:30256 void OnFrontTaskUnblocked(uint32_t order_num) override
257 EXCLUSIVE_LOCKS_REQUIRED(lock());
258
Yuzhu Shen84ee8572024-09-06 01:30:47259 SchedulingPriority current_priority() const
260 EXCLUSIVE_LOCKS_REQUIRED(lock()) {
261 return current_priority_;
Yuzhu Shenff6622c2024-08-29 21:18:44262 }
263
Victor Miura651b0c32017-11-18 05:03:43264 private:
Bo Liu3bf6be52020-07-07 15:56:25265 friend class Scheduler;
266
Victor Miura651b0c32017-11-18 05:03:43267 enum RunningState { IDLE, SCHEDULED, RUNNING };
268
Victor Miura651b0c32017-11-18 05:03:43269 // If the sequence is enabled. Sequences are disabled/enabled based on when
270 // the command buffer is descheduled/scheduled.
Yuzhu Shen84ee8572024-09-06 01:30:47271 bool enabled_ GUARDED_BY(lock()) = true;
Victor Miura651b0c32017-11-18 05:03:43272
Yuzhu Shen84ee8572024-09-06 01:30:47273 // TODO(elgarawany): This is no longer needed. Replace with bool running_.
274 RunningState running_state_ GUARDED_BY(lock()) = IDLE;
Victor Miura651b0c32017-11-18 05:03:43275
276 // Cached scheduling state used for comparison with other sequences while
277 // running. Updated in |SetScheduled| and |UpdateRunningPriority|.
Yuzhu Shen84ee8572024-09-06 01:30:47278 SchedulingState scheduling_state_ GUARDED_BY(lock());
Victor Miura651b0c32017-11-18 05:03:43279
Yuzhu Shen84ee8572024-09-06 01:30:47280 // RAW_PTR_EXCLUSION: Scheduler was added to raw_ptr unsupported type for
281 // performance reasons. See raw_ptr.h for more info.
282 RAW_PTR_EXCLUSION Scheduler* const scheduler_ = nullptr;
283 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
Victor Miura651b0c32017-11-18 05:03:43284
285 const SchedulingPriority default_priority_;
Yuzhu Shen84ee8572024-09-06 01:30:47286 SchedulingPriority current_priority_ GUARDED_BY(lock());
Victor Miura651b0c32017-11-18 05:03:43287 };
288
Yuzhu Shen84ee8572024-09-06 01:30:47289 base::Lock& lock() const LOCK_RETURNED(task_graph_.lock()) {
290 return task_graph_.lock();
291 }
Bo Liueca0009f2022-08-25 22:59:32292
Yuzhu Shen84ee8572024-09-06 01:30:47293 Sequence* GetSequence(SequenceId sequence_id)
294 EXCLUSIVE_LOCKS_REQUIRED(lock());
sunnyps8f9139e2017-05-12 17:53:25295
Yuzhu Shen84ee8572024-09-06 01:30:47296 void ScheduleTaskHelper(Scheduler::Task task)
297 EXCLUSIVE_LOCKS_REQUIRED(lock());
Sunny Sachanandani9b8fb342017-08-26 00:49:56298
Yuzhu Shen84ee8572024-09-06 01:30:47299 void TryScheduleSequence(Sequence* sequence) EXCLUSIVE_LOCKS_REQUIRED(lock());
sunnyps8f9139e2017-05-12 17:53:25300
Yuzhu Shen84ee8572024-09-06 01:30:47301 // Returns a sorted list of runnable sequences.
302 const std::vector<SchedulingState>& GetSortedRunnableSequences(
303 base::SingleThreadTaskRunner* task_runner)
304 EXCLUSIVE_LOCKS_REQUIRED(lock());
sunnyps8f9139e2017-05-12 17:53:25305
Yuzhu Shen84ee8572024-09-06 01:30:47306 // Returns true if there are *any* unblocked tasks in sequences assigned to
307 // |task_runner|. This is used to decide if RunNextTask needs to be
308 // rescheduled.
309 bool HasAnyUnblockedTasksOnRunner(
310 const base::SingleThreadTaskRunner* task_runner) const
311 EXCLUSIVE_LOCKS_REQUIRED(lock());
sunnyps8f9139e2017-05-12 17:53:25312
Yuzhu Shen84ee8572024-09-06 01:30:47313 // Finds the sequence of the next task that can be run under |root_sequence|'s
314 // dependency graph. This function will visit sequences that are tied to other
315 // threads in case other threads depends on work on this thread; however, it
316 // will not run any *leaves* that are tied to other threads. nullptr is
317 // returned only if DrDC is enabled and when a sequence's only dependency is a
318 // sequence that is tied to another thread.
319 Sequence* FindNextTaskFromRoot(Sequence* root_sequence)
320 EXCLUSIVE_LOCKS_REQUIRED(lock());
sunnyps8f9139e2017-05-12 17:53:25321
Yuzhu Shen84ee8572024-09-06 01:30:47322 // Calls |FindNextTaskFromRoot| on the ordered list of all sequences, and
323 // returns the first runnable task. Returns nullptr if there is no work to do.
324 Sequence* FindNextTask() EXCLUSIVE_LOCKS_REQUIRED(lock());
325
326 // Executes the closure of the first task for |sequence_id|. Assumes that
327 // the sequence has tasks, and that the first task is unblocked.
328 void ExecuteSequence(SequenceId sequence_id) LOCKS_EXCLUDED(lock());
329
330 // The scheduler's main loop. At each tick, it will call FindNextTask on the
331 // sorted list of sequences to find the highest priority available sequence.
332 // The scheduler then walks the sequence's dependency graph using DFS to find
333 // any unblocked task. If there are multiple choices at any node, the
334 // scheduler picks the dependency with the lowest SchedulingState, effectively
335 // ordering the dependencies by priority and order_num.
336 void RunNextTask() LOCKS_EXCLUDED(lock());
337
338 TaskGraph task_graph_;
339
340 // The Sequence instances in the map are owned by `task_graph_`.
341 base::flat_map<SequenceId, Sequence*> scheduler_sequence_map_
342 GUARDED_BY(lock());
343
344 base::MetricsSubSampler metrics_subsampler_ GUARDED_BY(lock());
sunnyps8f9139e2017-05-12 17:53:25345
Vikas Soni4fa4c09a2021-05-14 20:19:19346 // Each thread will have its own priority queue to schedule sequences
347 // created on that thread.
348 struct PerThreadState {
349 PerThreadState();
350 PerThreadState(PerThreadState&&);
351 ~PerThreadState();
352 PerThreadState& operator=(PerThreadState&&);
Sunny Sachanandanif7c6409d2022-05-18 19:53:43353
Yuzhu Shen84ee8572024-09-06 01:30:47354 // Sorted list of SchedulingState that contains sequences that Runnable. Is
355 // only used so that GetSortedRunnableSequences does not have to re-allocate
356 // a vector. It is rebuilt at each call to GetSortedRunnableSequences.
357 std::vector<SchedulingState> sorted_sequences;
Sunny Sachanandanif7c6409d2022-05-18 19:53:43358
359 // Indicates if the scheduler is actively running tasks on this thread.
Vikas Soni4fa4c09a2021-05-14 20:19:19360 bool running = false;
Sunny Sachanandanif7c6409d2022-05-18 19:53:43361
362 // Indicates when the next task run was scheduled
363 base::TimeTicks run_next_task_scheduled;
Vikas Soni4fa4c09a2021-05-14 20:19:19364 };
Vikas Soni1e0503e2021-06-04 01:29:03365 base::flat_map<base::SingleThreadTaskRunner*, PerThreadState>
Yuzhu Shen84ee8572024-09-06 01:30:47366 per_thread_state_map_ GUARDED_BY(lock());
sunnyps8f9139e2017-05-12 17:53:25367
Yuzhu Shen84ee8572024-09-06 01:30:47368 // Accumulated time the thread was blocked during running task
369 base::TimeDelta total_blocked_time_ GUARDED_BY(lock());
Ramy El Garawanyb1dedd22022-12-06 02:32:50370
Victor Miura651b0c32017-11-18 05:03:43371 private:
372 FRIEND_TEST_ALL_PREFIXES(SchedulerTest, StreamPriorities);
sunnyps8f9139e2017-05-12 17:53:25373};
374
375} // namespace gpu
376
377#endif // GPU_COMMAND_BUFFER_SERVICE_SCHEDULER_H_