Commit cf9a28b6 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Reduce job priority once baseline compilation finishes

This Cl changes the priority of baseline compilation from kUserVisible
to kUserBlocking. Once baseline compilation finishes, the priority is
reduced to kUserVisible. The reason for using kUserBlocking is that
thereby TurboFan compilation cannot block Liftoff compilation anymore.
Additionally, kUserBlocking is quite appropriate, as the initial
compilation does block a whole section of a web app from execution.

R=clemensb@chromium.org

Bug: v8:11088
Change-Id: Ifde42d20f36d4c0a5122b0008311ccdffbb60e48
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2519559
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71404}
parent c23d93c4
...@@ -595,9 +595,10 @@ class CompilationStateImpl { ...@@ -595,9 +595,10 @@ class CompilationStateImpl {
void WaitForCompilationEvent(CompilationEvent event); void WaitForCompilationEvent(CompilationEvent event);
void SetHighPriority() { void ReduceCompilationPriority() {
base::MutexGuard guard(&mutex_); if (current_compile_job_ && current_compile_job_->UpdatePriorityEnabled()) {
has_priority_ = true; current_compile_job_->UpdatePriority(TaskPriority::kUserVisible);
}
} }
bool failed() const { bool failed() const {
...@@ -675,8 +676,6 @@ class CompilationStateImpl { ...@@ -675,8 +676,6 @@ class CompilationStateImpl {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// Protected by {mutex_}: // Protected by {mutex_}:
bool has_priority_ = false;
std::shared_ptr<JobHandle> current_compile_job_; std::shared_ptr<JobHandle> current_compile_job_;
// Features detected to be used in this module. Features can be detected // Features detected to be used in this module. Features can be detected
...@@ -799,8 +798,6 @@ void CompilationState::WaitForTopTierFinished() { ...@@ -799,8 +798,6 @@ void CompilationState::WaitForTopTierFinished() {
top_tier_finished_semaphore->Wait(); top_tier_finished_semaphore->Wait();
} }
void CompilationState::SetHighPriority() { Impl(this)->SetHighPriority(); }
void CompilationState::InitializeAfterDeserialization() { void CompilationState::InitializeAfterDeserialization() {
Impl(this)->InitializeCompilationProgressAfterDeserialization(); Impl(this)->InitializeCompilationProgressAfterDeserialization();
} }
...@@ -1638,8 +1635,6 @@ std::shared_ptr<NativeModule> CompileToNativeModule( ...@@ -1638,8 +1635,6 @@ std::shared_ptr<NativeModule> CompileToNativeModule(
native_module = isolate->wasm_engine()->NewNativeModule( native_module = isolate->wasm_engine()->NewNativeModule(
isolate, enabled, module, code_size_estimate); isolate, enabled, module, code_size_estimate);
native_module->SetWireBytes(std::move(wire_bytes_copy)); native_module->SetWireBytes(std::move(wire_bytes_copy));
// Sync compilation is user blocking, so we increase the priority.
native_module->compilation_state()->SetHighPriority();
v8::metrics::Recorder::ContextId context_id = v8::metrics::Recorder::ContextId context_id =
isolate->GetOrRegisterRecorderContextId(isolate->native_context()); isolate->GetOrRegisterRecorderContextId(isolate->native_context());
...@@ -2719,7 +2714,13 @@ CompilationStateImpl::CompilationStateImpl( ...@@ -2719,7 +2714,13 @@ CompilationStateImpl::CompilationStateImpl(
? CompileMode::kTiering ? CompileMode::kTiering
: CompileMode::kRegular), : CompileMode::kRegular),
async_counters_(std::move(async_counters)), async_counters_(std::move(async_counters)),
compilation_unit_queues_(native_module->num_functions()) {} compilation_unit_queues_(native_module->num_functions()) {
AddCallback([&](CompilationEvent event) {
if (event == CompilationEvent::kFinishedBaselineCompilation) {
ReduceCompilationPriority();
}
});
}
void CompilationStateImpl::CancelCompilation() { void CompilationStateImpl::CancelCompilation() {
// No more callbacks after abort. // No more callbacks after abort.
...@@ -3241,15 +3242,9 @@ void CompilationStateImpl::ScheduleCompileJobForNewUnits() { ...@@ -3241,15 +3242,9 @@ void CompilationStateImpl::ScheduleCompileJobForNewUnits() {
std::unique_ptr<JobTask> new_compile_job = std::unique_ptr<JobTask> new_compile_job =
std::make_unique<BackgroundCompileJob>(native_module_weak_, std::make_unique<BackgroundCompileJob>(native_module_weak_,
async_counters_); async_counters_);
// TODO(wasm): Lower priority for TurboFan-only jobs.
new_job_handle = V8::GetCurrentPlatform()->PostJob( new_job_handle = V8::GetCurrentPlatform()->PostJob(
has_priority_ ? TaskPriority::kUserBlocking TaskPriority::kUserBlocking, std::move(new_compile_job));
: TaskPriority::kUserVisible,
std::move(new_compile_job));
current_compile_job_ = new_job_handle; current_compile_job_ = new_job_handle;
// Reset the priority. Later uses of the compilation state, e.g. for
// debugging, should compile with the default priority again.
has_priority_ = false;
} }
if (new_job_handle) { if (new_job_handle) {
...@@ -3372,7 +3367,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module, ...@@ -3372,7 +3367,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
auto job = std::make_unique<CompileJSToWasmWrapperJob>( auto job = std::make_unique<CompileJSToWasmWrapperJob>(
&queue, &compilation_units, max_concurrency); &queue, &compilation_units, max_concurrency);
auto job_handle = V8::GetCurrentPlatform()->PostJob( auto job_handle = V8::GetCurrentPlatform()->PostJob(
TaskPriority::kUserVisible, std::move(job)); TaskPriority::kUserBlocking, std::move(job));
// Wait for completion, while contributing to the work. // Wait for completion, while contributing to the work.
job_handle->Join(); job_handle->Join();
......
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