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

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: Created 5 years, 11 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 #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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/power_monitor/power_monitor.h" 16 #include "base/power_monitor/power_monitor.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
20 #include "content/public/common/result_codes.h" 20 #include "content/public/common/result_codes.h"
21 21
22 #if defined(USE_X11)
23 extern "C" {
24 #include <X11/Xlib.h>
25 }
26 #include "ui/gfx/x/x11_types.h"
27 #endif
28
22 namespace content { 29 namespace content {
23 namespace { 30 namespace {
24 const int64 kCheckPeriodMs = 2000; 31 const int64 kCheckPeriodMs = 2000;
25 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
26 const base::FilePath::CharType 33 const base::FilePath::CharType
27 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active"); 34 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active");
28 #endif 35 #endif
29 } // namespace 36 } // namespace
30 37
31 GpuWatchdogThread::GpuWatchdogThread(int timeout) 38 GpuWatchdogThread::GpuWatchdogThread(int timeout)
32 : base::Thread("Watchdog"), 39 : base::Thread("Watchdog"),
33 watched_message_loop_(base::MessageLoop::current()), 40 watched_message_loop_(base::MessageLoop::current()),
34 timeout_(base::TimeDelta::FromMilliseconds(timeout)), 41 timeout_(base::TimeDelta::FromMilliseconds(timeout)),
35 armed_(false), 42 armed_(false),
36 #if defined(OS_WIN) 43 #if defined(OS_WIN)
37 watched_thread_handle_(0), 44 watched_thread_handle_(0),
38 arm_cpu_time_(), 45 arm_cpu_time_(),
39 #endif 46 #endif
40 task_observer_(this), 47 task_observer_(this),
41 suspended_(false), 48 suspended_(false),
49 #if defined(USE_X11)
50 x_server_active(true),
51 #endif
42 weak_factory_(this) { 52 weak_factory_(this) {
43 DCHECK(timeout >= 0); 53 DCHECK(timeout >= 0);
44 54
45 #if defined(OS_WIN) 55 #if defined(OS_WIN)
46 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread 56 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread
47 // to identify another. DuplicateHandle creates a "real" handle that can be 57 // to identify another. DuplicateHandle creates a "real" handle that can be
48 // used for this purpose. 58 // used for this purpose.
49 BOOL result = DuplicateHandle(GetCurrentProcess(), 59 BOOL result = DuplicateHandle(GetCurrentProcess(),
50 GetCurrentThread(), 60 GetCurrentThread(),
51 GetCurrentProcess(), 61 GetCurrentProcess(),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1); 187 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1);
178 suspension_timeout_ = base::Time::Now() + timeout * 2; 188 suspension_timeout_ = base::Time::Now() + timeout * 2;
179 189
180 // Post a task to the monitored thread that does nothing but wake up the 190 // 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 191 // 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. 192 // also wake up the observer. This simply ensures there is at least one.
183 watched_message_loop_->PostTask( 193 watched_message_loop_->PostTask(
184 FROM_HERE, 194 FROM_HERE,
185 base::Bind(&base::DoNothing)); 195 base::Bind(&base::DoNothing));
186 196
187 // Post a task to the watchdog thread to exit if the monitored thread does 197 #if defined(USE_X11)
188 // not respond in time. 198 // Post a task to the watchdog thread to check XServer is active
189 message_loop()->PostDelayedTask( 199 // if the monitored thread does not respond in time.
190 FROM_HERE, 200 if (x_server_active) {
191 base::Bind( 201 message_loop()->PostDelayedTask(
192 &GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang, 202 FROM_HERE, base::Bind(&GpuWatchdogThread::CheckXServerActive,
193 weak_factory_.GetWeakPtr()), 203 weak_factory_.GetWeakPtr()),
194 timeout); 204 timeout);
205 } else
206 #endif
207 {
208 // Post a task to the watchdog thread to exit if the monitored thread does
209 // not respond in time.
210 message_loop()->PostDelayedTask(
211 FROM_HERE,
212 base::Bind(&GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang,
213 weak_factory_.GetWeakPtr()),
214 timeout);
215 }
195 } 216 }
196 217
197 // Use the --disable-gpu-watchdog command line switch to disable this. 218 // Use the --disable-gpu-watchdog command line switch to disable this.
198 void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() { 219 void GpuWatchdogThread::DeliberatelyTerminateToRecoverFromHang() {
199 // Should not get here while the system is suspended. 220 // Should not get here while the system is suspended.
200 DCHECK(!suspended_); 221 DCHECK(!suspended_);
201 222
202 #if defined(OS_WIN) 223 #if defined(OS_WIN)
203 // Defer termination until a certain amount of CPU time has elapsed on the 224 // Defer termination until a certain amount of CPU time has elapsed on the
204 // watched thread. 225 // watched thread.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 273
253 LOG(ERROR) << "The GPU process hung. Terminating after " 274 LOG(ERROR) << "The GPU process hung. Terminating after "
254 << timeout_.InMilliseconds() << " ms."; 275 << timeout_.InMilliseconds() << " ms.";
255 276
256 // Deliberately crash the process to create a crash dump. 277 // Deliberately crash the process to create a crash dump.
257 *((volatile int*)0) = 0x1337; 278 *((volatile int*)0) = 0x1337;
258 279
259 terminated = true; 280 terminated = true;
260 } 281 }
261 282
283 #if defined(USE_X11)
284 void GpuWatchdogThread::CheckXServerActive() {
285 if (!XDisplayString(gfx::GetXDisplay())) {
danakj 2015/01/06 00:29:19 What does this do if the X server is not the activ
sohanjg 2015/01/06 12:21:45 Hmm..i was assuming this would return NULL in that
286 x_server_active = false;
287 timeout_ /= 2;
288 } else {
289 x_server_active = true;
290 }
291 }
292 #endif
262 void GpuWatchdogThread::AddPowerObserver() { 293 void GpuWatchdogThread::AddPowerObserver() {
263 message_loop()->PostTask( 294 message_loop()->PostTask(
264 FROM_HERE, 295 FROM_HERE,
265 base::Bind(&GpuWatchdogThread::OnAddPowerObserver, this)); 296 base::Bind(&GpuWatchdogThread::OnAddPowerObserver, this));
266 } 297 }
267 298
268 void GpuWatchdogThread::OnAddPowerObserver() { 299 void GpuWatchdogThread::OnAddPowerObserver() {
269 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 300 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
270 DCHECK(power_monitor); 301 DCHECK(power_monitor);
271 power_monitor->AddObserver(this); 302 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 345 // not increasing. The other is where either the kernel hangs and never
315 // returns to user level or where user level code 346 // returns to user level or where user level code
316 // calls into kernel level repeatedly, giving up its quanta before it is 347 // calls into kernel level repeatedly, giving up its quanta before it is
317 // tracked, for example a loop that repeatedly Sleeps. 348 // tracked, for example a loop that repeatedly Sleeps.
318 return base::TimeDelta::FromMilliseconds(static_cast<int64>( 349 return base::TimeDelta::FromMilliseconds(static_cast<int64>(
319 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); 350 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000));
320 } 351 }
321 #endif 352 #endif
322 353
323 } // namespace content 354 } // namespace content
OLDNEW
« content/gpu/gpu_watchdog_thread.h ('K') | « content/gpu/gpu_watchdog_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698