Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Merge 115] Add a high priority queue for sync cookie calls in the ne…
…twork service This change adds a minimal scheduler for the network service thread which has a default task queue and high priority task queue. The RestrictedCookieManager interface will be bound using the high priority task queue, which should make the sync cookie accesses/writes from the renderer faster if there are other tasks that need to be run in the network service. The hope is that re-ordering these tasks with other network tasks will not be a problem since they are generally called as sync calls from the renderer. If there turns out to be problems with this later we can revisit how tasks are prioritized. (cherry picked from commit a922565) Bug: 1448685 Change-Id: I42f7f4e895a0b7d8708c49db707aab6286ef18bf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4561626 Commit-Queue: Clark DuVall <cduvall@chromium.org> Reviewed-by: Scott Haseley <shaseley@chromium.org> Reviewed-by: John Abd-El-Malek <jam@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1149519} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573725 Commit-Queue: John Abd-El-Malek <jam@chromium.org> Auto-Submit: Clark DuVall <cduvall@chromium.org> Cr-Commit-Position: refs/branch-heads/5790@{#133} Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
- Loading branch information
1 parent
803348b
commit b8bf3ae
Showing
10 changed files
with
178 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "services/network/public/cpp/thread_delegate.h" | ||
|
||
#include "base/task/sequence_manager/sequence_manager.h" | ||
#include "third_party/abseil-cpp/absl/base/attributes.h" | ||
|
||
namespace network { | ||
namespace { | ||
|
||
using ProtoPriority = perfetto::protos::pbzero::SequenceManagerTask::Priority; | ||
|
||
ABSL_CONST_INIT thread_local ThreadDelegate* thread_local_delegate = nullptr; | ||
|
||
ProtoPriority TaskPriorityToProto( | ||
base::sequence_manager::TaskQueue::QueuePriority priority) { | ||
DCHECK_LT(static_cast<size_t>(priority), | ||
static_cast<size_t>(TaskPriority::kNumPriorities)); | ||
switch (static_cast<TaskPriority>(priority)) { | ||
case TaskPriority::kHighPriority: | ||
return ProtoPriority::HIGH_PRIORITY; | ||
case TaskPriority::kNormalPriority: | ||
return ProtoPriority::NORMAL_PRIORITY; | ||
case TaskPriority::kNumPriorities: | ||
return ProtoPriority::UNKNOWN; | ||
} | ||
} | ||
|
||
base::sequence_manager::SequenceManager::PrioritySettings | ||
GetPrioritySettings() { | ||
base::sequence_manager::SequenceManager::PrioritySettings settings( | ||
TaskPriority::kNumPriorities, TaskPriority::kNormalPriority); | ||
settings.SetProtoPriorityConverter(&TaskPriorityToProto); | ||
return settings; | ||
} | ||
|
||
} // namespace | ||
|
||
// static | ||
scoped_refptr<base::SequencedTaskRunner> | ||
ThreadDelegate::GetHighPriorityTaskRunner() { | ||
if (thread_local_delegate) { | ||
return thread_local_delegate->high_priority_task_queue_->task_runner(); | ||
} | ||
return base::SequencedTaskRunner::GetCurrentDefault(); | ||
} | ||
|
||
ThreadDelegate::ThreadDelegate(base::MessagePumpType message_pump_type) | ||
: sequence_manager_(base::sequence_manager::CreateUnboundSequenceManager( | ||
base::sequence_manager::SequenceManager::Settings::Builder() | ||
.SetMessagePumpType(message_pump_type) | ||
.SetPrioritySettings(GetPrioritySettings()) | ||
.Build())), | ||
default_task_queue_(sequence_manager_->CreateTaskQueue( | ||
base::sequence_manager::TaskQueue::Spec( | ||
base::sequence_manager::QueueName::DEFAULT_TQ))), | ||
high_priority_task_queue_(sequence_manager_->CreateTaskQueue( | ||
base::sequence_manager::TaskQueue::Spec( | ||
base::sequence_manager::QueueName::OTHER_TQ))), | ||
message_pump_type_(message_pump_type) { | ||
default_task_queue_->SetQueuePriority(TaskPriority::kNormalPriority); | ||
high_priority_task_queue_->SetQueuePriority(TaskPriority::kHighPriority); | ||
sequence_manager_->SetDefaultTaskRunner(default_task_queue_->task_runner()); | ||
} | ||
|
||
ThreadDelegate::~ThreadDelegate() { | ||
thread_local_delegate = nullptr; | ||
} | ||
|
||
scoped_refptr<base::SingleThreadTaskRunner> | ||
ThreadDelegate::GetDefaultTaskRunner() { | ||
return default_task_queue_->task_runner(); | ||
} | ||
|
||
void ThreadDelegate::BindToCurrentThread(base::TimerSlack timer_slack) { | ||
thread_local_delegate = this; | ||
sequence_manager_->BindToMessagePump( | ||
base::MessagePump::Create(message_pump_type_)); | ||
sequence_manager_->SetTimerSlack(timer_slack); | ||
} | ||
|
||
} // namespace network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SERVICES_NETWORK_PUBLIC_CPP_THREAD_DELEGATE_H_ | ||
#define SERVICES_NETWORK_PUBLIC_CPP_THREAD_DELEGATE_H_ | ||
|
||
#include "base/component_export.h" | ||
#include "base/message_loop/message_pump.h" | ||
#include "base/task/sequence_manager/task_queue.h" | ||
#include "base/threading/thread.h" | ||
|
||
namespace base { | ||
namespace sequence_manager { | ||
class TaskQueue; | ||
class SequenceManager; | ||
} // namespace sequence_manager | ||
} // namespace base | ||
|
||
namespace network { | ||
|
||
enum class TaskPriority : base::sequence_manager::TaskQueue::QueuePriority { | ||
kHighPriority = 0, | ||
kNormalPriority = 1, | ||
|
||
kNumPriorities = 2, | ||
}; | ||
|
||
// A thread delegate which allows running high priority tasks. | ||
class COMPONENT_EXPORT(NETWORK_CPP) ThreadDelegate | ||
: public base::Thread::Delegate { | ||
public: | ||
explicit ThreadDelegate(base::MessagePumpType message_pump_type); | ||
~ThreadDelegate() override; | ||
|
||
// Gets the high priority task runner for this thread, or the default task | ||
// runner if a high priority task runner doesn't exist. | ||
static scoped_refptr<base::SequencedTaskRunner> GetHighPriorityTaskRunner(); | ||
|
||
scoped_refptr<base::SingleThreadTaskRunner> GetDefaultTaskRunner() override; | ||
void BindToCurrentThread(base::TimerSlack timer_slack) override; | ||
|
||
private: | ||
std::unique_ptr<base::sequence_manager::SequenceManager> sequence_manager_; | ||
scoped_refptr<base::sequence_manager::TaskQueue> default_task_queue_; | ||
scoped_refptr<base::sequence_manager::TaskQueue> high_priority_task_queue_; | ||
base::MessagePumpType message_pump_type_; | ||
}; | ||
|
||
} // namespace network | ||
|
||
#endif // SERVICES_NETWORK_PUBLIC_CPP_THREAD_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters