[task] Delete meaningless timer slack calls
TIMER_SLACK_NONE is the default thus a no-op. TIMER_SLACK_MAXIMUM only has effect on mac (UI) MessagePump, though none of the calls to TIMER_SLACK_MAXIMUM run on a thread that supports it; blink::MainThreadSchedulerImpl used to be the only meaningful case, but the message pump was replaced by the default one: https://chromium-review.googlesource.com/c/chromium/src/+/4369441 ThreadType and DelayPolicy are now used to control thread policies and timer leeway. Change-Id: I9638ea298d9cd87843c00eda15513541a512608e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4371223 Reviewed-by: Gabriel Charette <gab@chromium.org> Owners-Override: Gabriel Charette <gab@chromium.org> Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/main@{#1168774}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
40ae25ea96
commit
ef5dcca880
base
BUILD.gn
message_loop
message_pump.ccmessage_pump.hmessage_pump_mac.hmessage_pump_mac.mmmessage_pump_unittest.cctimer_slack.h
task
sequence_manager
sequence_manager.hsequence_manager_impl.ccsequence_manager_impl.hthread_controller.hthread_controller_impl.ccthread_controller_impl.hthread_controller_with_message_pump_impl.ccthread_controller_with_message_pump_impl.hthread_controller_with_message_pump_impl_unittest.cc
thread_pool
threading
codelabs/threading_and_scheduling
content
browser
child
gpu
gpu/ipc/service
services
audio
network
public
proxy_resolver
third_party/blink/renderer/platform/scheduler
@ -470,7 +470,6 @@ component("base") {
|
||||
"message_loop/message_pump_for_io.h",
|
||||
"message_loop/message_pump_for_ui.h",
|
||||
"message_loop/message_pump_type.h",
|
||||
"message_loop/timer_slack.h",
|
||||
"message_loop/work_id_provider.cc",
|
||||
"message_loop/work_id_provider.h",
|
||||
"metrics/bucket_ranges.cc",
|
||||
|
@ -27,9 +27,6 @@ MessagePump::MessagePump() = default;
|
||||
|
||||
MessagePump::~MessagePump() = default;
|
||||
|
||||
void MessagePump::SetTimerSlack(TimerSlack) {
|
||||
}
|
||||
|
||||
// static
|
||||
void MessagePump::OverrideMessagePumpForUIFactory(MessagePumpFactory* factory) {
|
||||
DCHECK(!message_pump_for_ui_factory_);
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "base/check_op.h"
|
||||
#include "base/memory/raw_ptr_exclusion.h"
|
||||
#include "base/message_loop/message_pump_type.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/sequence_checker.h"
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
@ -252,9 +251,6 @@ class BASE_EXPORT MessagePump {
|
||||
// entered.
|
||||
virtual void ScheduleDelayedWork(
|
||||
const Delegate::NextWorkInfo& next_work_info) = 0;
|
||||
|
||||
// Sets the timer slack to the specified value.
|
||||
virtual void SetTimerSlack(TimerSlack timer_slack);
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "base/containers/stack.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "build/build_config.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
@ -76,7 +75,6 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
|
||||
void ScheduleWork() override;
|
||||
void ScheduleDelayedWork(
|
||||
const Delegate::NextWorkInfo& next_work_info) override;
|
||||
void SetTimerSlack(TimerSlack timer_slack) override;
|
||||
|
||||
#if BUILDFLAG(IS_IOS)
|
||||
// Some iOS message pumps do not support calling |Run()| to spin the main
|
||||
@ -233,8 +231,6 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
|
||||
// (weak) Delegate passed as an argument to the innermost Run call.
|
||||
raw_ptr<Delegate> delegate_ = nullptr;
|
||||
|
||||
base::TimerSlack timer_slack_ = base::TIMER_SLACK_NONE;
|
||||
|
||||
// Time at which `delayed_work_timer_` is set to fire.
|
||||
base::TimeTicks delayed_work_scheduled_at_ = base::TimeTicks::Max();
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/scoped_policy.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/metrics/histogram_samples.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/run_loop.h"
|
||||
@ -214,13 +213,6 @@ void MessagePumpCFRunLoopBase::ScheduleDelayedWork(
|
||||
} else {
|
||||
const double delay_seconds = next_work_info.remaining_delay().InSecondsF();
|
||||
|
||||
// The tolerance needs to be set before the fire date or it may be ignored.
|
||||
if (timer_slack_ == TIMER_SLACK_MAXIMUM) {
|
||||
CFRunLoopTimerSetTolerance(delayed_work_timer_, delay_seconds * 0.5);
|
||||
} else {
|
||||
CFRunLoopTimerSetTolerance(delayed_work_timer_, 0);
|
||||
}
|
||||
|
||||
CFRunLoopTimerSetNextFireDate(delayed_work_timer_,
|
||||
CFAbsoluteTimeGetCurrent() + delay_seconds);
|
||||
}
|
||||
@ -228,10 +220,6 @@ void MessagePumpCFRunLoopBase::ScheduleDelayedWork(
|
||||
delayed_work_scheduled_at_ = next_work_info.delayed_run_time;
|
||||
}
|
||||
|
||||
void MessagePumpCFRunLoopBase::SetTimerSlack(TimerSlack timer_slack) {
|
||||
timer_slack_ = timer_slack;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_IOS)
|
||||
void MessagePumpCFRunLoopBase::Attach(Delegate* delegate) {}
|
||||
|
||||
@ -255,6 +243,7 @@ MessagePumpCFRunLoopBase::MessagePumpCFRunLoopBase(int initial_mode_mask) {
|
||||
/*order=*/0,
|
||||
/*callout=*/RunDelayedWorkTimer,
|
||||
/*context=*/&timer_context));
|
||||
CFRunLoopTimerSetTolerance(delayed_work_timer_, 0);
|
||||
|
||||
CFRunLoopSourceContext source_context = {0};
|
||||
source_context.info = this;
|
||||
|
@ -301,94 +301,6 @@ TEST_P(MessagePumpTest, YieldToNativeRequestedSmokeTest) {
|
||||
message_pump_->Run(&delegate);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class TimerSlackTestDelegate : public MessagePump::Delegate {
|
||||
public:
|
||||
TimerSlackTestDelegate(MessagePump* message_pump)
|
||||
: message_pump_(message_pump) {
|
||||
// We first schedule a delayed task far in the future with maximum timer
|
||||
// slack.
|
||||
message_pump_->SetTimerSlack(TIMER_SLACK_MAXIMUM);
|
||||
const TimeTicks now = TimeTicks::Now();
|
||||
message_pump_->ScheduleDelayedWork({now + Hours(1), now});
|
||||
|
||||
// Since we have no other work pending, the pump will initially be idle.
|
||||
action_.store(NONE);
|
||||
}
|
||||
|
||||
void OnBeginWorkItem() override {}
|
||||
void OnEndWorkItem(int run_level_depth) override {}
|
||||
int RunDepth() override { return 0; }
|
||||
void BeforeWait() override {}
|
||||
|
||||
MessagePump::Delegate::NextWorkInfo DoWork() override {
|
||||
switch (action_.load()) {
|
||||
case NONE:
|
||||
break;
|
||||
case SCHEDULE_DELAYED_WORK: {
|
||||
// After being woken up by the other thread, we let the pump know that
|
||||
// the next delayed task is in fact much sooner than the 1 hour delay it
|
||||
// was aware of. If the pump refreshes its timer correctly, it will wake
|
||||
// up shortly, finishing the test.
|
||||
action_.store(QUIT);
|
||||
TimeTicks now = TimeTicks::Now();
|
||||
return {now + Milliseconds(50), now};
|
||||
}
|
||||
case QUIT:
|
||||
message_pump_->Quit();
|
||||
break;
|
||||
}
|
||||
return MessagePump::Delegate::NextWorkInfo{TimeTicks::Max()};
|
||||
}
|
||||
|
||||
bool DoIdleWork() override { return false; }
|
||||
|
||||
void WakeUpFromOtherThread() {
|
||||
action_.store(SCHEDULE_DELAYED_WORK);
|
||||
message_pump_->ScheduleWork();
|
||||
}
|
||||
|
||||
private:
|
||||
enum Action {
|
||||
NONE,
|
||||
SCHEDULE_DELAYED_WORK,
|
||||
QUIT,
|
||||
};
|
||||
|
||||
const raw_ptr<MessagePump> message_pump_;
|
||||
std::atomic<Action> action_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_P(MessagePumpTest, TimerSlackWithLongDelays) {
|
||||
// This is a regression test for an issue where the iOS message pump fails to
|
||||
// run delayed work when timer slack is enabled. The steps needed to trigger
|
||||
// this are:
|
||||
//
|
||||
// 1. The message pump timer slack is set to maximum.
|
||||
// 2. A delayed task is posted for far in the future (e.g., 1h).
|
||||
// 3. The system goes idle at least for a few seconds.
|
||||
// 4. Another delayed task is posted with a much smaller delay.
|
||||
//
|
||||
// The following message pump test delegate automatically runs through this
|
||||
// sequence.
|
||||
TimerSlackTestDelegate delegate(message_pump_.get());
|
||||
|
||||
// We use another thread to wake up the pump after 2 seconds to allow the
|
||||
// system to enter an idle state. This delay was determined experimentally on
|
||||
// the iPhone 6S simulator.
|
||||
Thread thread("Waking thread");
|
||||
thread.StartAndWaitForTesting();
|
||||
thread.task_runner()->PostDelayedTask(
|
||||
FROM_HERE,
|
||||
BindLambdaForTesting([&delegate] { delegate.WakeUpFromOtherThread(); }),
|
||||
Seconds(2));
|
||||
|
||||
message_pump_->Run(&delegate);
|
||||
}
|
||||
|
||||
TEST_P(MessagePumpTest, RunWithoutScheduleWorkInvokesDoWork) {
|
||||
testing::InSequence sequence;
|
||||
testing::StrictMock<MockMessagePumpDelegate> delegate(GetParam());
|
||||
|
@ -1,25 +0,0 @@
|
||||
// Copyright 2014 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef BASE_MESSAGE_LOOP_TIMER_SLACK_H_
|
||||
#define BASE_MESSAGE_LOOP_TIMER_SLACK_H_
|
||||
|
||||
#include "base/base_export.h"
|
||||
#include "base/time/time.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
// Amount of timer slack to use for delayed timers. Increasing timer slack
|
||||
// allows the OS to coalesce timers more effectively.
|
||||
enum TimerSlack {
|
||||
// Lowest value for timer slack allowed by OS.
|
||||
TIMER_SLACK_NONE,
|
||||
|
||||
// Maximal value for timer slack allowed by OS.
|
||||
TIMER_SLACK_MAXIMUM
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_MESSAGE_LOOP_TIMER_SLACK_H_
|
@ -15,7 +15,6 @@
|
||||
#include "base/dcheck_is_on.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/message_loop/message_pump_type.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/task/sequence_manager/task_queue_impl.h"
|
||||
#include "base/task/sequence_manager/task_time_observer.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
@ -272,10 +271,6 @@ class BASE_EXPORT SequenceManager {
|
||||
// logic at the cost of a potentially worse latency. 1 by default.
|
||||
virtual void SetWorkBatchSize(int work_batch_size) = 0;
|
||||
|
||||
// Requests desired timer precision from the OS.
|
||||
// Has no effect on some platforms.
|
||||
virtual void SetTimerSlack(TimerSlack timer_slack) = 0;
|
||||
|
||||
// Enables crash keys that can be set in the scope of a task which help
|
||||
// to identify the culprit if upcoming work results in a crash.
|
||||
// Key names must be thread-specific to avoid races and corrupted crash dumps.
|
||||
|
@ -955,11 +955,6 @@ void SequenceManagerImpl::SetWorkBatchSize(int work_batch_size) {
|
||||
controller_->SetWorkBatchSize(work_batch_size);
|
||||
}
|
||||
|
||||
void SequenceManagerImpl::SetTimerSlack(TimerSlack timer_slack) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(associated_thread_->thread_checker);
|
||||
controller_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
void SequenceManagerImpl::AddTaskObserver(TaskObserver* task_observer) {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(associated_thread_->thread_checker);
|
||||
main_thread_only().task_observers.AddObserver(task_observer);
|
||||
|
@ -130,7 +130,6 @@ class BASE_EXPORT SequenceManagerImpl
|
||||
void ReclaimMemory() override;
|
||||
bool GetAndClearSystemIsQuiescentBit() override;
|
||||
void SetWorkBatchSize(int work_batch_size) override;
|
||||
void SetTimerSlack(TimerSlack timer_slack) override;
|
||||
void EnableCrashKeys(const char* async_stack_crash_key) override;
|
||||
const MetricRecordingSettings& GetMetricRecordingSettings() const override;
|
||||
size_t GetPendingTaskCountForTesting() const override;
|
||||
|
@ -109,10 +109,6 @@ class BASE_EXPORT ThreadController {
|
||||
// Must be called before the first call to Schedule*Work().
|
||||
virtual void SetSequencedTaskSource(SequencedTaskSource*) = 0;
|
||||
|
||||
// Requests desired timer precision from the OS.
|
||||
// Has no effect on some platforms.
|
||||
virtual void SetTimerSlack(TimerSlack timer_slack) = 0;
|
||||
|
||||
// Completes delayed initialization of unbound ThreadControllers.
|
||||
// BindToCurrentThread(MessageLoopBase*) or BindToCurrentThread(MessagePump*)
|
||||
// may only be called once.
|
||||
|
@ -78,12 +78,6 @@ void ThreadControllerImpl::SetSequencedTaskSource(
|
||||
sequence_ = sequence;
|
||||
}
|
||||
|
||||
void ThreadControllerImpl::SetTimerSlack(TimerSlack timer_slack) {
|
||||
if (!funneled_sequence_manager_)
|
||||
return;
|
||||
funneled_sequence_manager_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
void ThreadControllerImpl::ScheduleWork() {
|
||||
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("sequence_manager"),
|
||||
"ThreadControllerImpl::ScheduleWork::PostTask");
|
||||
|
@ -51,7 +51,6 @@ class BASE_EXPORT ThreadControllerImpl : public ThreadController,
|
||||
void SetNextDelayedDoWork(LazyNow* lazy_now,
|
||||
absl::optional<WakeUp> wake_up) override;
|
||||
void SetSequencedTaskSource(SequencedTaskSource* sequence) override;
|
||||
void SetTimerSlack(TimerSlack timer_slack) override;
|
||||
bool RunsTasksInCurrentSequence() override;
|
||||
void SetDefaultTaskRunner(scoped_refptr<SingleThreadTaskRunner>) override;
|
||||
scoped_refptr<SingleThreadTaskRunner> GetDefaultTaskRunner() override;
|
||||
|
@ -189,12 +189,6 @@ void ThreadControllerWithMessagePumpImpl::SetWorkBatchSize(
|
||||
main_thread_only().work_batch_size = work_batch_size;
|
||||
}
|
||||
|
||||
void ThreadControllerWithMessagePumpImpl::SetTimerSlack(
|
||||
TimerSlack timer_slack) {
|
||||
DCHECK(RunsTasksInCurrentSequence());
|
||||
pump_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
void ThreadControllerWithMessagePumpImpl::WillQueueTask(
|
||||
PendingTask* pending_task) {
|
||||
task_annotator_.WillQueueTask("SequenceManager PostTask", pending_task);
|
||||
|
@ -62,7 +62,6 @@ class BASE_EXPORT ThreadControllerWithMessagePumpImpl
|
||||
void ScheduleWork() override;
|
||||
void SetNextDelayedDoWork(LazyNow* lazy_now,
|
||||
absl::optional<WakeUp> wake_up) override;
|
||||
void SetTimerSlack(TimerSlack timer_slack) override;
|
||||
bool RunsTasksInCurrentSequence() override;
|
||||
void SetDefaultTaskRunner(
|
||||
scoped_refptr<SingleThreadTaskRunner> task_runner) override;
|
||||
|
@ -89,7 +89,6 @@ class MockMessagePump : public MessagePump {
|
||||
MOCK_METHOD0(Quit, void());
|
||||
MOCK_METHOD0(ScheduleWork, void());
|
||||
MOCK_METHOD1(ScheduleDelayedWork_TimeTicks, void(const TimeTicks&));
|
||||
MOCK_METHOD1(SetTimerSlack, void(TimerSlack));
|
||||
|
||||
void ScheduleDelayedWork(
|
||||
const MessagePump::Delegate::NextWorkInfo& next_work_info) override {
|
||||
|
@ -136,7 +136,6 @@ void ThreadPoolImpl::Start(const ThreadPoolInstance::InitParams& init_params,
|
||||
#else
|
||||
MessagePumpType::DEFAULT;
|
||||
#endif
|
||||
service_thread_options.timer_slack = TIMER_SLACK_MAXIMUM;
|
||||
CHECK(service_thread_.StartWithOptions(std::move(service_thread_options)));
|
||||
if (g_synchronous_thread_start_for_testing)
|
||||
service_thread_.WaitUntilThreadStarted();
|
||||
|
@ -93,10 +93,9 @@ class SequenceManagerThreadDelegate : public Thread::Delegate {
|
||||
return sequence_manager_->GetTaskRunner();
|
||||
}
|
||||
|
||||
void BindToCurrentThread(TimerSlack timer_slack) override {
|
||||
void BindToCurrentThread() override {
|
||||
sequence_manager_->BindToMessagePump(
|
||||
std::move(message_pump_factory_).Run());
|
||||
sequence_manager_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -118,7 +117,6 @@ Thread::Options::Options(ThreadType thread_type) : thread_type(thread_type) {}
|
||||
Thread::Options::Options(Options&& other)
|
||||
: message_pump_type(std::move(other.message_pump_type)),
|
||||
delegate(std::move(other.delegate)),
|
||||
timer_slack(std::move(other.timer_slack)),
|
||||
message_pump_factory(std::move(other.message_pump_factory)),
|
||||
stack_size(std::move(other.stack_size)),
|
||||
thread_type(std::move(other.thread_type)),
|
||||
@ -131,7 +129,6 @@ Thread::Options& Thread::Options::operator=(Thread::Options&& other) {
|
||||
|
||||
message_pump_type = std::move(other.message_pump_type);
|
||||
delegate = std::move(other.delegate);
|
||||
timer_slack = std::move(other.timer_slack);
|
||||
message_pump_factory = std::move(other.message_pump_factory);
|
||||
stack_size = std::move(other.stack_size);
|
||||
thread_type = std::move(other.thread_type);
|
||||
@ -189,8 +186,6 @@ bool Thread::StartWithOptions(Options options) {
|
||||
|
||||
SetThreadWasQuitProperly(false);
|
||||
|
||||
timer_slack_ = options.timer_slack;
|
||||
|
||||
if (options.delegate) {
|
||||
DCHECK(!options.message_pump_factory);
|
||||
delegate_ = std::move(options.delegate);
|
||||
@ -377,7 +372,7 @@ void Thread::ThreadMain() {
|
||||
// Lazily initialize the |message_loop| so that it can run on this thread.
|
||||
DCHECK(delegate_);
|
||||
// This binds CurrentThread and SingleThreadTaskRunner::CurrentDefaultHandle.
|
||||
delegate_->BindToCurrentThread(timer_slack_);
|
||||
delegate_->BindToCurrentThread();
|
||||
DCHECK(CurrentThread::Get());
|
||||
DCHECK(SingleThreadTaskRunner::HasCurrentDefault());
|
||||
#if (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL)) || BUILDFLAG(IS_FUCHSIA)
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/message_loop/message_pump_type.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/sequence_checker.h"
|
||||
#include "base/synchronization/atomic_flag.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
@ -66,9 +65,8 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
|
||||
virtual scoped_refptr<SingleThreadTaskRunner> GetDefaultTaskRunner() = 0;
|
||||
|
||||
// Binds a RunLoop::Delegate and task runner CurrentDefaultHandle to the
|
||||
// thread. The underlying MessagePump will have its |timer_slack| set to the
|
||||
// specified amount.
|
||||
virtual void BindToCurrentThread(TimerSlack timer_slack) = 0;
|
||||
// thread.
|
||||
virtual void BindToCurrentThread() = 0;
|
||||
};
|
||||
|
||||
struct BASE_EXPORT Options {
|
||||
@ -90,9 +88,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
|
||||
// of |delegate| will be transferred to the thread.
|
||||
std::unique_ptr<Delegate> delegate = nullptr;
|
||||
|
||||
// Specifies timer slack for thread message loop.
|
||||
TimerSlack timer_slack = TIMER_SLACK_NONE;
|
||||
|
||||
// Used to create the MessagePump for the MessageLoop. The callback is Run()
|
||||
// on the thread. If message_pump_factory.is_null(), then a MessagePump
|
||||
// appropriate for |message_pump_type| is created. Setting this forces the
|
||||
@ -325,10 +320,6 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
|
||||
|
||||
raw_ptr<RunLoop> run_loop_ = nullptr;
|
||||
|
||||
// Stores Options::timer_slack_ until the sequence manager has been bound to
|
||||
// a thread.
|
||||
TimerSlack timer_slack_ = TIMER_SLACK_NONE;
|
||||
|
||||
// The name of the thread. Used for debugging purposes.
|
||||
const std::string name_;
|
||||
|
||||
|
@ -564,10 +564,9 @@ class SequenceManagerThreadDelegate : public Thread::Delegate {
|
||||
return task_queue_->task_runner();
|
||||
}
|
||||
|
||||
void BindToCurrentThread(base::TimerSlack timer_slack) override {
|
||||
void BindToCurrentThread() override {
|
||||
sequence_manager_->BindToMessagePump(
|
||||
base::MessagePump::Create(base::MessagePumpType::DEFAULT));
|
||||
sequence_manager_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -58,10 +58,9 @@ class IOThreadDelegate : public base::Thread::Delegate {
|
||||
// This is similar to i.e.,
|
||||
// `content::BrowserIOThreadDelegate::BindToCurrentThread()`, and is the first
|
||||
// function to run on the new physical thread.
|
||||
void BindToCurrentThread(base::TimerSlack timer_slack) override {
|
||||
void BindToCurrentThread() override {
|
||||
owned_sequence_manager_->BindToMessagePump(
|
||||
base::MessagePump::Create(base::MessagePumpType::IO));
|
||||
owned_sequence_manager_->SetTimerSlack(timer_slack);
|
||||
owned_sequence_manager_->SetDefaultTaskRunner(GetDefaultTaskRunner());
|
||||
}
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetDefaultTaskRunner() override {
|
||||
|
@ -72,10 +72,9 @@ class SequenceManagerThreadDelegate : public base::Thread::Delegate {
|
||||
return default_task_runner_;
|
||||
}
|
||||
|
||||
void BindToCurrentThread(base::TimerSlack timer_slack) override {
|
||||
void BindToCurrentThread() override {
|
||||
ui_sequence_manager_->BindToMessagePump(
|
||||
base::MessagePump::Create(base::MessagePumpType::DEFAULT));
|
||||
ui_sequence_manager_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -49,12 +49,10 @@ BrowserIOThreadDelegate::GetDefaultTaskRunner() {
|
||||
|
||||
BrowserIOThreadDelegate::~BrowserIOThreadDelegate() = default;
|
||||
|
||||
void BrowserIOThreadDelegate::BindToCurrentThread(
|
||||
base::TimerSlack timer_slack) {
|
||||
void BrowserIOThreadDelegate::BindToCurrentThread() {
|
||||
DCHECK(sequence_manager_);
|
||||
sequence_manager_->BindToMessagePump(
|
||||
base::MessagePump::Create(base::MessagePumpType::IO));
|
||||
sequence_manager_->SetTimerSlack(timer_slack);
|
||||
sequence_manager_->SetDefaultTaskRunner(GetDefaultTaskRunner());
|
||||
sequence_manager_->EnableCrashKeys("io_scheduler_async_stack");
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class CONTENT_EXPORT BrowserIOThreadDelegate : public base::Thread::Delegate {
|
||||
}
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetDefaultTaskRunner() override;
|
||||
void BindToCurrentThread(base::TimerSlack timer_slack) override;
|
||||
void BindToCurrentThread() override;
|
||||
|
||||
bool allow_blocking_for_testing() const {
|
||||
return allow_blocking_for_testing_;
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/memory_pressure_listener.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/message_loop/timer_slack.h"
|
||||
#include "base/metrics/field_trial.h"
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/power_monitor/power_monitor.h"
|
||||
|
@ -480,9 +480,7 @@ bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
|
||||
base::BindOnce(GpuProcessPreSandboxHook), sandbox_options);
|
||||
|
||||
if (watchdog_thread) {
|
||||
base::Thread::Options thread_options;
|
||||
thread_options.timer_slack = base::TIMER_SLACK_MAXIMUM;
|
||||
watchdog_thread->StartWithOptions(std::move(thread_options));
|
||||
watchdog_thread->Start();
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -147,9 +147,7 @@ std::unique_ptr<GpuWatchdogThread> GpuWatchdogThread::Create(
|
||||
const std::string& thread_name) {
|
||||
auto watchdog_thread = base::WrapUnique(new GpuWatchdogThread(
|
||||
timeout, init_factor, restart_factor, is_test_mode, thread_name));
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_MAXIMUM;
|
||||
watchdog_thread->StartWithOptions(std::move(options));
|
||||
watchdog_thread->Start();
|
||||
if (start_backgrounded)
|
||||
watchdog_thread->OnBackgrounded();
|
||||
return watchdog_thread;
|
||||
|
@ -106,7 +106,6 @@ base::SingleThreadTaskRunner* MainThread::GetWorkerTaskRunner() {
|
||||
(worker_task_runner_ && worker_task_runner_->BelongsToCurrentThread()));
|
||||
if (!worker_task_runner_) {
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_NONE;
|
||||
options.thread_type = base::ThreadType::kRealtimeAudio;
|
||||
CHECK(worker_thread_.StartWithOptions(std::move(options)));
|
||||
worker_task_runner_ = worker_thread_.task_runner();
|
||||
|
@ -37,7 +37,6 @@ TEST_F(RealtimeAudioThreadTest, StartStop) {
|
||||
RealtimeAudioThread thread("TestThread", kPeriod);
|
||||
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_NONE;
|
||||
options.thread_type = base::ThreadType::kRealtimeAudio;
|
||||
EXPECT_TRUE(thread.StartWithOptions(std::move(options)));
|
||||
|
||||
@ -50,7 +49,6 @@ TEST_F(RealtimeAudioThreadTest, StartDestroy) {
|
||||
RealtimeAudioThread thread("TestThread", kPeriod);
|
||||
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_NONE;
|
||||
options.thread_type = base::ThreadType::kRealtimeAudio;
|
||||
EXPECT_TRUE(thread.StartWithOptions(std::move(options)));
|
||||
|
||||
|
@ -220,7 +220,6 @@ void StreamFactory::CreateLoopbackStream(
|
||||
} else {
|
||||
TRACE_EVENT_BEGIN0("audio", "Start Loopback Worker");
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_NONE;
|
||||
options.thread_type = base::ThreadType::kRealtimeAudio;
|
||||
if (loopback_worker_thread_.StartWithOptions(std::move(options))) {
|
||||
task_runner = loopback_worker_thread_.task_runner();
|
||||
|
@ -74,11 +74,10 @@ ThreadDelegate::GetDefaultTaskRunner() {
|
||||
return default_task_queue_->task_runner();
|
||||
}
|
||||
|
||||
void ThreadDelegate::BindToCurrentThread(base::TimerSlack timer_slack) {
|
||||
void ThreadDelegate::BindToCurrentThread() {
|
||||
thread_local_delegate = this;
|
||||
sequence_manager_->BindToMessagePump(
|
||||
base::MessagePump::Create(message_pump_type_));
|
||||
sequence_manager_->SetTimerSlack(timer_slack);
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
|
@ -37,7 +37,7 @@ class COMPONENT_EXPORT(NETWORK_CPP) ThreadDelegate
|
||||
static scoped_refptr<base::SequencedTaskRunner> GetHighPriorityTaskRunner();
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> GetDefaultTaskRunner() override;
|
||||
void BindToCurrentThread(base::TimerSlack timer_slack) override;
|
||||
void BindToCurrentThread() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<base::sequence_manager::SequenceManager> sequence_manager_;
|
||||
|
@ -1028,9 +1028,7 @@ class ProxyResolverV8TracingFactoryImpl::CreateJob
|
||||
callback_(std::move(callback)),
|
||||
num_outstanding_callbacks_(0) {
|
||||
// Start up the thread.
|
||||
base::Thread::Options options;
|
||||
options.timer_slack = base::TIMER_SLACK_MAXIMUM;
|
||||
CHECK(thread_->StartWithOptions(std::move(options)));
|
||||
CHECK(thread_->Start());
|
||||
job_params_ = std::make_unique<Job::Params>(thread_->task_runner(),
|
||||
&num_outstanding_callbacks_);
|
||||
create_resolver_job_ = new Job(job_params_.get(), std::move(bindings));
|
||||
|
@ -162,14 +162,6 @@ base::TimeTicks SchedulerHelper::NowTicks() const {
|
||||
return base::TimeTicks::Now();
|
||||
}
|
||||
|
||||
void SchedulerHelper::SetTimerSlack(base::TimerSlack timer_slack) {
|
||||
if (sequence_manager_) {
|
||||
static_cast<base::sequence_manager::internal::SequenceManagerImpl*>(
|
||||
sequence_manager_)
|
||||
->SetTimerSlack(timer_slack);
|
||||
}
|
||||
}
|
||||
|
||||
bool SchedulerHelper::HasCPUTimingForEachTask() const {
|
||||
if (sequence_manager_) {
|
||||
return sequence_manager_->GetMetricRecordingSettings()
|
||||
|
@ -50,7 +50,6 @@ class PLATFORM_EXPORT SchedulerHelper
|
||||
|
||||
const base::TickClock* GetClock() const;
|
||||
base::TimeTicks NowTicks() const;
|
||||
void SetTimerSlack(base::TimerSlack timer_slack);
|
||||
|
||||
// Returns the task runner for the default task queue.
|
||||
const scoped_refptr<base::SingleThreadTaskRunner>& DefaultTaskRunner() {
|
||||
|
@ -1025,12 +1025,6 @@ void MainThreadSchedulerImpl::SetRendererHidden(bool hidden) {
|
||||
void MainThreadSchedulerImpl::SetRendererBackgrounded(bool backgrounded) {
|
||||
helper_.CheckOnValidThread();
|
||||
|
||||
// Increasing timer slack helps the OS to coalesce timers efficiently.
|
||||
base::TimerSlack timer_slack = base::TIMER_SLACK_NONE;
|
||||
if (backgrounded)
|
||||
timer_slack = base::TIMER_SLACK_MAXIMUM;
|
||||
helper_.SetTimerSlack(timer_slack);
|
||||
|
||||
if (helper_.IsShutdown() ||
|
||||
main_thread_only().renderer_backgrounded.get() == backgrounded)
|
||||
return;
|
||||
|
Reference in New Issue
Block a user