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

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

Issue 1991353002: Don't restart the GPU process when switching to another TTY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't exit the GPU process if on a non-host TTY Created 4 years, 7 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 #include "content/gpu/gpu_watchdog_thread.h" 5 #include "content/gpu/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"
(...skipping 11 matching lines...) Expand all
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/result_codes.h" 24 #include "content/public/common/result_codes.h"
25 25
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 #include <windows.h> 27 #include <windows.h>
28 #endif 28 #endif
29 29
30 namespace content { 30 namespace content {
31 namespace { 31 namespace {
32 #if defined(OS_CHROMEOS) 32 #if defined(USE_X11)
33 const base::FilePath::CharType 33 const base::FilePath::CharType
34 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active"); 34 kTtyFilePath[] = FILE_PATH_LITERAL("/sys/class/tty/tty0/active");
35 #endif
36 #if defined(USE_X11)
37 const unsigned char text[20] = "check"; 35 const unsigned char text[20] = "check";
38 #endif 36 #endif
39 } // namespace 37 } // namespace
40 38
41 GpuWatchdogThread::GpuWatchdogThread(int timeout) 39 GpuWatchdogThread::GpuWatchdogThread(int timeout)
42 : base::Thread("Watchdog"), 40 : base::Thread("Watchdog"),
43 watched_message_loop_(base::MessageLoop::current()), 41 watched_message_loop_(base::MessageLoop::current()),
44 timeout_(base::TimeDelta::FromMilliseconds(timeout)), 42 timeout_(base::TimeDelta::FromMilliseconds(timeout)),
45 armed_(false), 43 armed_(false),
46 task_observer_(this), 44 task_observer_(this),
47 use_thread_cpu_time_(true), 45 use_thread_cpu_time_(true),
48 responsive_acknowledge_count_(0), 46 responsive_acknowledge_count_(0),
49 #if defined(OS_WIN) 47 #if defined(OS_WIN)
50 watched_thread_handle_(0), 48 watched_thread_handle_(0),
51 arm_cpu_time_(), 49 arm_cpu_time_(),
52 #endif 50 #endif
53 suspended_(false), 51 suspended_(false),
54 #if defined(USE_X11) 52 #if defined(USE_X11)
55 display_(NULL), 53 display_(NULL),
56 window_(0), 54 window_(0),
57 atom_(None), 55 atom_(None),
56 host_tty_(-1),
58 #endif 57 #endif
59 weak_factory_(this) { 58 weak_factory_(this) {
60 DCHECK(timeout >= 0); 59 DCHECK(timeout >= 0);
61 60
62 #if defined(OS_WIN) 61 #if defined(OS_WIN)
63 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread 62 // GetCurrentThread returns a pseudo-handle that cannot be used by one thread
64 // to identify another. DuplicateHandle creates a "real" handle that can be 63 // to identify another. DuplicateHandle creates a "real" handle that can be
65 // used for this purpose. 64 // used for this purpose.
66 BOOL result = DuplicateHandle(GetCurrentProcess(), 65 BOOL result = DuplicateHandle(GetCurrentProcess(),
67 GetCurrentThread(), 66 GetCurrentThread(),
68 GetCurrentProcess(), 67 GetCurrentProcess(),
69 &watched_thread_handle_, 68 &watched_thread_handle_,
70 THREAD_QUERY_INFORMATION, 69 THREAD_QUERY_INFORMATION,
71 FALSE, 70 FALSE,
72 0); 71 0);
73 DCHECK(result); 72 DCHECK(result);
74 #endif 73 #endif
75 74
76 #if defined(OS_CHROMEOS) 75 #if defined(USE_X11)
77 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r"); 76 tty_file_ = base::OpenFile(base::FilePath(kTtyFilePath), "r");
78 #endif
79 #if defined(USE_X11)
80 SetupXServer(); 77 SetupXServer();
81 #endif 78 #endif
82 watched_message_loop_->AddTaskObserver(&task_observer_); 79 watched_message_loop_->AddTaskObserver(&task_observer_);
83 } 80 }
84 81
85 void GpuWatchdogThread::PostAcknowledge() { 82 void GpuWatchdogThread::PostAcknowledge() {
86 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use 83 // Called on the monitored thread. Responds with OnAcknowledge. Cannot use
87 // the method factory. Rely on reference counting instead. 84 // the method factory. Rely on reference counting instead.
88 task_runner()->PostTask(FROM_HERE, 85 task_runner()->PostTask(FROM_HERE,
89 base::Bind(&GpuWatchdogThread::OnAcknowledge, this)); 86 base::Bind(&GpuWatchdogThread::OnAcknowledge, this));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 DCHECK(!weak_factory_.HasWeakPtrs()); 126 DCHECK(!weak_factory_.HasWeakPtrs());
130 127
131 #if defined(OS_WIN) 128 #if defined(OS_WIN)
132 CloseHandle(watched_thread_handle_); 129 CloseHandle(watched_thread_handle_);
133 #endif 130 #endif
134 131
135 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); 132 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
136 if (power_monitor) 133 if (power_monitor)
137 power_monitor->RemoveObserver(this); 134 power_monitor->RemoveObserver(this);
138 135
139 #if defined(OS_CHROMEOS) 136 #if defined(USE_X11)
140 if (tty_file_) 137 if (tty_file_)
141 fclose(tty_file_); 138 fclose(tty_file_);
142 #endif
143
144 #if defined(USE_X11)
145 XDestroyWindow(display_, window_); 139 XDestroyWindow(display_, window_);
146 XCloseDisplay(display_); 140 XCloseDisplay(display_);
147 #endif 141 #endif
148 142
149 watched_message_loop_->RemoveTaskObserver(&task_observer_); 143 watched_message_loop_->RemoveTaskObserver(&task_observer_);
150 } 144 }
151 145
152 void GpuWatchdogThread::OnAcknowledge() { 146 void GpuWatchdogThread::OnAcknowledge() {
153 CHECK(base::PlatformThread::CurrentId() == GetThreadId()); 147 CHECK(base::PlatformThread::CurrentId() == GetThreadId());
154 148
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // useful. 312 // useful.
319 static bool terminated = false; 313 static bool terminated = false;
320 if (terminated) 314 if (terminated)
321 return; 315 return;
322 316
323 #if defined(OS_WIN) 317 #if defined(OS_WIN)
324 if (IsDebuggerPresent()) 318 if (IsDebuggerPresent())
325 return; 319 return;
326 #endif 320 #endif
327 321
328 #if defined(OS_CHROMEOS) 322 #if defined(USE_X11)
329 // Don't crash if we're not on tty1. This avoids noise in the GPU process 323 // Don't crash if we're not on the TTY of our host X11 server.
330 // crashes caused by people who use VT2 but still enable crash reporting. 324 int active_tty = GetActiveTTY();
331 char tty_string[8] = {0}; 325 if(host_tty_ != -1 && active_tty != -1 && host_tty_ != active_tty) {
332 if (tty_file_ && 326 return;
333 !fseek(tty_file_, 0, SEEK_SET) &&
334 fread(tty_string, 1, 7, tty_file_)) {
335 int tty_number = -1;
336 int num_res = sscanf(tty_string, "tty%d", &tty_number);
337 if (num_res == 1 && tty_number != 1)
338 return;
339 } 327 }
340 #endif 328 #endif
341 329
342 // Store variables so they're available in crash dumps to help determine the 330 // Store variables so they're available in crash dumps to help determine the
343 // cause of any hang. 331 // cause of any hang.
344 #if defined(OS_WIN) 332 #if defined(OS_WIN)
345 ULONGLONG fire_interrupt_time; 333 ULONGLONG fire_interrupt_time;
346 QueryUnbiasedInterruptTime(&fire_interrupt_time); 334 QueryUnbiasedInterruptTime(&fire_interrupt_time);
347 335
348 // This is the time since the watchdog was armed, in 100ns intervals, 336 // This is the time since the watchdog was armed, in 100ns intervals,
(...skipping 24 matching lines...) Expand all
373 361
374 terminated = true; 362 terminated = true;
375 } 363 }
376 364
377 #if defined(USE_X11) 365 #if defined(USE_X11)
378 void GpuWatchdogThread::SetupXServer() { 366 void GpuWatchdogThread::SetupXServer() {
379 display_ = XOpenDisplay(NULL); 367 display_ = XOpenDisplay(NULL);
380 window_ = XCreateWindow(display_, DefaultRootWindow(display_), 0, 0, 1, 1, 0, 368 window_ = XCreateWindow(display_, DefaultRootWindow(display_), 0, 0, 1, 1, 0,
381 CopyFromParent, InputOutput, CopyFromParent, 0, NULL); 369 CopyFromParent, InputOutput, CopyFromParent, 0, NULL);
382 atom_ = XInternAtom(display_, "CHECK", False); 370 atom_ = XInternAtom(display_, "CHECK", False);
371 host_tty_ = GetActiveTTY();
383 } 372 }
384 373
385 void GpuWatchdogThread::SetupXChangeProp() { 374 void GpuWatchdogThread::SetupXChangeProp() {
386 XChangeProperty(display_, window_, atom_, XA_STRING, 8, PropModeReplace, text, 375 XChangeProperty(display_, window_, atom_, XA_STRING, 8, PropModeReplace, text,
387 (arraysize(text) - 1)); 376 (arraysize(text) - 1));
388 } 377 }
389 378
390 bool GpuWatchdogThread::MatchXEventAtom(XEvent* event) { 379 bool GpuWatchdogThread::MatchXEventAtom(XEvent* event) {
391 if (event->xproperty.window == window_ && event->type == PropertyNotify && 380 if (event->xproperty.window == window_ && event->type == PropertyNotify &&
392 event->xproperty.atom == atom_) 381 event->xproperty.atom == atom_)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // returns to user level or where user level code 445 // returns to user level or where user level code
457 // calls into kernel level repeatedly, giving up its quanta before it is 446 // calls into kernel level repeatedly, giving up its quanta before it is
458 // tracked, for example a loop that repeatedly Sleeps. 447 // tracked, for example a loop that repeatedly Sleeps.
459 return base::ThreadTicks() + 448 return base::ThreadTicks() +
460 base::TimeDelta::FromMilliseconds(static_cast<int64_t>( 449 base::TimeDelta::FromMilliseconds(static_cast<int64_t>(
461 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); 450 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000));
462 } 451 }
463 } 452 }
464 #endif 453 #endif
465 454
455 #if defined(USE_X11)
456 int GpuWatchdogThread::GetActiveTTY() const {
457 char tty_string[8] = {0};
458 if (tty_file_ && !fseek(tty_file_, 0, SEEK_SET) &&
459 fread(tty_string, 1, 7, tty_file_)) {
460 int tty_number;
461 size_t num_res = sscanf(tty_string, "tty%d\n", &tty_number);
462 if (num_res == 1)
463 return tty_number;
464 }
465 return -1;
466 }
467 #endif
468
466 } // namespace content 469 } // 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