Commit 153b3d46 authored by Francois Doray's avatar Francois Doray Committed by Chromium LUCI CQ

[cc] Simplify lowering the priority of the background worker.

Previously, the priority of the background worker was set via an
asynchronous callback. With SimpleThread::handle() which was added
in https://crrev.com/c/2578172, this can be simplified.

Change-Id: Ia50abab5647ef13412488e40f1589ec9d263dc86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2578677
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835655}
parent 9ae34772
...@@ -55,32 +55,13 @@ class CategorizedWorkerPoolThread : public base::SimpleThread { ...@@ -55,32 +55,13 @@ class CategorizedWorkerPoolThread : public base::SimpleThread {
categories_(categories), categories_(categories),
has_ready_to_run_tasks_cv_(has_ready_to_run_tasks_cv) {} has_ready_to_run_tasks_cv_(has_ready_to_run_tasks_cv) {}
void SetBackgroundingCallback(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceCallback<void(base::PlatformThreadId)> callback) {
DCHECK(!HasStartBeenAttempted());
background_task_runner_ = std::move(task_runner);
backgrounding_callback_ = std::move(callback);
}
// base::SimpleThread: // base::SimpleThread:
void BeforeRun() override {
if (backgrounding_callback_) {
DCHECK(background_task_runner_);
background_task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(backgrounding_callback_), tid()));
}
}
void Run() override { pool_->Run(categories_, has_ready_to_run_tasks_cv_); } void Run() override { pool_->Run(categories_, has_ready_to_run_tasks_cv_); }
private: private:
CategorizedWorkerPool* const pool_; CategorizedWorkerPool* const pool_;
const std::vector<cc::TaskCategory> categories_; const std::vector<cc::TaskCategory> categories_;
base::ConditionVariable* const has_ready_to_run_tasks_cv_; base::ConditionVariable* const has_ready_to_run_tasks_cv_;
base::OnceCallback<void(base::PlatformThreadId)> backgrounding_callback_;
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
}; };
} // namespace } // namespace
...@@ -180,7 +161,9 @@ CategorizedWorkerPool::CategorizedWorkerPool() ...@@ -180,7 +161,9 @@ CategorizedWorkerPool::CategorizedWorkerPool()
has_task_for_background_priority_thread_cv_.declare_only_used_while_idle(); has_task_for_background_priority_thread_cv_.declare_only_used_while_idle();
} }
void CategorizedWorkerPool::Start(int num_normal_threads) { void CategorizedWorkerPool::Start(
int num_normal_threads,
base::PlatformThreadHandle* background_worker_handle) {
DCHECK(threads_.empty()); DCHECK(threads_.empty());
// |num_normal_threads| normal threads and 1 background threads are created. // |num_normal_threads| normal threads and 1 background threads are created.
...@@ -216,11 +199,9 @@ void CategorizedWorkerPool::Start(int num_normal_threads) { ...@@ -216,11 +199,9 @@ void CategorizedWorkerPool::Start(int num_normal_threads) {
"CompositorTileWorkerBackground", thread_options, this, "CompositorTileWorkerBackground", thread_options, this,
background_thread_prio_categories, background_thread_prio_categories,
&has_task_for_background_priority_thread_cv_); &has_task_for_background_priority_thread_cv_);
if (backgrounding_callback_) {
thread->SetBackgroundingCallback(std::move(background_task_runner_),
std::move(backgrounding_callback_));
}
thread->StartAsync(); thread->StartAsync();
if (background_worker_handle)
*background_worker_handle = thread->handle();
threads_.push_back(std::move(thread)); threads_.push_back(std::move(thread));
DCHECK_EQ(num_threads, threads_.size()); DCHECK_EQ(num_threads, threads_.size());
...@@ -318,15 +299,6 @@ CategorizedWorkerPool::CreateSequencedTaskRunner() { ...@@ -318,15 +299,6 @@ CategorizedWorkerPool::CreateSequencedTaskRunner() {
return new CategorizedWorkerPoolSequencedTaskRunner(this); return new CategorizedWorkerPoolSequencedTaskRunner(this);
} }
void CategorizedWorkerPool::SetBackgroundingCallback(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceCallback<void(base::PlatformThreadId)> callback) {
// The callback must be set before the threads have been created.
DCHECK(threads_.empty());
backgrounding_callback_ = std::move(callback);
background_task_runner_ = std::move(task_runner);
}
CategorizedWorkerPool::~CategorizedWorkerPool() {} CategorizedWorkerPool::~CategorizedWorkerPool() {}
cc::NamespaceToken CategorizedWorkerPool::GenerateNamespaceToken() { cc::NamespaceToken CategorizedWorkerPool::GenerateNamespaceToken() {
......
...@@ -13,16 +13,13 @@ ...@@ -13,16 +13,13 @@
#include "base/synchronization/condition_variable.h" #include "base/synchronization/condition_variable.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/thread_annotations.h" #include "base/thread_annotations.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h" #include "base/threading/simple_thread.h"
#include "cc/raster/task_category.h" #include "cc/raster/task_category.h"
#include "cc/raster/task_graph_runner.h" #include "cc/raster/task_graph_runner.h"
#include "cc/raster/task_graph_work_queue.h" #include "cc/raster/task_graph_work_queue.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace content { namespace content {
// A pool of threads used to run categorized work. The work can be scheduled on // A pool of threads used to run categorized work. The work can be scheduled on
...@@ -58,8 +55,11 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner, ...@@ -58,8 +55,11 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
void FlushForTesting(); void FlushForTesting();
// Spawn |num_threads| normal threads and 1 background thread and start // Spawn |num_threads| normal threads and 1 background thread and start
// running work on the worker threads. // running work on the worker threads. A PlatformThreadHandle to the
void Start(int num_normal_threads); // background worker is returned via |background_worker_handle| if not
// nullptr. The handle remains valid until shutdown.
void Start(int num_normal_threads,
base::PlatformThreadHandle* background_worker_handle = nullptr);
// Finish running all the posted tasks (and nested task posted by those tasks) // Finish running all the posted tasks (and nested task posted by those tasks)
// of all the associated task runners. // of all the associated task runners.
...@@ -72,12 +72,6 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner, ...@@ -72,12 +72,6 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
// Create a new sequenced task graph runner. // Create a new sequenced task graph runner.
scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner(); scoped_refptr<base::SequencedTaskRunner> CreateSequencedTaskRunner();
// Runs the callback on the specified task-runner once the background worker
// thread is initialized.
void SetBackgroundingCallback(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceCallback<void(base::PlatformThreadId)> callback);
protected: protected:
~CategorizedWorkerPool() override; ~CategorizedWorkerPool() override;
...@@ -156,9 +150,6 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner, ...@@ -156,9 +150,6 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_; base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_;
// Set during shutdown. Tells Run() to return when no more tasks are pending. // Set during shutdown. Tells Run() to return when no more tasks are pending.
bool shutdown_ GUARDED_BY(lock_); bool shutdown_ GUARDED_BY(lock_);
base::OnceCallback<void(base::PlatformThreadId)> backgrounding_callback_;
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
}; };
} // namespace content } // namespace content
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h" #include "base/threading/simple_thread.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
...@@ -709,20 +710,16 @@ void RenderThreadImpl::Init() { ...@@ -709,20 +710,16 @@ void RenderThreadImpl::Init() {
DCHECK(parsed_num_raster_threads) << string_value; DCHECK(parsed_num_raster_threads) << string_value;
DCHECK_GT(num_raster_threads, 0); DCHECK_GT(num_raster_threads, 0);
{
base::PlatformThreadHandle background_worker_handle;
categorized_worker_pool_->Start(num_raster_threads,
&background_worker_handle);
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
categorized_worker_pool_->SetBackgroundingCallback( int32_t ns_tid = background_worker_handle.platform_handle();
main_thread_scheduler_->DefaultTaskRunner(), render_message_filter()->SetThreadPriority(
base::BindOnce( ns_tid, base::ThreadPriority::BACKGROUND);
[](base::WeakPtr<RenderThreadImpl> render_thread,
base::PlatformThreadId thread_id) {
if (!render_thread)
return;
render_thread->render_message_filter()->SetThreadPriority(
thread_id, base::ThreadPriority::BACKGROUND);
},
weak_factory_.GetWeakPtr()));
#endif #endif
categorized_worker_pool_->Start(num_raster_threads); }
discardable_memory_allocator_ = CreateDiscardableMemoryAllocator(); discardable_memory_allocator_ = CreateDiscardableMemoryAllocator();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment