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

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

Issue 836473003: Avoid gpu watchdog crash on timeout if X is un-responsive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: create new display and explicitly catch change in prop in watchdog thread. Created 5 years, 10 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
« no previous file with comments | « content/gpu/gpu_watchdog_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(OS_WIN) 5 #if defined(OS_WIN)
6 #include <windows.h> 6 #include <windows.h>
7 #endif 7 #endif
8 8
9 #include "content/gpu/gpu_watchdog_thread.h" 9 #include "content/gpu/gpu_watchdog_thread.h"
10 10
(...skipping 21 matching lines...) Expand all
32 : base::Thread("Watchdog"), 32 : base::Thread("Watchdog"),
33 watched_message_loop_(base::MessageLoop::current()), 33 watched_message_loop_(base::MessageLoop::current()),
34 timeout_(base::TimeDelta::FromMilliseconds(timeout)), 34 timeout_(base::TimeDelta::FromMilliseconds(timeout)),
35 armed_(false), 35 armed_(false),
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 watched_thread_handle_(0), 37 watched_thread_handle_(0),
38 arm_cpu_time_(), 38 arm_cpu_time_(),
39 #endif 39 #endif
40 task_observer_(this), 40 task_observer_(this),
41 suspended_(false), 41 suspended_(false),
42 #if defined(USE_X11)
43 x_server_active_(true),
44 display_(NULL),
45 window_(1),
piman 2015/02/04 01:03:05 why 1?
sohanjg 2015/02/06 10:40:58 Done.
46 atom_(None),
47 #endif
42 weak_factory_(this) { 48 weak_factory_(this) {
43 DCHECK(timeout >= 0); 49 DCHECK(timeout >= 0);
44 50
45 #if defined(OS_WIN) 51 #if defined(OS_WIN)
46 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread 52 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread
47 // to identify another. DuplicateHandle creates a "real" handle that can be 53 // to identify another. DuplicateHandle creates a "real" handle that can be
48 // used for this purpose. 54 // used for this purpose.
49 BOOL result = DuplicateHandle(GetCurrentProcess(), 55 BOOL result = DuplicateHandle(GetCurrentProcess(),
50 GetCurrentThread(), 56 GetCurrentThread(),
51 GetCurrentProcess(), 57 GetCurrentProcess(),
52 &watched_thread_handle_, 58 &watched_thread_handle_,
53 THREAD_QUERY_INFORMATION, 59 THREAD_QUERY_INFORMATION,
54 FALSE, 60 FALSE,
55 0); 61 0);
56 DCHECK(result); 62 DCHECK(result);
57 #endif 63 #endif
58 64
59 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
60 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r"); 66 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r");
61 #endif 67 #endif
68 #if defined(USE_X11)
69 SetupXServer();
70 #endif
62 watched_message_loop_->AddTaskObserver(&task_observer_); 71 watched_message_loop_->AddTaskObserver(&task_observer_);
63 } 72 }
64 73
65 void GpuWatchdogThread::PostAcknowledge() { 74 void GpuWatchdogThread::PostAcknowledge() {
66 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use 75 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use
67 // the method factory. Rely on reference counting instead. 76 // the method factory. Rely on reference counting instead.
68 message_loop()->PostTask( 77 message_loop()->PostTask(
69 FROM_HERE, 78 FROM_HERE,
70 base::Bind(&GpuWatchdogThread::OnAcknowledge, this)); 79 base::Bind(&GpuWatchdogThread::OnAcknowledge, this));
71 } 80 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1); 186 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1);
178 suspension_timeout_ = base::Time::Now() + timeout * 2; 187 suspension_timeout_ = base::Time::Now() + timeout * 2;
179 188
180 // Post a task to the monitored thread that does nothing but wake up the 189 // Post a task to the monitored thread that does nothing but wake up the
181 // TaskObserver. Any other tasks that are pending on the watched thread will 190 // TaskObserver. Any other tasks that are pending on the watched thread will
182 // also wake up the observer. This simply ensures there is at least one. 191 // also wake up the observer. This simply ensures there is at least one.
183 watched_message_loop_->PostTask( 192 watched_message_loop_->PostTask(
184 FROM_HERE, 193 FROM_HERE,
185 base::Bind(&base::DoNothing)); 194 base::Bind(&base::DoNothing));
186 195
187 // Post a task to the watchdog thread to exit if the monitored thread does 196 #if defined(USE_X11)
188 // not respond in time. 197 // Post a task to the watchdog thread to check XServer is active
198 // if the monitored thread does not respond in time.
199 SetupXChangeProp();
189 message_loop()->PostDelayedTask( 200 message_loop()->PostDelayedTask(
sohanjg 2015/02/02 14:17:19 Should we post a delayed task here, or explicitly
190 FROM_HERE, 201 FROM_HERE, base::Bind(&GpuWatchdogThread::CheckXServerActive,
191 base::Bind( 202 weak_factory_.GetWeakPtr()),
192 &GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang,
193 weak_factory_.GetWeakPtr()),
194 timeout); 203 timeout);
204 if (!x_server_active_)
205 #endif
206 {
207 // Post a task to the watchdog thread to exit if the monitored thread does
208 // not respond in time.
209 message_loop()->PostDelayedTask(
210 FROM_HERE,
211 base::Bind(&GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang,
212 weak_factory_.GetWeakPtr()),
213 timeout);
214 }
195 } 215 }
196 216
197 // Use the --disable-gpu-watchdog command line switch to disable this. 217 // Use the --disable-gpu-watchdog command line switch to disable this.
198 void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() { 218 void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() {
199 // Should not get here while the system is suspended. 219 // Should not get here while the system is suspended.
200 DCHECK(!suspended_); 220 DCHECK(!suspended_);
201 221
202 #if defined(OS_WIN) 222 #if defined(OS_WIN)
203 // Defer termination until a certain amount of CPU time has elapsed on the 223 // Defer termination until a certain amount of CPU time has elapsed on the
204 // watched thread. 224 // watched thread.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 272
253 LOG(ERROR) << "The GPU process hung. Terminating after " 273 LOG(ERROR) << "The GPU process hung. Terminating after "
254 << timeout_.InMilliseconds() << " ms."; 274 << timeout_.InMilliseconds() << " ms.";
255 275
256 // Deliberately crash the process to create a crash dump. 276 // Deliberately crash the process to create a crash dump.
257 *((volatile int*)0) = 0x1337; 277 *((volatile int*)0) = 0x1337;
258 278
259 terminated = true; 279 terminated = true;
260 } 280 }
261 281
282 #if defined(USE_X11)
283 void GpuWatchdogThread::CheckXServerActive() {
284 unsigned long nitems = 0;
285 unsigned long nbytes = 0;
286 XAtom prop_type = None;
287 int prop_format = 0;
288 unsigned char* property_data = NULL;
289 if (XGetWindowProperty(display_, window_, atom_, 0, 65535, False,
290 AnyPropertyType, &prop_type, &prop_format, &nitems,
291 &nbytes, &property_data) == Success) {
piman 2015/02/04 01:03:05 If X is blocked, this will block. I don't think th
sohanjg 2015/02/06 10:40:58 Done.
292 if (prop_type == XA_STRING && prop_format == 8 && nitems == 5) {
293 x_server_active_ = true;
294 return;
295 }
296 }
297 x_server_active_ = false;
298 }
299
300 void GpuWatchdogThread::SetupXServer() {
301 display_ = XOpenDisplay(NULL);
302 window_ = XCreateWindow(display_, DefaultRootWindow(display_), 0, 0, 1, 1, 0,
303 CopyFromParent, InputOutput, CopyFromParent, 0, NULL);
304 }
305
306 void GpuWatchdogThread::SetupXChangeProp() {
307 unsigned char text[20] = "check";
308 atom_ = XInternAtom(display_, "CHK", False);
309 XChangeProperty(display_, window_, atom_, XA_STRING, 8, PropModeReplace, text,
310 5);
311 }
312 #endif
262 void GpuWatchdogThread::AddPowerObserver() { 313 void GpuWatchdogThread::AddPowerObserver() {
263 message_loop()->PostTask( 314 message_loop()->PostTask(
264 FROM_HERE, 315 FROM_HERE,
265 base::Bind(&GpuWatchdogThread::OnAddPowerObserver, this)); 316 base::Bind(&GpuWatchdogThread::OnAddPowerObserver, this));
266 } 317 }
267 318
268 void GpuWatchdogThread::OnAddPowerObserver() { 319 void GpuWatchdogThread::OnAddPowerObserver() {
269 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 320 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
270 DCHECK(power_monitor); 321 DCHECK(power_monitor);
271 power_monitor->AddObserver(this); 322 power_monitor->AddObserver(this);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // not increasing. The other is where either the kernel hangs and never 365 // not increasing. The other is where either the kernel hangs and never
315 // returns to user level or where user level code 366 // returns to user level or where user level code
316 // calls into kernel level repeatedly, giving up its quanta before it is 367 // calls into kernel level repeatedly, giving up its quanta before it is
317 // tracked, for example a loop that repeatedly Sleeps. 368 // tracked, for example a loop that repeatedly Sleeps.
318 return base::TimeDelta::FromMilliseconds(static_cast<int64>( 369 return base::TimeDelta::FromMilliseconds(static_cast<int64>(
319 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); 370 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000));
320 } 371 }
321 #endif 372 #endif
322 373
323 } // namespace content 374 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/gpu_watchdog_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698