Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: content/gpu/gpu_main.cc

Issue 2286063003: gpu: Move GpuWatchdogThread into //gpu/ipc/service from content. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool WarmUpSandbox(const base::CommandLine& command_line); 95 bool WarmUpSandbox(const base::CommandLine& command_line);
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*, bool); 105 bool StartSandboxLinux(const gpu::GPUInfo&, gpu::GpuWatchdogThread*, bool);
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
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } else { // gl_initialized 332 } else { // gl_initialized
347 VLOG(1) << "gl::init::InitializeGLOneOff failed"; 333 VLOG(1) << "gl::init::InitializeGLOneOff failed";
348 dead_on_arrival = true; 334 dead_on_arrival = true;
349 } 335 }
350 336
351 base::TimeDelta initialize_one_off_time = 337 base::TimeDelta initialize_one_off_time =
352 base::TimeTicks::Now() - before_initialize_one_off; 338 base::TimeTicks::Now() - before_initialize_one_off;
353 UMA_HISTOGRAM_MEDIUM_TIMES("GPU.InitializeOneOffMediumTime", 339 UMA_HISTOGRAM_MEDIUM_TIMES("GPU.InitializeOneOffMediumTime",
354 initialize_one_off_time); 340 initialize_one_off_time);
355 341
356 if (enable_watchdog && delayed_watchdog_enable) { 342 if (enable_watchdog && delayed_watchdog_enable) {
Fady Samuel 2016/08/29 16:41:37 nit: get rid of braces.
sadrul 2016/08/29 20:00:32 Done.
357 watchdog_thread = new GpuWatchdogThread(kGpuTimeout); 343 watchdog_thread = gpu::GpuWatchdogThread::Create();
358 base::Thread::Options options;
359 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
360 watchdog_thread->StartWithOptions(options);
361 } 344 }
362 345
363 // OSMesa is expected to run very slowly, so disable the watchdog in that 346 // OSMesa is expected to run very slowly, so disable the watchdog in that
364 // case. 347 // case.
365 if (enable_watchdog && 348 if (enable_watchdog &&
366 gl::GetGLImplementation() == gl::kGLImplementationOSMesaGL) { 349 gl::GetGLImplementation() == gl::kGLImplementationOSMesaGL) {
367 watchdog_thread->Stop(); 350 watchdog_thread->Stop();
368 watchdog_thread = NULL; 351 watchdog_thread = NULL;
369 } 352 }
370 353
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA. 547 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
565 gpu_info.driver_vendor == "NVIDIA") || 548 gpu_info.driver_vendor == "NVIDIA") ||
566 gpu_info.optimus; 549 gpu_info.optimus;
567 if (uses_nvidia_driver && should_initialize_gl_context) { 550 if (uses_nvidia_driver && should_initialize_gl_context) {
568 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0. 551 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
569 CreateDummyGlContext(); 552 CreateDummyGlContext();
570 } 553 }
571 } 554 }
572 555
573 bool StartSandboxLinux(const gpu::GPUInfo& gpu_info, 556 bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
574 GpuWatchdogThread* watchdog_thread, 557 gpu::GpuWatchdogThread* watchdog_thread,
575 bool should_initialize_gl_context) { 558 bool should_initialize_gl_context) {
576 TRACE_EVENT0("gpu,startup", "Initialize sandbox"); 559 TRACE_EVENT0("gpu,startup", "Initialize sandbox");
577 560
578 bool res = false; 561 bool res = false;
579 562
580 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context); 563 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
581 564
582 if (watchdog_thread) { 565 if (watchdog_thread) {
583 // LinuxSandbox needs to be able to ensure that the thread 566 // LinuxSandbox needs to be able to ensure that the thread
584 // has really been stopped. 567 // has really been stopped.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 return true; 604 return true;
622 } 605 }
623 606
624 return false; 607 return false;
625 } 608 }
626 #endif // defined(OS_WIN) 609 #endif // defined(OS_WIN)
627 610
628 } // namespace. 611 } // namespace.
629 612
630 } // namespace content 613 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698