Commit 4cb4a229 authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

cppgc, jobs: Update job priority

This CL aligns the library implementation with the blink implementation:
(*) Concurrent marking increases job priority if no concurrent progress
    is made in the last 50% of the expected marking duration.
(*) Concurrent sweeping increases job priority when calling
    FinishIfRunning (the library equivalent of blink's CompleteSweep).

Bug: chromium:1056170
Change-Id: Ice275cb90a7dd76bf4125f4338d9d80e5f576c58
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2431572
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70375}
parent 4a601911
......@@ -234,6 +234,16 @@ class JobHandle {
* Returns false after Join() or Cancel() was called.
*/
virtual bool IsRunning() = 0;
/**
* Returns true if job priority can be changed.
*/
virtual bool UpdatePriorityEnabled() const { return false; }
/**
* Update this Job's priority.
*/
virtual void UpdatePriority(TaskPriority new_priority) {}
};
/**
......
......@@ -189,6 +189,7 @@ bool ConcurrentMarkerBase::NotifyIncrementalMutatorStepCompleted() {
}
void ConcurrentMarkerBase::IncreaseMarkingPriorityIfNeeded() {
if (!concurrent_marking_handle_->UpdatePriorityEnabled()) return;
if (concurrent_marking_priority_increased_) return;
// If concurrent tasks aren't executed, it might delay GC finalization.
// As long as GC is active so is the write barrier, which incurs a
......@@ -196,7 +197,7 @@ void ConcurrentMarkerBase::IncreaseMarkingPriorityIfNeeded() {
// |MarkingSchedulingOracle::kEstimatedMarkingTimeMs|. If
// concurrent marking tasks have not reported any progress (i.e. the
// concurrently marked bytes count as not changed) in over
// |kMarkingScheduleRatioBeforeConcurrentPriorityIncrease| (50%) of
// |kMarkingScheduleRatioBeforeConcurrentPriorityIncrease| of
// that expected duration, we increase the concurrent task priority
// for the duration of the current GC. This is meant to prevent the
// GC from exceeding it's expected end time.
......@@ -210,9 +211,8 @@ void ConcurrentMarkerBase::IncreaseMarkingPriorityIfNeeded() {
.InMilliseconds() >
kMarkingScheduleRatioBeforeConcurrentPriorityIncrease *
IncrementalMarkingSchedule::kEstimatedMarkingTimeMs) {
// TODO(chromium:1056170): Enable priority update after it is added to the
// platform.
// concurrent_marking_handle_.UpdatePriority(v8::TaskPriority::USER_BLOCKING);
concurrent_marking_handle_->UpdatePriority(
cppgc::TaskPriority::kUserBlocking);
concurrent_marking_priority_increased_ = true;
}
}
......
......@@ -179,6 +179,10 @@ class DefaultJobImpl<Thread>::JobHandle final : public cppgc::JobHandle {
bool IsCompleted() override { return job_->IsCompleted(); }
bool IsRunning() override { return job_->IsRunning(); }
// DefaultJobImpl doesn't support priorities.
bool UpdatePriorityEnabled() const override { return false; }
void UpdatePriority(TaskPriority) override { UNREACHABLE(); }
private:
std::shared_ptr<DefaultJobImpl> job_;
};
......
......@@ -504,6 +504,13 @@ class Sweeper::SweeperImpl final {
void FinishIfRunning() {
if (!is_in_progress_) return;
if (concurrent_sweeper_handle_ &&
concurrent_sweeper_handle_->UpdatePriorityEnabled()) {
DCHECK(concurrent_sweeper_handle_->IsRunning());
concurrent_sweeper_handle_->UpdatePriority(
cppgc::TaskPriority::kUserBlocking);
}
Finish();
}
......
......@@ -209,6 +209,11 @@ void DefaultJobState::CallOnWorkerThread(TaskPriority priority,
}
}
void DefaultJobState::UpdatePriority(TaskPriority priority) {
base::MutexGuard guard(&mutex_);
priority_ = priority;
}
DefaultJobHandle::DefaultJobHandle(std::shared_ptr<DefaultJobState> state)
: state_(std::move(state)) {
state_->NotifyConcurrencyIncrease();
......@@ -232,5 +237,9 @@ void DefaultJobHandle::CancelAndDetach() {
bool DefaultJobHandle::IsCompleted() { return state_->IsCompleted(); }
void DefaultJobHandle::UpdatePriority(TaskPriority priority) {
state_->UpdatePriority(priority);
}
} // namespace platform
} // namespace v8
......@@ -65,6 +65,8 @@ class V8_PLATFORM_EXPORT DefaultJobState
// must contribute again, or false if it should return.
bool DidRunTask();
void UpdatePriority(TaskPriority);
private:
// Called from the joining thread. Waits for the worker count to be below or
// equal to max concurrency (will happen when a worker calls
......@@ -114,6 +116,10 @@ class V8_PLATFORM_EXPORT DefaultJobHandle : public JobHandle {
bool IsCompleted() override;
bool IsRunning() override { return state_ != nullptr; }
bool UpdatePriorityEnabled() const override { return true; }
void UpdatePriority(TaskPriority) override;
private:
std::shared_ptr<DefaultJobState> state_;
......
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