#include "third_party/blink/renderer/platform/scheduler/worker/worker_thread_scheduler.h"
#include <memory>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequence_manager/sequence_manager.h"
#include "base/task/sequence_manager/task_queue.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/scheduler/common/auto_advancing_virtual_time_domain.h"
#include "third_party/blink/renderer/platform/scheduler/common/features.h"
#include "third_party/blink/renderer/platform/scheduler/common/metrics_helper.h"
#include "third_party/blink/renderer/platform/scheduler/common/process_state.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/cpu_time_budget_pool.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/task_queue_throttler.h"
#include "third_party/blink/renderer/platform/scheduler/common/throttling/wake_up_budget_pool.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/scheduler/worker/non_main_thread_scheduler_helper.h"
#include "third_party/blink/renderer/platform/scheduler/worker/worker_scheduler_impl.h"
#include "third_party/blink/renderer/platform/scheduler/worker/worker_scheduler_proxy.h"
namespace blink {
namespace scheduler {
TaskQueue;
namespace {
const char kWorkerThrottlingTrial[] = …;
const char kWorkerThrottlingMaxBudgetParam[] = …;
const char kWorkerThrottlingRecoveryRateParam[] = …;
const char kWorkerThrottlingMaxDelayParam[] = …;
constexpr base::TimeDelta kDefaultMaxBudget = …;
constexpr double kDefaultRecoveryRate = …;
constexpr base::TimeDelta kDefaultMaxThrottlingDelay = …;
std::optional<base::TimeDelta> GetMaxBudgetLevel() { … }
double GetBudgetRecoveryRate() { … }
std::optional<base::TimeDelta> GetMaxThrottlingDelay() { … }
std::unique_ptr<ukm::MojoUkmRecorder> CreateMojoUkmRecorder() { … }
}
WorkerThreadScheduler::WorkerThreadScheduler(
ThreadType thread_type,
base::sequence_manager::SequenceManager* sequence_manager,
WorkerSchedulerProxy* proxy)
: … { … }
WorkerThreadScheduler::~WorkerThreadScheduler() { … }
scoped_refptr<SingleThreadIdleTaskRunner>
WorkerThreadScheduler::IdleTaskRunner() { … }
scoped_refptr<base::SingleThreadTaskRunner>
WorkerThreadScheduler::V8TaskRunner() { … }
scoped_refptr<base::SingleThreadTaskRunner>
WorkerThreadScheduler::CleanupTaskRunner() { … }
scoped_refptr<base::SingleThreadTaskRunner>
WorkerThreadScheduler::CompositorTaskRunner() { … }
bool WorkerThreadScheduler::ShouldYieldForHighPriorityWork() { … }
void WorkerThreadScheduler::AddTaskObserver(base::TaskObserver* task_observer) { … }
void WorkerThreadScheduler::RemoveTaskObserver(
base::TaskObserver* task_observer) { … }
void WorkerThreadScheduler::Shutdown() { … }
scoped_refptr<NonMainThreadTaskQueue>
WorkerThreadScheduler::DefaultTaskQueue() { … }
void WorkerThreadScheduler::Init() { … }
void WorkerThreadScheduler::OnTaskCompleted(
NonMainThreadTaskQueue* task_queue,
const base::sequence_manager::Task& task,
TaskQueue::TaskTiming* task_timing,
base::LazyNow* lazy_now) { … }
SchedulerHelper* WorkerThreadScheduler::GetSchedulerHelperForTesting() { … }
bool WorkerThreadScheduler::CanEnterLongIdlePeriod(base::TimeTicks,
base::TimeDelta*) { … }
base::TimeTicks WorkerThreadScheduler::CurrentIdleTaskDeadlineForTesting()
const { … }
void WorkerThreadScheduler::OnLifecycleStateChanged(
SchedulingLifecycleState lifecycle_state) { … }
void WorkerThreadScheduler::RegisterWorkerScheduler(
WorkerSchedulerImpl* worker_scheduler) { … }
void WorkerThreadScheduler::UnregisterWorkerScheduler(
WorkerSchedulerImpl* worker_scheduler) { … }
scoped_refptr<NonMainThreadTaskQueue>
WorkerThreadScheduler::ControlTaskQueue() { … }
void WorkerThreadScheduler::CreateBudgetPools() { … }
void WorkerThreadScheduler::RecordTaskUkm(
NonMainThreadTaskQueue* worker_task_queue,
const base::sequence_manager::Task& task,
const base::sequence_manager::TaskQueue::TaskTiming& task_timing) { … }
void WorkerThreadScheduler::SetUkmRecorderForTest(
std::unique_ptr<ukm::UkmRecorder> ukm_recorder) { … }
void WorkerThreadScheduler::SetUkmTaskSamplingRateForTest(double rate) { … }
void WorkerThreadScheduler::SetCPUTimeBudgetPoolForTesting(
std::unique_ptr<CPUTimeBudgetPool> cpu_time_budget_pool) { … }
HashSet<WorkerSchedulerImpl*>&
WorkerThreadScheduler::GetWorkerSchedulersForTesting() { … }
void WorkerThreadScheduler::PerformMicrotaskCheckpoint() { … }
base::SequencedTaskRunner* WorkerThreadScheduler::GetVirtualTimeTaskRunner() { … }
void WorkerThreadScheduler::OnVirtualTimeDisabled() { … }
void WorkerThreadScheduler::OnVirtualTimePaused() { … }
void WorkerThreadScheduler::OnVirtualTimeResumed() { … }
void WorkerThreadScheduler::PostIdleTask(const base::Location& location,
Thread::IdleTask task) { … }
void WorkerThreadScheduler::PostNonNestableIdleTask(
const base::Location& location,
Thread::IdleTask task) { … }
void WorkerThreadScheduler::PostDelayedIdleTask(const base::Location& location,
base::TimeDelta delay,
Thread::IdleTask task) { … }
base::TimeTicks WorkerThreadScheduler::MonotonicallyIncreasingVirtualTime() { … }
void WorkerThreadScheduler::SetV8Isolate(v8::Isolate* isolate) { … }
}
}