Commit 39d6363c authored by Daniel Cheng's avatar Daniel Cheng Committed by Chromium LUCI CQ

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

This reverts commit 153b3d46.

Reason for revert: https://crbug.com/1158103

Original change's description:
> [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: Kentaro Hara <haraken@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#835655}

TBR=fdoray@chromium.org,haraken@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com
Bug: 1158103

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Ia4ad30cf20d2ccd406cfff6a75317183a889a0f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587801Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836424}
parent 76431c22
......@@ -55,13 +55,32 @@ class CategorizedWorkerPoolThread : public base::SimpleThread {
categories_(categories),
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:
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_); }
private:
CategorizedWorkerPool* const pool_;
const std::vector<cc::TaskCategory> categories_;
base::ConditionVariable* const has_ready_to_run_tasks_cv_;
base::OnceCallback<void(base::PlatformThreadId)> backgrounding_callback_;
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
};
} // namespace
......@@ -161,9 +180,7 @@ CategorizedWorkerPool::CategorizedWorkerPool()
has_task_for_background_priority_thread_cv_.declare_only_used_while_idle();
}
void CategorizedWorkerPool::Start(
int num_normal_threads,
base::PlatformThreadHandle* background_worker_handle) {
void CategorizedWorkerPool::Start(int num_normal_threads) {
DCHECK(threads_.empty());
// |num_normal_threads| normal threads and 1 background threads are created.
......@@ -199,9 +216,11 @@ void CategorizedWorkerPool::Start(
"CompositorTileWorkerBackground", thread_options, this,
background_thread_prio_categories,
&has_task_for_background_priority_thread_cv_);
if (backgrounding_callback_) {
thread->SetBackgroundingCallback(std::move(background_task_runner_),
std::move(backgrounding_callback_));
}
thread->StartAsync();
if (background_worker_handle)
*background_worker_handle = thread->handle();
threads_.push_back(std::move(thread));
DCHECK_EQ(num_threads, threads_.size());
......@@ -299,6 +318,15 @@ CategorizedWorkerPool::CreateSequencedTaskRunner() {
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() {}
cc::NamespaceToken CategorizedWorkerPool::GenerateNamespaceToken() {
......
......@@ -13,13 +13,16 @@
#include "base/synchronization/condition_variable.h"
#include "base/task_runner.h"
#include "base/thread_annotations.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
#include "cc/raster/task_category.h"
#include "cc/raster/task_graph_runner.h"
#include "cc/raster/task_graph_work_queue.h"
#include "content/common/content_export.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace content {
// A pool of threads used to run categorized work. The work can be scheduled on
......@@ -55,11 +58,8 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
void FlushForTesting();
// Spawn |num_threads| normal threads and 1 background thread and start
// running work on the worker threads. A PlatformThreadHandle to the
// 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);
// running work on the worker threads.
void Start(int num_normal_threads);
// Finish running all the posted tasks (and nested task posted by those tasks)
// of all the associated task runners.
......@@ -72,6 +72,12 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
// Create a new sequenced task graph runner.
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:
~CategorizedWorkerPool() override;
......@@ -150,6 +156,9 @@ class CONTENT_EXPORT CategorizedWorkerPool : public base::TaskRunner,
base::ConditionVariable has_namespaces_with_finished_running_tasks_cv_;
// Set during shutdown. Tells Run() to return when no more tasks are pending.
bool shutdown_ GUARDED_BY(lock_);
base::OnceCallback<void(base::PlatformThreadId)> backgrounding_callback_;
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner_;
};
} // namespace content
......
......@@ -36,7 +36,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
#include "base/threading/thread_local.h"
#include "base/threading/thread_restrictions.h"
......@@ -710,16 +709,20 @@ void RenderThreadImpl::Init() {
DCHECK(parsed_num_raster_threads) << string_value;
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)
int32_t ns_tid = background_worker_handle.platform_handle();
render_message_filter()->SetThreadPriority(
ns_tid, base::ThreadPriority::BACKGROUND);
categorized_worker_pool_->SetBackgroundingCallback(
main_thread_scheduler_->DefaultTaskRunner(),
base::BindOnce(
[](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
}
categorized_worker_pool_->Start(num_raster_threads);
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