Commit 83d289b8 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

Reland [wasm] Reduce job priority once baseline compilation finishes

ReduceCompilationPriority takes a lock now.

Original message:
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
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel_ng
Change-Id: I6e1bcc809148198a4b4f88bfd4f2e62b1b061439
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2563675
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71546}
parent b6643320
......@@ -595,9 +595,11 @@ class CompilationStateImpl {
void WaitForCompilationEvent(CompilationEvent event);
void SetHighPriority() {
void ReduceCompilationPriority() {
base::MutexGuard guard(&mutex_);
has_priority_ = true;
if (current_compile_job_ && current_compile_job_->UpdatePriorityEnabled()) {
current_compile_job_->UpdatePriority(TaskPriority::kUserVisible);
}
}
bool failed() const {
......@@ -675,8 +677,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 +799,6 @@ void CompilationState::WaitForTopTierFinished() {
top_tier_finished_semaphore->Wait();
}
void CompilationState::SetHighPriority() { Impl(this)->SetHighPriority(); }
void CompilationState::InitializeAfterDeserialization() {
Impl(this)->InitializeCompilationProgressAfterDeserialization();
}
......@@ -1638,8 +1636,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());
......@@ -2721,7 +2717,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.
......@@ -3245,13 +3247,8 @@ void CompilationStateImpl::ScheduleCompileJobForNewUnits() {
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) {
......@@ -3374,7 +3371,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