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

Side by Side Diff: gpu/ipc/service/gpu_watchdog_thread.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 "content/gpu/gpu_watchdog_thread.h" 5 #include "gpu/ipc/service/gpu_watchdog_thread.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/debug/alias.h" 14 #include "base/debug/alias.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/power_monitor/power_monitor.h" 18 #include "base/power_monitor/power_monitor.h"
19 #include "base/process/process.h" 19 #include "base/process/process.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/threading/platform_thread.h" 21 #include "base/threading/platform_thread.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/result_codes.h"
25 23
26 #if defined(OS_WIN) 24 #if defined(OS_WIN)
27 #include <windows.h> 25 #include <windows.h>
28 #endif 26 #endif
29 27
30 namespace content { 28 namespace gpu {
31 namespace { 29 namespace {
30
31 #if defined(CYGPROFILE_INSTRUMENTATION)
32 const int kGpuTimeout = 30000;
33 #elif defined(OS_WIN)
34 // Use a slightly longer timeout on Windows due to prevalence of slow and
35 // infected machines.
36 const int kGpuTimeout = 15000;
37 #else
38 const int kGpuTimeout = 10000;
39 #endif
40
32 #if defined(USE_X11) 41 #if defined(USE_X11)
33 const base::FilePath::CharType 42 const base::FilePath::CharType kTtyFilePath[] =
34 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active"); 43 FILE_PATH_LITERAL("/sys/class/tty/tty0/active");
35 const unsigned char text[20] = "check"; 44 const unsigned char text[20] = "check";
36 #endif 45 #endif
46
37 } // namespace 47 } // namespace
38 48
39 GpuWatchdogThread::GpuWatchdogThread(int timeout) 49 GpuWatchdogThread::GpuWatchdogThread()
40 : base::Thread("Watchdog"), 50 : base::Thread("Watchdog"),
41 watched_message_loop_(base::MessageLoop::current()), 51 watched_message_loop_(base::MessageLoop::current()),
42 timeout_(base::TimeDelta::FromMilliseconds(timeout)), 52 timeout_(base::TimeDelta::FromMilliseconds(kGpuTimeout)),
43 armed_(false), 53 armed_(false),
44 task_observer_(this), 54 task_observer_(this),
45 use_thread_cpu_time_(true), 55 use_thread_cpu_time_(true),
46 responsive_acknowledge_count_(0), 56 responsive_acknowledge_count_(0),
47 #if defined(OS_WIN) 57 #if defined(OS_WIN)
48 watched_thread_handle_(0), 58 watched_thread_handle_(0),
49 arm_cpu_time_(), 59 arm_cpu_time_(),
50 #endif 60 #endif
51 suspended_(false), 61 suspended_(false),
52 #if defined(USE_X11) 62 #if defined(USE_X11)
53 display_(NULL), 63 display_(NULL),
54 window_(0), 64 window_(0),
55 atom_(None), 65 atom_(None),
56 host_tty_(-1), 66 host_tty_(-1),
57 #endif 67 #endif
58 weak_factory_(this) { 68 weak_factory_(this) {
59 DCHECK(timeout >= 0);
60
61 #if defined(OS_WIN) 69 #if defined(OS_WIN)
62 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread 70 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread
63 // to identify another. DuplicateHandle creates a "real" handle that can be 71 // to identify another. DuplicateHandle creates a "real" handle that can be
64 // used for this purpose. 72 // used for this purpose.
65 BOOL result = DuplicateHandle(GetCurrentProcess(), 73 BOOL result = DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
66 GetCurrentThread(), 74 GetCurrentProcess(), &watched_thread_handle_,
67 GetCurrentProcess(), 75 THREAD_QUERY_INFORMATION, FALSE, 0);
68 &watched_thread_handle_,
69 THREAD_QUERY_INFORMATION,
70 FALSE,
71 0);
72 DCHECK(result); 76 DCHECK(result);
73 #endif 77 #endif
74 78
75 #if defined(USE_X11) 79 #if defined(USE_X11)
76 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r"); 80 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r");
77 SetupXServer(); 81 SetupXServer();
78 #endif 82 #endif
79 watched_message_loop_->AddTaskObserver(&task_observer_); 83 watched_message_loop_->AddTaskObserver(&task_observer_);
80 } 84 }
81 85
86 // static
87 scoped_refptr<GpuWatchdogThread> GpuWatchdogThread::Create() {
88 scoped_refptr<GpuWatchdogThread> watchdog_thread = new GpuWatchdogThread();
89 base::Thread::Options options;
90 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
91 watchdog_thread->StartWithOptions(options);
92 return watchdog_thread;
93 }
94
82 void GpuWatchdogThread::PostAcknowledge() { 95 void GpuWatchdogThread::PostAcknowledge() {
83 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use 96 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use
84 // the method factory. Rely on reference counting instead. 97 // the method factory. Rely on reference counting instead.
85 task_runner()->PostTask(FROM_HERE, 98 task_runner()->PostTask(FROM_HERE,
86 base::Bind(&GpuWatchdogThread::OnAcknowledge, this)); 99 base::Bind(&GpuWatchdogThread::OnAcknowledge, this));
87 } 100 }
88 101
89 void GpuWatchdogThread::CheckArmed() { 102 void GpuWatchdogThread::CheckArmed() {
90 // Acknowledge the watchdog if it has armed itself. The watchdog will not 103 // Acknowledge the watchdog if it has armed itself. The watchdog will not
91 // change its armed state until it is acknowledged. 104 // change its armed state until it is acknowledged.
92 if (armed()) { 105 if (armed()) {
93 PostAcknowledge(); 106 PostAcknowledge();
94 } 107 }
95 } 108 }
96 109
97 void GpuWatchdogThread::Init() { 110 void GpuWatchdogThread::Init() {
98 // Schedule the first check. 111 // Schedule the first check.
99 OnCheck(false); 112 OnCheck(false);
100 } 113 }
101 114
102 void GpuWatchdogThread::CleanUp() { 115 void GpuWatchdogThread::CleanUp() {
103 weak_factory_.InvalidateWeakPtrs(); 116 weak_factory_.InvalidateWeakPtrs();
104 } 117 }
105 118
106 GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver( 119 GpuWatchdogThread::GpuWatchdogTaskObserver::GpuWatchdogTaskObserver(
107 GpuWatchdogThread* watchdog) 120 GpuWatchdogThread* watchdog)
108 : watchdog_(watchdog) { 121 : watchdog_(watchdog) {}
109 }
110 122
111 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() { 123 GpuWatchdogThread::GpuWatchdogTaskObserver::~GpuWatchdogTaskObserver() {}
112 }
113 124
114 void GpuWatchdogThread::GpuWatchdogTaskObserver::WillProcessTask( 125 void GpuWatchdogThread::GpuWatchdogTaskObserver::WillProcessTask(
115 const base::PendingTask& pending_task) { 126 const base::PendingTask& pending_task) {
116 watchdog_->CheckArmed(); 127 watchdog_->CheckArmed();
117 } 128 }
118 129
119 void GpuWatchdogThread::GpuWatchdogTaskObserver::DidProcessTask( 130 void GpuWatchdogThread::GpuWatchdogTaskObserver::DidProcessTask(
120 const base::PendingTask& pending_task) { 131 const base::PendingTask& pending_task) {}
121 }
122 132
123 GpuWatchdogThread::~GpuWatchdogThread() { 133 GpuWatchdogThread::~GpuWatchdogThread() {
124 // Verify that the thread was explicitly stopped. If the thread is stopped 134 // Verify that the thread was explicitly stopped. If the thread is stopped
125 // implicitly by the destructor, CleanUp() will not be called. 135 // implicitly by the destructor, CleanUp() will not be called.
126 DCHECK(!weak_factory_.HasWeakPtrs()); 136 DCHECK(!weak_factory_.HasWeakPtrs());
127 137
128 #if defined(OS_WIN) 138 #if defined(OS_WIN)
129 CloseHandle(watched_thread_handle_); 139 CloseHandle(watched_thread_handle_);
130 #endif 140 #endif
131 141
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 return; 324 return;
315 325
316 #if defined(OS_WIN) 326 #if defined(OS_WIN)
317 if (IsDebuggerPresent()) 327 if (IsDebuggerPresent())
318 return; 328 return;
319 #endif 329 #endif
320 330
321 #if defined(USE_X11) 331 #if defined(USE_X11)
322 // Don't crash if we're not on the TTY of our host X11 server. 332 // Don't crash if we're not on the TTY of our host X11 server.
323 int active_tty = GetActiveTTY(); 333 int active_tty = GetActiveTTY();
324 if(host_tty_ != -1 && active_tty != -1 && host_tty_ != active_tty) { 334 if (host_tty_ != -1 && active_tty != -1 && host_tty_ != active_tty) {
325 return; 335 return;
326 } 336 }
327 #endif 337 #endif
328 338
329 // Store variables so they're available in crash dumps to help determine the 339 // Store variables so they're available in crash dumps to help determine the
330 // cause of any hang. 340 // cause of any hang.
331 #if defined(OS_WIN) 341 #if defined(OS_WIN)
332 ULONGLONG fire_interrupt_time; 342 ULONGLONG fire_interrupt_time;
333 QueryUnbiasedInterruptTime(&fire_interrupt_time); 343 QueryUnbiasedInterruptTime(&fire_interrupt_time);
334 344
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 fread(tty_string, 1, 7, tty_file_)) { 472 fread(tty_string, 1, 7, tty_file_)) {
463 int tty_number; 473 int tty_number;
464 size_t num_res = sscanf(tty_string, "tty%d\n", &tty_number); 474 size_t num_res = sscanf(tty_string, "tty%d\n", &tty_number);
465 if (num_res == 1) 475 if (num_res == 1)
466 return tty_number; 476 return tty_number;
467 } 477 }
468 return -1; 478 return -1;
469 } 479 }
470 #endif 480 #endif
471 481
472 } // namespace content 482 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698