| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 20 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "content/child/child_process.h" | 23 #include "content/child/child_process.h" |
| 24 #include "content/common/content_constants_internal.h" | 24 #include "content/common/content_constants_internal.h" |
| 25 #include "content/common/gpu_host_messages.h" | 25 #include "content/common/gpu_host_messages.h" |
| 26 #include "content/common/sandbox_linux/sandbox_linux.h" | 26 #include "content/common/sandbox_linux/sandbox_linux.h" |
| 27 #include "content/gpu/gpu_child_thread.h" | 27 #include "content/gpu/gpu_child_thread.h" |
| 28 #include "content/gpu/gpu_process.h" | 28 #include "content/gpu/gpu_process.h" |
| 29 #include "content/gpu/gpu_watchdog_thread.h" | |
| 30 #include "content/public/common/content_client.h" | 29 #include "content/public/common/content_client.h" |
| 31 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 32 #include "content/public/common/main_function_params.h" | 31 #include "content/public/common/main_function_params.h" |
| 33 #include "gpu/command_buffer/service/gpu_switches.h" | 32 #include "gpu/command_buffer/service/gpu_switches.h" |
| 34 #include "gpu/config/gpu_info_collector.h" | 33 #include "gpu/config/gpu_info_collector.h" |
| 35 #include "gpu/config/gpu_switches.h" | 34 #include "gpu/config/gpu_switches.h" |
| 36 #include "gpu/config/gpu_util.h" | 35 #include "gpu/config/gpu_util.h" |
| 37 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 36 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 38 #include "gpu/ipc/service/gpu_config.h" | 37 #include "gpu/ipc/service/gpu_config.h" |
| 39 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 38 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| 39 #include "gpu/ipc/service/gpu_watchdog_thread.h" |
| 40 #include "ui/events/platform/platform_event_source.h" | 40 #include "ui/events/platform/platform_event_source.h" |
| 41 #include "ui/gl/gl_context.h" | 41 #include "ui/gl/gl_context.h" |
| 42 #include "ui/gl/gl_implementation.h" | 42 #include "ui/gl/gl_implementation.h" |
| 43 #include "ui/gl/gl_surface.h" | 43 #include "ui/gl/gl_surface.h" |
| 44 #include "ui/gl/gl_switches.h" | 44 #include "ui/gl/gl_switches.h" |
| 45 #include "ui/gl/gpu_switching_manager.h" | 45 #include "ui/gl/gpu_switching_manager.h" |
| 46 #include "ui/gl/init/gl_factory.h" | 46 #include "ui/gl/init/gl_factory.h" |
| 47 | 47 |
| 48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 49 #include <windows.h> | 49 #include <windows.h> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 80 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 81 #include "media/gpu/vaapi_wrapper.h" | 81 #include "media/gpu/vaapi_wrapper.h" |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 #if defined(SANITIZER_COVERAGE) | 84 #if defined(SANITIZER_COVERAGE) |
| 85 #include <sanitizer/common_interface_defs.h> | 85 #include <sanitizer/common_interface_defs.h> |
| 86 #include <sanitizer/coverage_interface.h> | 86 #include <sanitizer/coverage_interface.h> |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 #if defined(CYGPROFILE_INSTRUMENTATION) | |
| 90 const int kGpuTimeout = 30000; | |
| 91 #elif defined(OS_WIN) | |
| 92 // Use a slightly longer timeout on Windows due to prevalence of slow and | |
| 93 // infected machines. | |
| 94 const int kGpuTimeout = 15000; | |
| 95 #else | |
| 96 const int kGpuTimeout = 10000; | |
| 97 #endif | |
| 98 | |
| 99 namespace content { | 89 namespace content { |
| 100 | 90 |
| 101 namespace { | 91 namespace { |
| 102 | 92 |
| 103 void GetGpuInfoFromCommandLine(gpu::GPUInfo& gpu_info, | 93 void GetGpuInfoFromCommandLine(gpu::GPUInfo& gpu_info, |
| 104 const base::CommandLine& command_line); | 94 const base::CommandLine& command_line); |
| 105 void WarmUpSandbox(); | 95 void WarmUpSandbox(); |
| 106 | 96 |
| 107 #if !defined(OS_MACOSX) | 97 #if !defined(OS_MACOSX) |
| 108 bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info); | 98 bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info); |
| 109 #endif | 99 #endif |
| 110 | 100 |
| 111 #if defined(OS_LINUX) | 101 #if defined(OS_LINUX) |
| 112 #if !defined(OS_CHROMEOS) | 102 #if !defined(OS_CHROMEOS) |
| 113 bool CanAccessNvidiaDeviceFile(); | 103 bool CanAccessNvidiaDeviceFile(); |
| 114 #endif | 104 #endif |
| 115 bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*); | 105 bool StartSandboxLinux(const gpu::GPUInfo&, gpu::GpuWatchdogThread*); |
| 116 #elif defined(OS_WIN) | 106 #elif defined(OS_WIN) |
| 117 bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*); | 107 bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*); |
| 118 #endif | 108 #endif |
| 119 | 109 |
| 120 base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages = | 110 base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages = |
| 121 LAZY_INSTANCE_INITIALIZER; | 111 LAZY_INSTANCE_INITIALIZER; |
| 122 | 112 |
| 123 bool GpuProcessLogMessageHandler(int severity, | 113 bool GpuProcessLogMessageHandler(int severity, |
| 124 const char* file, int line, | 114 const char* file, int line, |
| 125 size_t message_start, | 115 size_t message_start, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 #endif | 218 #endif |
| 229 | 219 |
| 230 bool delayed_watchdog_enable = false; | 220 bool delayed_watchdog_enable = false; |
| 231 | 221 |
| 232 #if defined(OS_CHROMEOS) | 222 #if defined(OS_CHROMEOS) |
| 233 // Don't start watchdog immediately, to allow developers to switch to VT2 on | 223 // Don't start watchdog immediately, to allow developers to switch to VT2 on |
| 234 // startup. | 224 // startup. |
| 235 delayed_watchdog_enable = true; | 225 delayed_watchdog_enable = true; |
| 236 #endif | 226 #endif |
| 237 | 227 |
| 238 scoped_refptr<GpuWatchdogThread> watchdog_thread; | 228 scoped_refptr<gpu::GpuWatchdogThread> watchdog_thread; |
| 239 | 229 |
| 240 // Start the GPU watchdog only after anything that is expected to be time | 230 // Start the GPU watchdog only after anything that is expected to be time |
| 241 // consuming has completed, otherwise the process is liable to be aborted. | 231 // consuming has completed, otherwise the process is liable to be aborted. |
| 242 if (enable_watchdog && !delayed_watchdog_enable) { | 232 if (enable_watchdog && !delayed_watchdog_enable) |
| 243 watchdog_thread = new GpuWatchdogThread(kGpuTimeout); | 233 watchdog_thread = gpu::GpuWatchdogThread::Create(); |
| 244 base::Thread::Options options; | |
| 245 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
| 246 watchdog_thread->StartWithOptions(options); | |
| 247 } | |
| 248 | 234 |
| 249 // Initializes StatisticsRecorder which tracks UMA histograms. | 235 // Initializes StatisticsRecorder which tracks UMA histograms. |
| 250 base::StatisticsRecorder::Initialize(); | 236 base::StatisticsRecorder::Initialize(); |
| 251 | 237 |
| 252 gpu::GPUInfo gpu_info; | 238 gpu::GPUInfo gpu_info; |
| 253 // Get vendor_id, device_id, driver_version from browser process through | 239 // Get vendor_id, device_id, driver_version from browser process through |
| 254 // commandline switches. | 240 // commandline switches. |
| 255 GetGpuInfoFromCommandLine(gpu_info, command_line); | 241 GetGpuInfoFromCommandLine(gpu_info, command_line); |
| 256 gpu_info.in_process_gpu = false; | 242 gpu_info.in_process_gpu = false; |
| 257 | 243 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 UMA_HISTOGRAM_TIMES("GPU.CollectContextGraphicsInfo", collect_context_time); | 325 UMA_HISTOGRAM_TIMES("GPU.CollectContextGraphicsInfo", collect_context_time); |
| 340 } else { // gl_initialized | 326 } else { // gl_initialized |
| 341 VLOG(1) << "gl::init::InitializeGLOneOff failed"; | 327 VLOG(1) << "gl::init::InitializeGLOneOff failed"; |
| 342 dead_on_arrival = true; | 328 dead_on_arrival = true; |
| 343 } | 329 } |
| 344 | 330 |
| 345 base::TimeDelta initialize_one_off_time = | 331 base::TimeDelta initialize_one_off_time = |
| 346 base::TimeTicks::Now() - before_initialize_one_off; | 332 base::TimeTicks::Now() - before_initialize_one_off; |
| 347 UMA_HISTOGRAM_MEDIUM_TIMES("GPU.InitializeOneOffMediumTime", | 333 UMA_HISTOGRAM_MEDIUM_TIMES("GPU.InitializeOneOffMediumTime", |
| 348 initialize_one_off_time); | 334 initialize_one_off_time); |
| 349 | 335 if (enable_watchdog && delayed_watchdog_enable) |
| 350 if (enable_watchdog && delayed_watchdog_enable) { | 336 watchdog_thread = gpu::GpuWatchdogThread::Create(); |
| 351 watchdog_thread = new GpuWatchdogThread(kGpuTimeout); | |
| 352 base::Thread::Options options; | |
| 353 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | |
| 354 watchdog_thread->StartWithOptions(options); | |
| 355 } | |
| 356 | 337 |
| 357 // OSMesa is expected to run very slowly, so disable the watchdog in that | 338 // OSMesa is expected to run very slowly, so disable the watchdog in that |
| 358 // case. | 339 // case. |
| 359 if (enable_watchdog && | 340 if (enable_watchdog && |
| 360 gl::GetGLImplementation() == gl::kGLImplementationOSMesaGL) { | 341 gl::GetGLImplementation() == gl::kGLImplementationOSMesaGL) { |
| 361 watchdog_thread->Stop(); | 342 watchdog_thread->Stop(); |
| 362 watchdog_thread = NULL; | 343 watchdog_thread = NULL; |
| 363 } | 344 } |
| 364 | 345 |
| 365 #if defined(OS_LINUX) | 346 #if defined(OS_LINUX) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 base::ThreadRestrictions::AssertIOAllowed(); | 493 base::ThreadRestrictions::AssertIOAllowed(); |
| 513 if (access("/dev/nvidiactl", R_OK) != 0) { | 494 if (access("/dev/nvidiactl", R_OK) != 0) { |
| 514 DVLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; | 495 DVLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; |
| 515 res = false; | 496 res = false; |
| 516 } | 497 } |
| 517 return res; | 498 return res; |
| 518 } | 499 } |
| 519 #endif | 500 #endif |
| 520 | 501 |
| 521 bool StartSandboxLinux(const gpu::GPUInfo& gpu_info, | 502 bool StartSandboxLinux(const gpu::GPUInfo& gpu_info, |
| 522 GpuWatchdogThread* watchdog_thread) { | 503 gpu::GpuWatchdogThread* watchdog_thread) { |
| 523 TRACE_EVENT0("gpu,startup", "Initialize sandbox"); | 504 TRACE_EVENT0("gpu,startup", "Initialize sandbox"); |
| 524 | 505 |
| 525 bool res = false; | 506 bool res = false; |
| 526 | 507 |
| 527 if (watchdog_thread) { | 508 if (watchdog_thread) { |
| 528 // LinuxSandbox needs to be able to ensure that the thread | 509 // LinuxSandbox needs to be able to ensure that the thread |
| 529 // has really been stopped. | 510 // has really been stopped. |
| 530 LinuxSandbox::StopThread(watchdog_thread); | 511 LinuxSandbox::StopThread(watchdog_thread); |
| 531 } | 512 } |
| 532 | 513 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return true; | 547 return true; |
| 567 } | 548 } |
| 568 | 549 |
| 569 return false; | 550 return false; |
| 570 } | 551 } |
| 571 #endif // defined(OS_WIN) | 552 #endif // defined(OS_WIN) |
| 572 | 553 |
| 573 } // namespace. | 554 } // namespace. |
| 574 | 555 |
| 575 } // namespace content | 556 } // namespace content |
| OLD | NEW |