Commit cf41e292 authored by Maggie Chen's avatar Maggie Chen Committed by Commit Bot

Fix data race at GPU watchdog in_gpu_initialization_

in_gpu_initialization_ was set by the GPU main thread and read by the
watchdog thread. This caused data race. This CL fixes it by setting
the flag in the watchdog thread only after the init in the constructor.

Bug:1029475, 1028946

Change-Id: I5c38a2af70962e0d68880e930b6657f7107d2def
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943545Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Commit-Queue: Maggie Chen <magchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720748}
parent 6184f57c
......@@ -115,7 +115,11 @@ void GpuWatchdogThreadImplV2::OnForegrounded() {
// Called from the gpu thread when gpu init has completed.
void GpuWatchdogThreadImplV2::OnInitComplete() {
DCHECK(watched_gpu_task_runner_->BelongsToCurrentThread());
in_gpu_initialization_ = false;
task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&GpuWatchdogThreadImplV2::UpdateInitializationFlag,
base::Unretained(this)));
Disarm();
}
......@@ -315,6 +319,10 @@ void GpuWatchdogThreadImplV2::StopWatchdogTimeoutTask(
weak_factory_.InvalidateWeakPtrs();
}
void GpuWatchdogThreadImplV2::UpdateInitializationFlag() {
in_gpu_initialization_ = false;
}
// Called from the gpu main thread.
// The watchdog is armed only in these three functions -
// GpuWatchdogThreadImplV2(), WillProcessTask(), and OnGpuProcessTearDown()
......
......@@ -94,6 +94,7 @@ class GPU_IPC_SERVICE_EXPORT GpuWatchdogThreadImplV2
void OnAddPowerObserver();
void RestartWatchdogTimeoutTask(PauseResumeSource source_of_request);
void StopWatchdogTimeoutTask(PauseResumeSource source_of_request);
void UpdateInitializationFlag();
void Arm();
void Disarm();
void InProgress();
......@@ -195,8 +196,11 @@ class GPU_IPC_SERVICE_EXPORT GpuWatchdogThreadImplV2
// whether GpuWatchdogThreadEvent::kGpuWatchdogStart has been recorded.
bool is_watchdog_start_histogram_recorded = false;
// For the experiment and the debugging purpose
// Read/Write by the watchdog thread only after initialized in the
// constructor.
bool in_gpu_initialization_ = false;
// For the experiment and the debugging purpose
size_t num_of_timeout_after_power_resume_ = 0;
size_t num_of_timeout_after_foregrounded_ = 0;
bool foregrounded_event_ = false;
......
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