Commit 2f859102 authored by Maggie Chen's avatar Maggie Chen Committed by Commit Bot

Fix a GPU watchdog V2 DCHECK in GPU initialization

A DCHECK is triggered in GpuWatchdogThreadImplV2::Arm() during GPU
initialization. Whenever there is an error, GpuInit::InitializeAndStartSandbox()
exits earlier. watchdog_thread_->OnInitComplete() is not called in those cases
and arm_disarm_counter_ gets messed up.
A new class GpuWatchdogInit is created to call OnInitcomplete() in the destructor.
OnInitComplete() will never be missed at the end of InitializeAndStartSandbox().

Bug:949839, 995372

Change-Id: I1a107df0ca48409ff2252260ea41de643fa39b6c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762879Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Commit-Queue: Maggie Chen <magchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689343}
parent ee3f1767
...@@ -122,6 +122,20 @@ bool CanAccessNvidiaDeviceFile() { ...@@ -122,6 +122,20 @@ bool CanAccessNvidiaDeviceFile() {
} }
#endif // OS_LINUX && !OS_CHROMEOS && !IS_CHROMECAST #endif // OS_LINUX && !OS_CHROMEOS && !IS_CHROMECAST
class GpuWatchdogInit {
public:
GpuWatchdogInit() = default;
~GpuWatchdogInit() {
if (watchdog_ptr_)
watchdog_ptr_->OnInitComplete();
}
void SetGpuWatchdogPtr(gpu::GpuWatchdogThread* ptr) { watchdog_ptr_ = ptr; }
private:
gpu::GpuWatchdogThread* watchdog_ptr_ = nullptr;
};
} // namespace } // namespace
GpuInit::GpuInit() = default; GpuInit::GpuInit() = default;
...@@ -191,6 +205,10 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -191,6 +205,10 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
enable_watchdog = false; enable_watchdog = false;
#endif #endif
// watchdog_init will call watchdog OnInitComplete() at the end of this
// function.
GpuWatchdogInit watchdog_init;
bool delayed_watchdog_enable = false; bool delayed_watchdog_enable = false;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -205,6 +223,7 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -205,6 +223,7 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
if (base::FeatureList::IsEnabled(features::kGpuWatchdogV2)) { if (base::FeatureList::IsEnabled(features::kGpuWatchdogV2)) {
watchdog_thread_ = gpu::GpuWatchdogThreadImplV2::Create( watchdog_thread_ = gpu::GpuWatchdogThreadImplV2::Create(
gpu_preferences_.watchdog_starts_backgrounded); gpu_preferences_.watchdog_starts_backgrounded);
watchdog_init.SetGpuWatchdogPtr(watchdog_thread_.get());
} else { } else {
watchdog_thread_ = gpu::GpuWatchdogThreadImplV1::Create( watchdog_thread_ = gpu::GpuWatchdogThreadImplV1::Create(
gpu_preferences_.watchdog_starts_backgrounded); gpu_preferences_.watchdog_starts_backgrounded);
...@@ -415,6 +434,7 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -415,6 +434,7 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
if (base::FeatureList::IsEnabled(features::kGpuWatchdogV2)) { if (base::FeatureList::IsEnabled(features::kGpuWatchdogV2)) {
watchdog_thread_ = gpu::GpuWatchdogThreadImplV2::Create( watchdog_thread_ = gpu::GpuWatchdogThreadImplV2::Create(
gpu_preferences_.watchdog_starts_backgrounded); gpu_preferences_.watchdog_starts_backgrounded);
watchdog_init.SetGpuWatchdogPtr(watchdog_thread_.get());
} else { } else {
watchdog_thread_ = gpu::GpuWatchdogThreadImplV1::Create( watchdog_thread_ = gpu::GpuWatchdogThreadImplV1::Create(
gpu_preferences_.watchdog_starts_backgrounded); gpu_preferences_.watchdog_starts_backgrounded);
...@@ -430,11 +450,6 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -430,11 +450,6 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
UMA_HISTOGRAM_BOOLEAN("GPU.Sandbox.InitializedSuccessfully", UMA_HISTOGRAM_BOOLEAN("GPU.Sandbox.InitializedSuccessfully",
gpu_info_.sandboxed); gpu_info_.sandboxed);
// Notify the gpu watchdog that the gpu init has completed So the watchdog
// can be disarmed.
if (watchdog_thread_)
watchdog_thread_->OnInitComplete();
init_successful_ = true; init_successful_ = true;
#if defined(USE_OZONE) #if defined(USE_OZONE)
ui::OzonePlatform::GetInstance()->AfterSandboxEntry(); ui::OzonePlatform::GetInstance()->AfterSandboxEntry();
......
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