#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "gpu/command_buffer/service/scheduler.h"
#include <algorithm>
#include <cstddef>
#include <vector>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/hash/md5_constexpr.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "gpu/command_buffer/service/scheduler_dfs.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/gpu_preferences.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
namespace gpu {
namespace {
uint64_t GetTaskFlowId(uint32_t sequence_id, uint32_t order_num) { … }
}
Scheduler::Task::Task(SequenceId sequence_id,
TaskCallback task_callback,
std::vector<SyncToken> sync_token_fences,
const SyncToken& release,
ReportingCallback report_callback)
: … { … }
Scheduler::Task::Task(SequenceId sequence_id,
base::OnceClosure task_closure,
std::vector<SyncToken> sync_token_fences,
const SyncToken& release,
ReportingCallback report_callback)
: … { … }
Scheduler::Task::Task(SequenceId sequence_id,
base::OnceClosure task_closure,
std::vector<SyncToken> sync_token_fences,
ReportingCallback report_callback)
: … { … }
Scheduler::Task::Task(Task&& other) = default;
Scheduler::Task::~Task() = default;
Scheduler::Task& Scheduler::Task::operator=(Task&& other) = default;
Scheduler::SchedulingState::SchedulingState() = default;
Scheduler::SchedulingState::SchedulingState(const SchedulingState& other) =
default;
Scheduler::SchedulingState::~SchedulingState() = default;
Scheduler::ScopedAddWaitingPriority::ScopedAddWaitingPriority(
Scheduler* scheduler,
SequenceId sequence_id,
SchedulingPriority priority)
: … { … }
Scheduler::ScopedAddWaitingPriority::~ScopedAddWaitingPriority() { … }
void Scheduler::SchedulingState::WriteIntoTrace(
perfetto::TracedValue context) const { … }
Scheduler::Sequence::Task::Task(base::OnceClosure task_closure,
uint32_t order_num,
const SyncToken& release,
ReportingCallback report_callback)
: … { … }
Scheduler::Sequence::Task::Task(Task&& other) = default;
Scheduler::Sequence::Task::~Task() { … }
Scheduler::Sequence::Task& Scheduler::Sequence::Task::operator=(Task&& other) =
default;
Scheduler::Sequence::WaitFence::WaitFence(const SyncToken& sync_token,
uint32_t order_num,
SequenceId release_sequence_id)
: … { … }
Scheduler::Sequence::WaitFence::WaitFence(WaitFence&& other) = default;
Scheduler::Sequence::WaitFence::~WaitFence() = default;
Scheduler::Sequence::WaitFence& Scheduler::Sequence::WaitFence::operator=(
WaitFence&& other) = default;
Scheduler::PerThreadState::PerThreadState() = default;
Scheduler::PerThreadState::PerThreadState(PerThreadState&& other) = default;
Scheduler::PerThreadState::~PerThreadState() = default;
Scheduler::PerThreadState& Scheduler::PerThreadState::operator=(
PerThreadState&& other) = default;
Scheduler::Sequence::Sequence(
Scheduler* scheduler,
SequenceId sequence_id,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
SchedulingPriority priority,
scoped_refptr<SyncPointOrderData> order_data)
: … { … }
Scheduler::Sequence::~Sequence() { … }
void Scheduler::Sequence::UpdateSchedulingPriority() { … }
bool Scheduler::Sequence::NeedsRescheduling() const { … }
bool Scheduler::Sequence::IsRunnable() const { … }
bool Scheduler::Sequence::ShouldYieldTo(const Sequence* other) const { … }
void Scheduler::Sequence::SetEnabled(bool enabled) { … }
Scheduler::SchedulingState Scheduler::Sequence::SetScheduled() { … }
void Scheduler::Sequence::UpdateRunningPriority() { … }
void Scheduler::Sequence::ContinueTask(TaskCallback task_callback) { … }
void Scheduler::Sequence::ContinueTask(base::OnceClosure task_closure) { … }
uint32_t Scheduler::Sequence::ScheduleTask(TaskCallback task_callback,
const SyncToken& release,
ReportingCallback report_callback) { … }
uint32_t Scheduler::Sequence::ScheduleTask(base::OnceClosure task_closure,
const SyncToken& release,
ReportingCallback report_callback) { … }
base::TimeDelta Scheduler::Sequence::FrontTaskWaitingDependencyDelta() { … }
base::TimeDelta Scheduler::Sequence::FrontTaskSchedulingDelay() { … }
uint32_t Scheduler::Sequence::BeginTask(base::OnceClosure* task_closure) { … }
void Scheduler::Sequence::FinishTask() { … }
void Scheduler::Sequence::SetLastTaskFirstDependencyTimeIfNeeded() { … }
void Scheduler::Sequence::AddWaitFence(const SyncToken& sync_token,
uint32_t order_num,
SequenceId release_sequence_id) { … }
void Scheduler::Sequence::RemoveWaitFence(const SyncToken& sync_token,
uint32_t order_num,
SequenceId release_sequence_id) { … }
void Scheduler::Sequence::PropagatePriority(SchedulingPriority priority) { … }
void Scheduler::Sequence::AddWaitingPriority(SchedulingPriority priority) { … }
void Scheduler::Sequence::RemoveWaitingPriority(SchedulingPriority priority) { … }
void Scheduler::Sequence::ChangeWaitingPriority(
SchedulingPriority old_priority,
SchedulingPriority new_priority) { … }
void Scheduler::Sequence::AddClientWait(CommandBufferId command_buffer_id) { … }
void Scheduler::Sequence::RemoveClientWait(CommandBufferId command_buffer_id) { … }
void Scheduler::Sequence::CreateSyncPointClientState(
CommandBufferNamespace namespace_id,
CommandBufferId command_buffer_id) { … }
base::OnceClosure Scheduler::Sequence::CreateTaskClosure(
TaskCallback task_callback) { … }
Scheduler::Scheduler(SyncPointManager* sync_point_manager)
: … { … }
Scheduler::~Scheduler() { … }
SequenceId Scheduler::CreateSequence(
SchedulingPriority priority,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
SequenceId Scheduler::CreateSequenceForTesting(SchedulingPriority priority) { … }
void Scheduler::DestroySequence(SequenceId sequence_id) { … }
void Scheduler::CreateSyncPointClientState(SequenceId sequence_id,
CommandBufferNamespace namespace_id,
CommandBufferId command_buffer_id) { … }
Scheduler::Sequence* Scheduler::GetSequence(SequenceId sequence_id) { … }
void Scheduler::EnableSequence(SequenceId sequence_id) { … }
void Scheduler::DisableSequence(SequenceId sequence_id) { … }
void Scheduler::RaisePriorityForClientWait(SequenceId sequence_id,
CommandBufferId command_buffer_id) { … }
void Scheduler::ResetPriorityForClientWait(SequenceId sequence_id,
CommandBufferId command_buffer_id) { … }
void Scheduler::ScheduleTask(Task task) { … }
void Scheduler::ScheduleTasks(std::vector<Task> tasks) { … }
void Scheduler::ScheduleTaskHelper(Task task) { … }
void Scheduler::ContinueTask(SequenceId sequence_id,
TaskCallback task_callback) { … }
void Scheduler::ContinueTask(SequenceId sequence_id,
base::OnceClosure task_closure) { … }
bool Scheduler::ShouldYield(SequenceId sequence_id) { … }
void Scheduler::AddWaitingPriority(SequenceId sequence_id,
SchedulingPriority priority) { … }
void Scheduler::RemoveWaitingPriority(SequenceId sequence_id,
SchedulingPriority priority) { … }
void Scheduler::SyncTokenFenceReleased(const SyncToken& sync_token,
uint32_t order_num,
SequenceId release_sequence_id,
SequenceId waiting_sequence_id) { … }
void Scheduler::TryScheduleSequence(Sequence* sequence) { … }
std::vector<Scheduler::SchedulingState>&
Scheduler::RebuildSchedulingQueueIfNeeded(
base::SingleThreadTaskRunner* task_runner) { … }
void Scheduler::RunNextTask() { … }
base::SingleThreadTaskRunner* Scheduler::GetTaskRunnerForTesting(
SequenceId sequence_id) { … }
}