diff options
28 files changed, 475 insertions, 118 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 3cba7dc..432474a 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -762,28 +762,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; } @@ -1120,11 +1130,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 a33ef5c..b9e26e3 100644 --- a/chrome/browser/gpu_process_host.cc +++ b/chrome/browser/gpu_process_host.cc @@ -94,6 +94,7 @@ bool GpuProcessHost::Init() { static const char* const kSwitchNames[] = { switches::kUseGL, switches::kDisableGpuVsync, + switches::kDisableGpuWatchdog, switches::kDisableLogging, switches::kEnableAcceleratedDecoding, switches::kEnableLogging, @@ -126,16 +127,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 0e14402..68e0496 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 71db44b..9ab296d 100644 --- a/chrome/browser/gpu_process_host_ui_shim.cc +++ b/chrome/browser/gpu_process_host_ui_shim.cc @@ -74,3 +74,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 3e5d93b..a65f29c 100644 --- a/chrome/browser/gpu_process_host_ui_shim.h +++ b/chrome/browser/gpu_process_host_ui_shim.h @@ -46,6 +46,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 91a4636..35bc0ef 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -724,6 +724,8 @@ 'gpu/gpu_video_service.h', 'gpu/gpu_view_win.cc', 'gpu/gpu_view_win.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', @@ -739,6 +741,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/chrome_tests.gypi b/chrome/chrome_tests.gypi index 704171d..6534a6b 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -455,6 +455,7 @@ '../third_party/icu/icu.gyp:icuuc', '../third_party/libxml/libxml.gyp:libxml', # run time dependencies + '../third_party/mesa/mesa.gyp:osmesa', 'default_plugin/default_plugin.gyp:default_plugin', '../third_party/ppapi/ppapi.gyp:ppapi_tests', '../webkit/support/webkit_support.gyp:copy_npapi_layout_test_plugin', @@ -522,7 +523,6 @@ ['target_arch!="x64" and target_arch!="arm"', { 'dependencies': [ '../webkit/webkit.gyp:copy_npapi_test_plugin', - '../third_party/mesa/mesa.gyp:osmesa', ], }], # Only copy the pepper plugin on Windows which is the only platform diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index ba116a4..9263dd7 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -194,6 +194,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 ffd8dfe..3ac43ba 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 db7f597..e138a43 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(StringPrintf("<GPUInfo> %x %x %ls %d", + l->append(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 0c0d3c51..51a75d5 100644 --- a/chrome/gpu/gpu_main.cc +++ b/chrome/gpu/gpu_main.cc @@ -2,15 +2,23 @@ // 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/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" @@ -25,9 +33,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; @@ -37,12 +53,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(); @@ -65,18 +83,75 @@ int GpuMain(const MainFunctionParams& parameters) { #if defined(OS_WIN) win_util::ScopedCOMInitializer com_initializer; -#elif defined(GPU_USE_GLX) - gfx::InitializeGLBindings(gfx::kGLImplementationDesktopGL); #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; - gpu_process.set_main_thread(new GpuThread()); + 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(); + } #if defined(USE_X11) SetGpuX11ErrorHandlers(); #endif + // 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 8c1059f..3a1dc7b 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" @@ -67,6 +66,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); +} + #if defined(GPU_USE_GLX) GpuBackingStoreGLXContext* GpuThread::GetGLXContext() { if (!glx_context_.get()) @@ -102,40 +110,32 @@ 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()) { - // Fail to establish channel if GPU stats cannot be retreived. - if (gpu_info_collector::CollectGraphicsInfo(&gpu_info)) { - child_process_logging::SetGpuInfo(gpu_info); - GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); - if (iter == gpu_channels_.end()) { - channel = new GpuChannel(renderer_id); - } else { - channel = iter->second; - } - - DCHECK(channel != NULL); - - if (channel->Init()) { - gpu_channels_[renderer_id] = channel; - } else { - channel = NULL; - } - - if (channel.get()) { - channel_handle.name = channel->GetChannelName(); + GpuChannelMap::const_iterator iter = gpu_channels_.find(renderer_id); + if (iter == gpu_channels_.end()) { + channel = new GpuChannel(renderer_id); + } else { + channel = iter->second; + } + + DCHECK(channel != NULL); + + if (channel->Init()) { + gpu_channels_[renderer_id] = channel; + } else { + channel = NULL; + } + + 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() { @@ -157,14 +157,7 @@ void GpuThread::OnNewRenderWidgetHostView(GpuNativeWindowHandle parent_window, } 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 b896360..6d20422 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/common/gpu_native_window_handle.h" #include "chrome/gpu/gpu_channel.h" #include "chrome/gpu/gpu_config.h" @@ -25,6 +27,8 @@ class GpuThread : public ChildThread { GpuThread(); ~GpuThread(); + void Init(const base::Time& process_start_time); + #if defined(GPU_USE_GLX) GpuBackingStoreGLXContext* GetGLXContext(); @@ -55,6 +59,9 @@ class GpuThread : public ChildThread { scoped_ptr<GpuBackingStoreGLXContext> glx_context_; #endif + // 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 aade75f..43fe0c0 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(gpu::CommandBuffer::State state) { last_state_ = state; diff --git a/chrome/renderer/command_buffer_proxy.h b/chrome/renderer/command_buffer_proxy.h index 9b8e3f7..b425074 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(gpu::CommandBuffer::State state); void OnNotifyRepaint(); diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc index 0589852..2826013 100644 --- a/chrome/renderer/ggl/ggl.cc +++ b/chrome/renderer/ggl/ggl.cc @@ -156,7 +156,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/render_thread.cc b/chrome/renderer/render_thread.cc index ebb8af7..3ab778d 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -772,12 +772,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; } @@ -798,7 +798,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 1ffd0fe..3c4e38e 100644 --- a/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc +++ b/chrome/renderer/webgraphicscontext3d_command_buffer_impl.cc @@ -70,7 +70,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; diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 8c72435..69f2601 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -12,6 +12,7 @@ #include <set> #include <vector> +#include "app/app_switches.h" #include "app/sql/connection.h" #include "base/base_switches.h" #include "base/command_line.h" @@ -135,6 +136,9 @@ void UITestBase::SetUp() { AssertAppNotRunning(L"Please close any other instances " L"of the app before testing."); + // Force all tests to use OSMesa if they launch the GPU process. + launch_arguments_.AppendSwitchASCII(switches::kUseGL, "osmesa"); + JavaScriptExecutionController::set_timeout( TestTimeouts::action_max_timeout_ms()); test_start_time_ = Time::NowFromSystemTime(); diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index 9664810..cc10cc2 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -250,6 +250,25 @@ void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { ParamTraits<int64>::Log(p.ToInternalValue(), l); } +void ParamTraits<base::TimeDelta> ::Write(Message* m, const param_type& p) { + ParamTraits<int64> ::Write(m, p.InMicroseconds()); +} + +bool ParamTraits<base::TimeDelta> ::Read(const Message* m, + void** iter, + param_type* r) { + int64 value; + bool ret = ParamTraits<int64> ::Read(m, iter, &value); + if (ret) + *r = base::TimeDelta::FromMicroseconds(value); + + return ret; +} + +void ParamTraits<base::TimeDelta> ::Log(const param_type& p, std::string* l) { + ParamTraits<int64> ::Log(p.InMicroseconds(), l); +} + void ParamTraits<DictionaryValue>::Write(Message* m, const param_type& p) { WriteValue(m, &p, 0); } diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 0e22c6b..9629fac 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -88,6 +88,7 @@ class NullableString16; namespace base { class Time; +class TimeDelta; struct FileDescriptor; } @@ -293,6 +294,14 @@ struct ParamTraits<base::Time> { static void Log(const param_type& p, std::string* l); }; +template <> +struct ParamTraits<base::TimeDelta> { + typedef base::TimeDelta param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + #if defined(OS_WIN) template <> struct ParamTraits<LOGFONT> { |