summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-09 01:50:08 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-09 01:50:08 +0000
commite09cee46b136f877390960323c84ef935ce5b7df (patch)
treedd1429752417d269b5b252bb3baea676e427cb05
parent04b7a5a3bcfe08aa22c33e341184dfbbd3c00646 (diff)
downloadchromium_src-e09cee46b136f877390960323c84ef935ce5b7df.zip
chromium_src-e09cee46b136f877390960323c84ef935ce5b7df.tar.gz
chromium_src-e09cee46b136f877390960323c84ef935ce5b7df.tar.bz2
- Relanding 61718.
I disabled the GPU watchdog in three new cases: - If the OSMesa software renderer is in use. This will disable it on bots. - When running on valgrind, whether on a bot or locally. - In debug builds I added a GPU process initialization time to the GPU info. I moved the GPU initialization code outside the watchdog protection because it can take a long time and trigger the watchdog. I increased the timeout. I set up a field trial with different timeouts to see the rate of failure for each period. Original CL description: I added a watchdog thread that intermitently checks the main thread can respond to tasks posted on its message queue. I fixed some bugs that prevented GGL from failing when the GPU channel was lost. Added a command line swith to disable the watchdog thread for debugging purposes. TEST=try, local testing of all features BUG=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65461 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_about_handler.cc38
-rw-r--r--chrome/browser/gpu_process_host.cc11
-rw-r--r--chrome/browser/gpu_process_host.h7
-rw-r--r--chrome/browser/gpu_process_host_ui_shim.cc16
-rw-r--r--chrome/browser/gpu_process_host_ui_shim.h7
-rw-r--r--chrome/chrome.gyp3
-rw-r--r--chrome/common/chrome_switches.cc4
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/common/gpu_info.cc10
-rw-r--r--chrome/common/gpu_info.h8
-rw-r--r--chrome/common/gpu_messages.cc11
-rw-r--r--chrome/common/gpu_messages_unittest.cc5
-rw-r--r--chrome/gpu/gpu_main.cc91
-rw-r--r--chrome/gpu/gpu_thread.cc62
-rw-r--r--chrome/gpu/gpu_thread.h7
-rw-r--r--chrome/gpu/gpu_watchdog_thread.cc110
-rw-r--r--chrome/gpu/gpu_watchdog_thread.h41
-rw-r--r--chrome/renderer/command_buffer_proxy.cc77
-rw-r--r--chrome/renderer/command_buffer_proxy.h12
-rw-r--r--chrome/renderer/ggl/ggl.cc2
-rw-r--r--chrome/renderer/gpu_channel_host.cc17
-rw-r--r--chrome/renderer/gpu_channel_host.h6
-rw-r--r--chrome/renderer/pepper_plugin_delegate_impl.cc2
-rw-r--r--chrome/renderer/render_thread.cc8
-rw-r--r--chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc2
25 files changed, 440 insertions, 118 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 83b4bff..79775e6 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -772,28 +772,38 @@ std::string AboutGpu() {
html.append("</body></html> ");
} else {
html.append("<html><head><title>About GPU</title></head><body>\n");
- html.append("<h2>GPU Information</h2><ul>\n");
- html.append("<li><strong>Vendor ID:</strong> ");
+ html.append("<h2>GPU Information</h2>\n");
+ html.append("<table><tr>");
+ html.append("<td><strong>Initialization time</strong></td><td>");
+ html.append(base::Int64ToString(
+ gpu_info.initialization_time().InMilliseconds()));
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>Vendor ID</strong></td><td>");
html.append(base::StringPrintf("0x%04x", gpu_info.vendor_id()));
- html.append("<li><strong>Device ID:</strong> ");
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>Device ID</strong></td><td>");
html.append(base::StringPrintf("0x%04x", gpu_info.device_id()));
- html.append("<li><strong>Driver Version:</strong> ");
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>Driver Version</strong></td><td>");
html.append(WideToASCII(gpu_info.driver_version()).c_str());
- html.append("<li><strong>Pixel Shader Version:</strong> ");
- html.append(VersionNumberToString(
- gpu_info.pixel_shader_version()).c_str());
- html.append("<li><strong>Vertex Shader Version:</strong> ");
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>Pixel Shader Version</strong></td><td>");
+ html.append(VersionNumberToString(gpu_info.pixel_shader_version()).c_str());
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>Vertex Shader Version</strong></td><td>");
html.append(VersionNumberToString(
- gpu_info.vertex_shader_version()).c_str());
- html.append("<li><strong>GL Version:</strong> ");
+ gpu_info.vertex_shader_version()).c_str());
+ html.append("</td></tr><tr><td>");
+ html.append("<strong>GL Version</strong></td><td>");
html.append(VersionNumberToString(gpu_info.gl_version()).c_str());
+ html.append("</td></tr></table>");
#if defined(OS_WIN)
- html.append("<li><strong>DirectX Diagnostics:</strong> ");
+ html.append("<h2>DirectX Diagnostics</h2>");
DxDiagNodeToHTML(&html, gpu_info.dx_diagnostics());
#endif
- html.append("</ul></body></html> ");
+ html.append("</body></html>");
}
return html;
}
@@ -1138,11 +1148,11 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) {
// Handle URLs to wreck the gpu process.
if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuCrashURL)) {
- GpuProcessHost::SendAboutGpuCrash();
+ GpuProcessHostUIShim::Get()->SendAboutGpuCrash();
return true;
}
if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutGpuHangURL)) {
- GpuProcessHost::SendAboutGpuHang();
+ GpuProcessHostUIShim::Get()->SendAboutGpuHang();
return true;
}
diff --git a/chrome/browser/gpu_process_host.cc b/chrome/browser/gpu_process_host.cc
index 158a65f..171c404 100644
--- a/chrome/browser/gpu_process_host.cc
+++ b/chrome/browser/gpu_process_host.cc
@@ -95,6 +95,7 @@ bool GpuProcessHost::Init() {
static const char* const kSwitchNames[] = {
switches::kUseGL,
switches::kDisableGpuVsync,
+ switches::kDisableGpuWatchdog,
switches::kDisableLogging,
switches::kEnableAcceleratedDecoding,
switches::kEnableLogging,
@@ -127,16 +128,6 @@ GpuProcessHost* GpuProcessHost::Get() {
return sole_instance_;
}
-// static
-void GpuProcessHost::SendAboutGpuCrash() {
- Get()->Send(new GpuMsg_Crash());
-}
-
-// static
-void GpuProcessHost::SendAboutGpuHang() {
- Get()->Send(new GpuMsg_Hang());
-}
-
bool GpuProcessHost::Send(IPC::Message* msg) {
if (!EnsureInitialized())
return false;
diff --git a/chrome/browser/gpu_process_host.h b/chrome/browser/gpu_process_host.h
index de8d3e5..f9aa06f 100644
--- a/chrome/browser/gpu_process_host.h
+++ b/chrome/browser/gpu_process_host.h
@@ -28,13 +28,6 @@ class GpuProcessHost : public BrowserChildProcessHost {
// Getter for the singleton. This will return NULL on failure.
static GpuProcessHost* Get();
- // Tells the GPU process to crash. Useful for testing.
- static void SendAboutGpuCrash();
-
- // Tells the GPU process to let its main thread enter an infinite loop.
- // Useful for testing.
- static void SendAboutGpuHang();
-
// Shutdown routine, which should only be called upon process
// termination.
static void Shutdown();
diff --git a/chrome/browser/gpu_process_host_ui_shim.cc b/chrome/browser/gpu_process_host_ui_shim.cc
index 682eb1a..3d1223d 100644
--- a/chrome/browser/gpu_process_host_ui_shim.cc
+++ b/chrome/browser/gpu_process_host_ui_shim.cc
@@ -67,3 +67,19 @@ void GpuProcessHostUIShim::CollectGraphicsInfoAsynchronously() {
FROM_HERE,
new SendOnIOThreadTask(new GpuMsg_CollectGraphicsInfo()));
}
+
+void GpuProcessHostUIShim::SendAboutGpuCrash() {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ new SendOnIOThreadTask(new GpuMsg_Crash()));
+}
+
+void GpuProcessHostUIShim::SendAboutGpuHang() {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ new SendOnIOThreadTask(new GpuMsg_Hang()));
+}
diff --git a/chrome/browser/gpu_process_host_ui_shim.h b/chrome/browser/gpu_process_host_ui_shim.h
index e2f09ae..f43b41d 100644
--- a/chrome/browser/gpu_process_host_ui_shim.h
+++ b/chrome/browser/gpu_process_host_ui_shim.h
@@ -41,6 +41,13 @@ class GpuProcessHostUIShim : public IPC::Channel::Sender,
// graphics card.
void CollectGraphicsInfoAsynchronously();
+ // Tells the GPU process to crash. Useful for testing.
+ void SendAboutGpuCrash();
+
+ // Tells the GPU process to let its main thread enter an infinite loop.
+ // Useful for testing.
+ void SendAboutGpuHang();
+
private:
friend struct DefaultSingletonTraits<GpuProcessHostUIShim>;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 6900688..7df1243 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -720,6 +720,8 @@
'gpu/gpu_video_decoder.h',
'gpu/gpu_video_service.cc',
'gpu/gpu_video_service.h',
+ 'gpu/gpu_watchdog_thread.cc',
+ 'gpu/gpu_watchdog_thread.h',
'gpu/media/gpu_video_device.h',
'gpu/media/fake_gl_video_decode_engine.cc',
'gpu/media/fake_gl_video_decode_engine.h',
@@ -735,6 +737,7 @@
'<(DEPTH)/third_party/angle/include',
'<(DEPTH)/third_party/angle/src',
'<(DEPTH)/third_party/wtl/include',
+ '$(DXSDK_DIR)/include',
],
'dependencies': [
'../third_party/angle/src/build_angle.gyp:libEGL',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 1a6b7d0..30dd178 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -195,6 +195,10 @@ const char kDisableGeolocation[] = "disable-geolocation";
// Disable the GLSL translator.
const char kDisableGLSLTranslator[] = "disable-glsl-translator";
+// Disable the thread that crashes the GPU process if it stops responding to
+// messages.
+const char kDisableGpuWatchdog[] = "disable-gpu-watchdog";
+
// Suppresses hang monitor dialogs in renderer processes. This may allow slow
// unload handlers on a page to prevent the tab from closing, but the Task
// Manager can be used to terminate the offending process in this case.
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 0e742a0..93558c9 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -67,6 +67,7 @@ extern const char kDisableExtensions[];
extern const char kDisableFileSystem[];
extern const char kDisableGLSLTranslator[];
extern const char kDisableGeolocation[];
+extern const char kDisableGpuWatchdog[];
extern const char kDisableHangMonitor[];
extern const char kDisableHistoryQuickProvider[];
extern const char kDisableHistoryURLProvider[];
diff --git a/chrome/common/gpu_info.cc b/chrome/common/gpu_info.cc
index 667c375..64f0498 100644
--- a/chrome/common/gpu_info.cc
+++ b/chrome/common/gpu_info.cc
@@ -16,6 +16,10 @@ bool GPUInfo::initialized() const {
return initialized_;
}
+base::TimeDelta GPUInfo::initialization_time() const {
+ return initialization_time_;
+}
+
uint32 GPUInfo::vendor_id() const {
return vendor_id_;
}
@@ -45,6 +49,12 @@ bool GPUInfo::can_lose_context() const {
return can_lose_context_;
}
+void GPUInfo::SetInitializationTime(
+ const base::TimeDelta& initialization_time) {
+ initialization_time_ = initialization_time;
+}
+
+
void GPUInfo::SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
const std::wstring& driver_version,
uint32 pixel_shader_version,
diff --git a/chrome/common/gpu_info.h b/chrome/common/gpu_info.h
index 50728db..bdf8709 100644
--- a/chrome/common/gpu_info.h
+++ b/chrome/common/gpu_info.h
@@ -12,6 +12,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/time.h"
#include "build/build_config.h"
#include "chrome/common/dx_diag_node.h"
@@ -23,6 +24,10 @@ class GPUInfo {
// Returns whether this GPUInfo has been initialized with information
bool initialized() const;
+ // The amount of time taken to get from the process starting to the message
+ // loop being pumped.
+ base::TimeDelta initialization_time() const;
+
// Return the DWORD (uint32) representing the graphics card vendor id.
uint32 vendor_id() const;
@@ -55,6 +60,8 @@ class GPUInfo {
// semantics are available.
bool can_lose_context() const;
+ void SetInitializationTime(const base::TimeDelta& initialization_time);
+
// Populate variables with passed in values
void SetGraphicsInfo(uint32 vendor_id, uint32 device_id,
const std::wstring& driver_version,
@@ -72,6 +79,7 @@ class GPUInfo {
private:
bool initialized_;
+ base::TimeDelta initialization_time_;
uint32 vendor_id_;
uint32 device_id_;
std::wstring driver_version_;
diff --git a/chrome/common/gpu_messages.cc b/chrome/common/gpu_messages.cc
index b8232b8..671a6a6 100644
--- a/chrome/common/gpu_messages.cc
+++ b/chrome/common/gpu_messages.cc
@@ -10,6 +10,7 @@
#include "gfx/rect.h"
#include "gfx/size.h"
#include "ipc/ipc_channel_handle.h"
+#include "ipc/ipc_message_utils.h"
#define MESSAGES_INTERNAL_IMPL_FILE \
"chrome/common/gpu_messages_internal.h"
@@ -80,6 +81,7 @@ void ParamTraits<GpuHostMsg_AcceleratedSurfaceSetIOSurface_Params> ::Log(
#endif // if defined(OS_MACOSX)
void ParamTraits<GPUInfo> ::Write(Message* m, const param_type& p) {
+ ParamTraits<base::TimeDelta> ::Write(m, p.initialization_time());
m->WriteUInt32(p.vendor_id());
m->WriteUInt32(p.device_id());
m->WriteWString(p.driver_version());
@@ -94,6 +96,7 @@ void ParamTraits<GPUInfo> ::Write(Message* m, const param_type& p) {
}
bool ParamTraits<GPUInfo> ::Read(const Message* m, void** iter, param_type* p) {
+ base::TimeDelta initialization_time;
uint32 vendor_id;
uint32 device_id;
std::wstring driver_version;
@@ -101,13 +104,15 @@ bool ParamTraits<GPUInfo> ::Read(const Message* m, void** iter, param_type* p) {
uint32 vertex_shader_version;
uint32 gl_version;
bool can_lose_context;
- bool ret = m->ReadUInt32(iter, &vendor_id);
+ bool ret = ParamTraits<base::TimeDelta> ::Read(m, iter, &initialization_time);
+ ret = ret && m->ReadUInt32(iter, &vendor_id);
ret = ret && m->ReadUInt32(iter, &device_id);
ret = ret && m->ReadWString(iter, &driver_version);
ret = ret && m->ReadUInt32(iter, &pixel_shader_version);
ret = ret && m->ReadUInt32(iter, &vertex_shader_version);
ret = ret && m->ReadUInt32(iter, &gl_version);
ret = ret && m->ReadBool(iter, &can_lose_context);
+ p->SetInitializationTime(initialization_time);
p->SetGraphicsInfo(vendor_id,
device_id,
driver_version,
@@ -126,7 +131,9 @@ bool ParamTraits<GPUInfo> ::Read(const Message* m, void** iter, param_type* p) {
}
void ParamTraits<GPUInfo> ::Log(const param_type& p, std::string* l) {
- l->append(base::StringPrintf("<GPUInfo> %x %x %ls %d",
+ l->append(base::StringPrintf("<GPUInfo> %d %x %x %ls %d",
+ static_cast<int32>(
+ p.initialization_time().InMilliseconds()),
p.vendor_id(),
p.device_id(),
p.driver_version().c_str(),
diff --git a/chrome/common/gpu_messages_unittest.cc b/chrome/common/gpu_messages_unittest.cc
index 455458f..59d42ed 100644
--- a/chrome/common/gpu_messages_unittest.cc
+++ b/chrome/common/gpu_messages_unittest.cc
@@ -13,6 +13,7 @@
TEST(GPUIPCMessageTest, GPUInfo) {
GPUInfo input;
// Test variables taken from Lenovo T61
+ input.SetInitializationTime(base::TimeDelta::FromMilliseconds(100));
input.SetGraphicsInfo(0x10de, 0x429, L"6.14.11.7715",
0xffff0300,
0xfffe0300,
@@ -25,6 +26,8 @@ TEST(GPUIPCMessageTest, GPUInfo) {
GPUInfo output;
void* iter = NULL;
EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output));
+ EXPECT_EQ(input.initialization_time().InMilliseconds(),
+ output.initialization_time().InMilliseconds());
EXPECT_EQ(input.vendor_id(), output.vendor_id());
EXPECT_EQ(input.device_id(), output.device_id());
EXPECT_EQ(input.driver_version(), output.driver_version());
@@ -35,5 +38,5 @@ TEST(GPUIPCMessageTest, GPUInfo) {
std::string log_message;
IPC::LogParam(output, &log_message);
- EXPECT_STREQ("<GPUInfo> 10de 429 6.14.11.7715 1", log_message.c_str());
+ EXPECT_STREQ("<GPUInfo> 100 10de 429 6.14.11.7715 1", log_message.c_str());
}
diff --git a/chrome/gpu/gpu_main.cc b/chrome/gpu/gpu_main.cc
index b6dfef5..cf5822d4 100644
--- a/chrome/gpu/gpu_main.cc
+++ b/chrome/gpu/gpu_main.cc
@@ -2,16 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <stdlib.h>
+
#include "app/app_switches.h"
+#include "app/gfx/gl/gl_context.h"
#include "app/gfx/gl/gl_implementation.h"
+#include "base/environment.h"
#include "base/message_loop.h"
+#include "base/metrics/field_trial.h"
+#include "base/stringprintf.h"
#include "build/build_config.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/env_vars.h"
#include "chrome/common/main_function_params.h"
#include "chrome/gpu/gpu_config.h"
#include "chrome/gpu/gpu_process.h"
#include "chrome/gpu/gpu_thread.h"
+#include "chrome/gpu/gpu_watchdog_thread.h"
#if defined(USE_LINUX_BREAKPAD)
#include "chrome/app/breakpad_linux.h"
@@ -26,9 +34,17 @@
#include "app/x11_util_internal.h"
#endif
-#if defined(USE_X11)
+
namespace {
+// 1% per watchdog trial group.
+const int kFieldTrialSize = 1;
+
+// 5 - 20 seconds timeout.
+const int kMinGpuTimeout = 5;
+const int kMaxGpuTimeout = 20;
+
+#if defined(USE_X11)
int GpuX11ErrorHandler(Display* d, XErrorEvent* error) {
LOG(ERROR) << x11_util::GetErrorEventDescription(d, error);
return 0;
@@ -38,12 +54,14 @@ void SetGpuX11ErrorHandlers() {
// Set up the error handlers so that only general errors aren't fatal.
x11_util::SetX11ErrorHandlers(GpuX11ErrorHandler, NULL);
}
+#endif
}
-#endif
// Main function for starting the Gpu process.
int GpuMain(const MainFunctionParams& parameters) {
+ base::Time start_time = base::Time::Now();
+
#if defined(USE_LINUX_BREAKPAD)
// Needs to be called after we have chrome::DIR_USER_DATA.
InitCrashReporter();
@@ -66,20 +84,75 @@ int GpuMain(const MainFunctionParams& parameters) {
#if defined(OS_WIN)
win_util::ScopedCOMInitializer com_initializer;
-#elif defined(GPU_USE_GLX)
- if (!command_line.HasSwitch(switches::kUseGL)) {
- gfx::InitializeGLBindings(gfx::kGLImplementationDesktopGL);
- }
#endif
- GpuProcess gpu_process;
- gpu_process.set_main_thread(new GpuThread());
-
#if defined(USE_X11)
SetGpuX11ErrorHandlers();
#endif
+ // Load the GL implementation and locate the bindings before starting as
+ // this can take a lot of time and the GPU watchdog might terminate the GPU
+ // process.
+ if (!gfx::GLContext::InitializeOneOff())
+ return EXIT_FAILURE;
+
+ GpuProcess gpu_process;
+ GpuThread* gpu_thread = new GpuThread;
+ gpu_process.set_main_thread(gpu_thread);
+
+ // Only enable this experimental feaure for a subset of users.
+ scoped_refptr<base::FieldTrial> watchdog_trial(
+ new base::FieldTrial("GpuWatchdogTrial", 100));
+ int watchdog_timeout = 0;
+ for (int i = kMinGpuTimeout; i <= kMaxGpuTimeout; ++i) {
+ int group = watchdog_trial->AppendGroup(StringPrintf("%dsecs", i),
+ kFieldTrialSize);
+ if (group == watchdog_trial->group()) {
+ watchdog_timeout = i;
+ break;
+ }
+ }
+
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+
+ // In addition to disabling the watchdog if the command line switch is
+ // present, disable it in two other cases. OSMesa is expected to run very
+ // slowly. Also disable the watchdog on valgrind because the code is expected
+ // to run slowly in that case.
+ bool enable_watchdog =
+ watchdog_timeout != 0 &&
+ !command_line.HasSwitch(switches::kDisableGpuWatchdog) &&
+ gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL &&
+ !RunningOnValgrind();
+
+ // Disable the watchdog in debug builds because they tend to only be run by
+ // developers who will not appreciate the watchdog killing the GPU process.
+#ifndef NDEBUG
+ enable_watchdog = false;
+#endif
+
+// TODO(apatrick): Disable for this commit. I want to enable this feature with
+// a simple single file change that can easily be reverted if need be without
+// losing all the other features of the patch.
+#if 1
+ enable_watchdog = false;
+#endif
+
+ scoped_refptr<GpuWatchdogThread> watchdog_thread;
+ if (enable_watchdog) {
+ watchdog_thread = new GpuWatchdogThread(MessageLoop::current(),
+ watchdog_timeout * 1000);
+ watchdog_thread->Start();
+ }
+
+ // Do this immediately before running the message loop so the correct
+ // initialization time is recorded in the GPU info.
+ gpu_thread->Init(start_time);
+
main_message_loop.Run();
+ if (enable_watchdog)
+ watchdog_thread->Stop();
+
return 0;
}
diff --git a/chrome/gpu/gpu_thread.cc b/chrome/gpu/gpu_thread.cc
index 6116b48..9dc57d8 100644
--- a/chrome/gpu/gpu_thread.cc
+++ b/chrome/gpu/gpu_thread.cc
@@ -12,7 +12,6 @@
#include "build/build_config.h"
#include "chrome/common/child_process.h"
#include "chrome/common/child_process_logging.h"
-#include "chrome/common/gpu_info.h"
#include "chrome/common/gpu_messages.h"
#include "chrome/gpu/gpu_info_collector.h"
#include "ipc/ipc_channel_handle.h"
@@ -41,6 +40,15 @@ GpuThread::GpuThread() {
GpuThread::~GpuThread() {
}
+void GpuThread::Init(const base::Time& process_start_time) {
+ gpu_info_collector::CollectGraphicsInfo(&gpu_info_);
+ child_process_logging::SetGpuInfo(gpu_info_);
+
+ // Record initialization only after collecting the GPU info because that can
+ // take a significant amount of time.
+ gpu_info_.SetInitializationTime(base::Time::Now() - process_start_time);
+}
+
void GpuThread::RemoveChannel(int renderer_id) {
gpu_channels_.erase(renderer_id);
}
@@ -66,39 +74,30 @@ void GpuThread::OnEstablishChannel(int renderer_id) {
IPC::ChannelHandle channel_handle;
GPUInfo gpu_info;
- // Fail to establish a channel if some implementation of GL cannot be
- // initialized.
- if (gfx::GLContext::InitializeOneOff()) {
- if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info))
- LOG(WARNING) << "Could not collect GPU info.";
-
- child_process_logging::SetGpuInfo(gpu_info);
- GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id);
+ GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id);
+ if (iter == gpu_channels_.end())
+ channel = new GpuChannel(renderer_id);
+ else
+ channel = iter->second;
- if (iter == gpu_channels_.end())
- channel = new GpuChannel(renderer_id);
- else
- channel = iter->second;
+ DCHECK(channel != NULL);
- DCHECK(channel != NULL);
+ if (channel->Init())
+ gpu_channels_[renderer_id] = channel;
+ else
+ channel = NULL;
- if (channel->Init())
- gpu_channels_[renderer_id] = channel;
- else
- channel = NULL;
-
- if (channel.get()) {
- channel_handle.name = channel->GetChannelName();
+ if (channel.get()) {
+ channel_handle.name = channel->GetChannelName();
#if defined(OS_POSIX)
- // On POSIX, pass the renderer-side FD. Also mark it as auto-close so
- // that it gets closed after it has been sent.
- int renderer_fd = channel->DisownRendererFd();
- channel_handle.socket = base::FileDescriptor(renderer_fd, true);
+ // On POSIX, pass the renderer-side FD. Also mark it as auto-close so
+ // that it gets closed after it has been sent.
+ int renderer_fd = channel->DisownRendererFd();
+ channel_handle.socket = base::FileDescriptor(renderer_fd, true);
#endif
- }
}
- Send(new GpuHostMsg_ChannelEstablished(channel_handle, gpu_info));
+ Send(new GpuHostMsg_ChannelEstablished(channel_handle, gpu_info_));
}
void GpuThread::OnSynchronize() {
@@ -106,14 +105,7 @@ void GpuThread::OnSynchronize() {
}
void GpuThread::OnCollectGraphicsInfo() {
- // Fail to establish a channel if some implementation of GL cannot be
- // initialized.
- GPUInfo gpu_info;
- if (gfx::GLContext::InitializeOneOff()) {
- gpu_info_collector::CollectGraphicsInfo(&gpu_info);
- }
-
- Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info));
+ Send(new GpuHostMsg_GraphicsInfoCollected(gpu_info_));
}
void GpuThread::OnCrash() {
diff --git a/chrome/gpu/gpu_thread.h b/chrome/gpu/gpu_thread.h
index 65a0234..56d4b431 100644
--- a/chrome/gpu/gpu_thread.h
+++ b/chrome/gpu/gpu_thread.h
@@ -8,8 +8,10 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "base/time.h"
#include "build/build_config.h"
#include "chrome/common/child_thread.h"
+#include "chrome/common/gpu_info.h"
#include "chrome/gpu/gpu_channel.h"
#include "chrome/gpu/gpu_config.h"
#include "chrome/gpu/x_util.h"
@@ -20,6 +22,8 @@ class GpuThread : public ChildThread {
GpuThread();
~GpuThread();
+ void Init(const base::Time& process_start_time);
+
// Remove the channel for a particular renderer.
void RemoveChannel(int renderer_id);
@@ -37,6 +41,9 @@ class GpuThread : public ChildThread {
typedef base::hash_map<int, scoped_refptr<GpuChannel> > GpuChannelMap;
GpuChannelMap gpu_channels_;
+ // Information about the GPU, such as device and vendor ID.
+ GPUInfo gpu_info_;
+
DISALLOW_COPY_AND_ASSIGN(GpuThread);
};
diff --git a/chrome/gpu/gpu_watchdog_thread.cc b/chrome/gpu/gpu_watchdog_thread.cc
new file mode 100644
index 0000000..e262c79
--- /dev/null
+++ b/chrome/gpu/gpu_watchdog_thread.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
+#include "chrome/gpu/gpu_watchdog_thread.h"
+
+#include "base/compiler_specific.h"
+#include "build/build_config.h"
+
+namespace {
+const int64 kCheckPeriod = 2000;
+}
+
+GpuWatchdogThread::GpuWatchdogThread(MessageLoop* watched_message_loop,
+ int timeout)
+ : base::Thread("Watchdog"),
+ watched_message_loop_(watched_message_loop),
+ timeout_(timeout) {
+ DCHECK(watched_message_loop);
+ DCHECK(timeout >= 0);
+}
+
+GpuWatchdogThread::~GpuWatchdogThread() {
+ // Verify that the thread was explicitly stopped. If the thread is stopped
+ // implicitly by the destructor, CleanUp() will not be called.
+ DCHECK(!method_factory_.get());
+}
+
+void GpuWatchdogThread::Init() {
+ // The method factory must be created on the watchdog thread.
+ method_factory_.reset(new MethodFactory(this));
+
+ // Schedule the first check.
+ OnCheck();
+}
+
+void GpuWatchdogThread::CleanUp() {
+ // The method factory must be destroyed on the watchdog thread.
+ method_factory_->RevokeAll();
+ method_factory_.reset();
+
+ // Prevent any more delayed tasks from being posted.
+ watched_message_loop_ = NULL;
+}
+
+void GpuWatchdogThread::OnAcknowledge() {
+ // Revoke any pending OnExit.
+ method_factory_->RevokeAll();
+
+ // The monitored thread has responded. Post a task to check it again.
+ if (watched_message_loop_) {
+ message_loop()->PostDelayedTask(
+ FROM_HERE,
+ method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnCheck),
+ kCheckPeriod);
+ }
+}
+
+void GpuWatchdogThread::OnCheck() {
+ if (watched_message_loop_) {
+ // Post a task to the monitored thread that simply responds with a task that
+ // calls OnAcknowldge.
+ watched_message_loop_->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &GpuWatchdogThread::PostAcknowledge));
+
+ // Post a task to the watchdog thread to exit if the nmonitored thread does
+ // not respond in time.
+ message_loop()->PostDelayedTask(
+ FROM_HERE,
+ method_factory_->NewRunnableMethod(&GpuWatchdogThread::OnExit),
+ timeout_);
+ }
+}
+
+void GpuWatchdogThread::PostAcknowledge() {
+ // Called on the monitored thread. Responds with OnAcknowledge. Cannot use
+ // the method factory. Rely on reference counting instead.
+ message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &GpuWatchdogThread::OnAcknowledge));
+}
+
+// Use the --disable-gpu-watchdog command line switch to disable this.
+void GpuWatchdogThread::OnExit() {
+ // Make sure the timeout period is on the stack before crashing.
+ volatile int timeout = timeout_;
+
+ // For minimal developer annoyance, don't keep crashing.
+ static bool crashed = false;
+ if (crashed)
+ return;
+
+#if defined(OS_WIN)
+ if (IsDebuggerPresent())
+ return;
+#endif
+
+ LOG(ERROR) << "The GPU process hung. Restarting after "
+ << timeout_ << " seconds.";
+
+ volatile int* null_pointer = NULL;
+ *null_pointer = timeout;
+
+ crashed = true;
+}
diff --git a/chrome/gpu/gpu_watchdog_thread.h b/chrome/gpu/gpu_watchdog_thread.h
new file mode 100644
index 0000000..d6e1117
--- /dev/null
+++ b/chrome/gpu/gpu_watchdog_thread.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_GPU_GPU_WATCHDOG_THREAD_H_
+#define CHROME_GPU_GPU_WATCHDOG_THREAD_H_
+
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+#include "base/thread.h"
+
+// A thread that intermitently sends tasks to a group of watched message loops
+// and deliberately crashes if one of them does not respond after a timeout.
+class GpuWatchdogThread : public base::Thread,
+ public base::RefCountedThreadSafe<GpuWatchdogThread> {
+ public:
+ GpuWatchdogThread(MessageLoop* watched_message_loop, int timeout);
+ virtual ~GpuWatchdogThread();
+
+ protected:
+ virtual void Init();
+ virtual void CleanUp();
+
+ private:
+ void OnAcknowledge();
+ void OnCheck();
+ void PostAcknowledge();
+ void OnExit();
+ void Disable();
+
+ MessageLoop* watched_message_loop_;
+ int timeout_;
+
+ typedef ScopedRunnableMethodFactory<GpuWatchdogThread> MethodFactory;
+ scoped_ptr<MethodFactory> method_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuWatchdogThread);
+};
+
+#endif // CHROME_GPU_GPU_WATCHDOG_THREAD_H_
diff --git a/chrome/renderer/command_buffer_proxy.cc b/chrome/renderer/command_buffer_proxy.cc
index 0a0f9ad..0cc1e6a 100644
--- a/chrome/renderer/command_buffer_proxy.cc
+++ b/chrome/renderer/command_buffer_proxy.cc
@@ -53,16 +53,6 @@ void CommandBufferProxy::OnChannelError() {
last_state_.error = gpu::error::kLostContext;
}
-bool CommandBufferProxy::Send(IPC::Message* msg) {
- if (channel_)
- return channel_->Send(msg);
-
- // Callee takes ownership of message, regardless of whether Send is
- // successful. See IPC::Message::Sender.
- delete msg;
- return false;
-}
-
bool CommandBufferProxy::Initialize(int32 size) {
DCHECK(!ring_buffer_.get());
@@ -94,14 +84,21 @@ Buffer CommandBufferProxy::GetRingBuffer() {
}
gpu::CommandBuffer::State CommandBufferProxy::GetState() {
- Send(new GpuCommandBufferMsg_GetState(route_id_, &last_state_));
+ // Send will flag state with lost context if IPC fails.
+ if (last_state_.error == gpu::error::kNoError)
+ Send(new GpuCommandBufferMsg_GetState(route_id_, &last_state_));
+
return last_state_;
}
gpu::CommandBuffer::State CommandBufferProxy::Flush(int32 put_offset) {
- Send(new GpuCommandBufferMsg_Flush(route_id_,
- put_offset,
- &last_state_));
+ // Send will flag state with lost context if IPC fails.
+ if (last_state_.error == gpu::error::kNoError) {
+ Send(new GpuCommandBufferMsg_Flush(route_id_,
+ put_offset,
+ &last_state_));
+ }
+
return last_state_;
}
@@ -111,14 +108,22 @@ void CommandBufferProxy::SetGetOffset(int32 get_offset) {
}
int32 CommandBufferProxy::CreateTransferBuffer(size_t size) {
- int32 id;
- if (Send(new GpuCommandBufferMsg_CreateTransferBuffer(route_id_, size, &id)))
- return id;
+ if (last_state_.error == gpu::error::kNoError) {
+ int32 id;
+ if (Send(new GpuCommandBufferMsg_CreateTransferBuffer(route_id_,
+ size,
+ &id))) {
+ return id;
+ }
+ }
return -1;
}
void CommandBufferProxy::DestroyTransferBuffer(int32 id) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
// Remove the transfer buffer from the client side4 cache.
TransferBufferMap::iterator it = transfer_buffers_.find(id);
DCHECK(it != transfer_buffers_.end());
@@ -132,6 +137,9 @@ void CommandBufferProxy::DestroyTransferBuffer(int32 id) {
}
Buffer CommandBufferProxy::GetTransferBuffer(int32 id) {
+ if (last_state_.error != gpu::error::kNoError)
+ return Buffer();
+
// Check local cache to see if there is already a client side shared memory
// object for this id.
TransferBufferMap::iterator it = transfer_buffers_.find(id);
@@ -197,8 +205,12 @@ void CommandBufferProxy::SetSwapBuffersCallback(Callback0::Type* callback) {
}
void CommandBufferProxy::ResizeOffscreenFrameBuffer(const gfx::Size& size) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
IPC::Message* message =
new GpuCommandBufferMsg_ResizeOffscreenFrameBuffer(route_id_, size);
+
// We need to set the unblock flag on this message to guarantee the
// order in which it is processed in the GPU process. Ordinarily in
// certain situations, namely if a synchronous message is being
@@ -220,11 +232,17 @@ void CommandBufferProxy::SetNotifyRepaintTask(Task* task) {
#if defined(OS_MACOSX)
void CommandBufferProxy::SetWindowSize(const gfx::Size& size) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
Send(new GpuCommandBufferMsg_SetWindowSize(route_id_, size));
}
#endif
void CommandBufferProxy::AsyncGetState(Task* completion_task) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
IPC::Message* message = new GpuCommandBufferMsg_AsyncGetState(route_id_);
// Do not let a synchronous flush hold up this message. If this handler is
@@ -237,6 +255,9 @@ void CommandBufferProxy::AsyncGetState(Task* completion_task) {
}
void CommandBufferProxy::AsyncFlush(int32 put_offset, Task* completion_task) {
+ if (last_state_.error != gpu::error::kNoError)
+ return;
+
IPC::Message* message = new GpuCommandBufferMsg_AsyncFlush(route_id_,
put_offset);
@@ -249,6 +270,28 @@ void CommandBufferProxy::AsyncFlush(int32 put_offset, Task* completion_task) {
pending_async_flush_tasks_.push(linked_ptr<Task>(completion_task));
}
+bool CommandBufferProxy::Send(IPC::Message* msg) {
+ // Caller should not intentionally send a message if the context is lost.
+ DCHECK(last_state_.error == gpu::error::kNoError);
+
+ if (channel_) {
+ if (channel_->Send(msg)) {
+ return true;
+ } else {
+ // Flag the command buffer as lost. Defer deleting the channel until
+ // OnChannelError is called after returning to the message loop in case
+ // it is referenced elsewhere.
+ last_state_.error = gpu::error::kLostContext;
+ return false;
+ }
+ }
+
+ // Callee takes ownership of message, regardless of whether Send is
+ // successful. See IPC::Message::Sender.
+ delete msg;
+ return false;
+}
+
void CommandBufferProxy::OnUpdateState(const gpu::CommandBuffer::State& state) {
last_state_ = state;
diff --git a/chrome/renderer/command_buffer_proxy.h b/chrome/renderer/command_buffer_proxy.h
index 89a00df..245c0580 100644
--- a/chrome/renderer/command_buffer_proxy.h
+++ b/chrome/renderer/command_buffer_proxy.h
@@ -32,8 +32,7 @@ class Task;
// Client side proxy that forwards messages synchronously to a
// CommandBufferStub.
class CommandBufferProxy : public gpu::CommandBuffer,
- public IPC::Channel::Listener,
- public IPC::Message::Sender {
+ public IPC::Channel::Listener {
public:
CommandBufferProxy(IPC::Channel::Sender* channel, int route_id);
virtual ~CommandBufferProxy();
@@ -42,9 +41,6 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual void OnMessageReceived(const IPC::Message& message);
virtual void OnChannelError();
- // IPC::Message::Sender implementation:
- virtual bool Send(IPC::Message* msg);
-
int route_id() const { return route_id_; }
// CommandBuffer implementation:
@@ -89,6 +85,12 @@ class CommandBufferProxy : public gpu::CommandBuffer,
void AsyncFlush(int32 put_offset, Task* completion_task);
private:
+
+ // Send an IPC message over the GPU channel. This is private to fully
+ // encapsulate the channel; all callers of this function must explicitly
+ // verify that the context has not been lost.
+ bool Send(IPC::Message* msg);
+
// Message handlers:
void OnUpdateState(const gpu::CommandBuffer::State& state);
void OnNotifyRepaint();
diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc
index cfe6743..67fc932 100644
--- a/chrome/renderer/ggl/ggl.cc
+++ b/chrome/renderer/ggl/ggl.cc
@@ -158,7 +158,7 @@ bool Context::Initialize(gfx::NativeViewId view,
const int32* attrib_list) {
DCHECK(size.width() >= 0 && size.height() >= 0);
- if (channel_->state() != GpuChannelHost::CONNECTED)
+ if (channel_->state() != GpuChannelHost::kConnected)
return false;
// Ensure the gles2 library is initialized first in a thread safe way.
diff --git a/chrome/renderer/gpu_channel_host.cc b/chrome/renderer/gpu_channel_host.cc
index e2e14be..6ce8d7d 100644
--- a/chrome/renderer/gpu_channel_host.cc
+++ b/chrome/renderer/gpu_channel_host.cc
@@ -10,7 +10,7 @@
#include "chrome/renderer/command_buffer_proxy.h"
#include "chrome/renderer/gpu_video_service_host.h"
-GpuChannelHost::GpuChannelHost() : state_(UNCONNECTED) {
+GpuChannelHost::GpuChannelHost() : state_(kUnconnected) {
}
GpuChannelHost::~GpuChannelHost() {
@@ -26,7 +26,7 @@ void GpuChannelHost::Connect(const std::string& channel_name) {
// It is safe to send IPC messages before the channel completes the connection
// and receives the hello message from the GPU process. The messages get
// cached.
- state_ = CONNECTED;
+ state_ = kConnected;
}
void GpuChannelHost::set_gpu_info(const GPUInfo& gpu_info) {
@@ -55,7 +55,7 @@ void GpuChannelHost::OnChannelConnected(int32 peer_pid) {
}
void GpuChannelHost::OnChannelError() {
- state_ = LOST;
+ state_ = kLost;
// Channel is invalid and will be reinitialized if this host is requested
// again.
@@ -76,12 +76,13 @@ void GpuChannelHost::OnChannelError() {
}
bool GpuChannelHost::Send(IPC::Message* message) {
- if (!channel_.get()) {
- delete message;
- return false;
- }
+ if (channel_.get())
+ return channel_->Send(message);
- return channel_->Send(message);
+ // Callee takes ownership of message, regardless of whether Send is
+ // successful. See IPC::Message::Sender.
+ delete message;
+ return false;
}
CommandBufferProxy* GpuChannelHost::CreateViewCommandBuffer(
diff --git a/chrome/renderer/gpu_channel_host.h b/chrome/renderer/gpu_channel_host.h
index dc738bd..818202e 100644
--- a/chrome/renderer/gpu_channel_host.h
+++ b/chrome/renderer/gpu_channel_host.h
@@ -30,12 +30,12 @@ class GpuChannelHost : public IPC::Channel::Listener,
public:
enum State {
// Not yet connected.
- UNCONNECTED,
+ kUnconnected,
// Ready to use.
- CONNECTED,
+ kConnected,
// An error caused the host to become disconnected. Recreate channel to
// reestablish connection.
- LOST
+ kLost
};
// Called on the render thread
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc
index d7b6c87..d056fdb 100644
--- a/chrome/renderer/pepper_plugin_delegate_impl.cc
+++ b/chrome/renderer/pepper_plugin_delegate_impl.cc
@@ -196,7 +196,7 @@ bool PlatformContext3DImpl::Init() {
if (!host)
return false;
- DCHECK(host->state() == GpuChannelHost::CONNECTED);
+ DCHECK(host->state() == GpuChannelHost::kConnected);
// TODO(apatrick): Let Pepper plugins configure their back buffer surface.
static const int32 attribs[] = {
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index a43a6ec..b871bbe 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -765,12 +765,12 @@ void RenderThread::EstablishGpuChannel() {
if (gpu_channel_.get()) {
// Do nothing if we already have a GPU channel or are already
// establishing one.
- if (gpu_channel_->state() == GpuChannelHost::UNCONNECTED ||
- gpu_channel_->state() == GpuChannelHost::CONNECTED)
+ if (gpu_channel_->state() == GpuChannelHost::kUnconnected ||
+ gpu_channel_->state() == GpuChannelHost::kConnected)
return;
// Recreate the channel if it has been lost.
- if (gpu_channel_->state() == GpuChannelHost::LOST)
+ if (gpu_channel_->state() == GpuChannelHost::kLost)
gpu_channel_ = NULL;
}
@@ -791,7 +791,7 @@ GpuChannelHost* RenderThread::GetGpuChannel() {
if (!gpu_channel_.get())
return NULL;
- if (gpu_channel_->state() != GpuChannelHost::CONNECTED)
+ if (gpu_channel_->state() != GpuChannelHost::kConnected)
return NULL;
return gpu_channel_.get();
diff --git a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
index 5246bdc..f8725af 100644
--- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
+++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc
@@ -72,7 +72,7 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
GpuChannelHost* host = render_thread->EstablishGpuChannelSync();
if (!host)
return false;
- DCHECK(host->state() == GpuChannelHost::CONNECTED);
+ DCHECK(host->state() == GpuChannelHost::kConnected);
// Convert WebGL context creation attributes into GGL/EGL size requests.
const int alpha_size = attributes.alpha ? 8 : 0;