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 {
void WaitForCompilationEvent(CompilationEvent event);
void SetHighPriority() {
base::MutexGuard guard(&mutex_);
has_priority_ = true;
void ReduceCompilationPriority() {
if (current_compile_job_ && current_compile_job_->UpdatePriorityEnabled()) {
current_compile_job_->UpdatePriority(TaskPriority::kUserVisible);
}
}
bool failed() const {
......@@ -675,8 +676,6 @@ class CompilationStateImpl {
//////////////////////////////////////////////////////////////////////////////
// Protected by {mutex_}:
bool has_priority_ = false;
std::shared_ptr<JobHandle> current_compile_job_;
// Features detected to be used in this module. Features can be detected
......@@ -799,8 +798,6 @@ void CompilationState::WaitForTopTierFinished() {
top_tier_finished_semaphore->Wait();
}
void CompilationState::SetHighPriority() { Impl(this)->SetHighPriority(); }
void CompilationState::InitializeAfterDeserialization() {
Impl(this)->InitializeCompilationProgressAfterDeserialization();
}
......@@ -1638,8 +1635,6 @@ std::shared_ptr<NativeModule> CompileToNativeModule(
native_module = isolate->wasm_engine()->NewNativeModule(
isolate, enabled, module, code_size_estimate);
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 =
isolate->GetOrRegisterRecorderContextId(isolate->native_context());
......@@ -2719,7 +2714,13 @@ CompilationStateImpl::CompilationStateImpl(
? CompileMode::kTiering
: CompileMode::kRegular),
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() {
// No more callbacks after abort.
......@@ -3241,15 +3242,9 @@ void CompilationStateImpl::ScheduleCompileJobForNewUnits() {
std::unique_ptr<JobTask> new_compile_job =
std::make_unique<BackgroundCompileJob>(native_module_weak_,
async_counters_);
// TODO(wasm): Lower priority for TurboFan-only jobs.
new_job_handle = V8::GetCurrentPlatform()->PostJob(
has_priority_ ? TaskPriority::kUserBlocking
: TaskPriority::kUserVisible,
std::move(new_compile_job));
TaskPriority::kUserBlocking, std::move(new_compile_job));
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) {
......@@ -3372,7 +3367,7 @@ void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
auto job = std::make_unique<CompileJSToWasmWrapperJob>(
&queue, &compilation_units, max_concurrency);
auto job_handle = V8::GetCurrentPlatform()->PostJob(
TaskPriority::kUserVisible, std::move(job));
TaskPriority::kUserBlocking, std::move(job));
// Wait for completion, while contributing to the work.
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