| OLD | NEW |
| 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" |
| 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/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/power_monitor/power_monitor.h" | 18 #include "base/power_monitor/power_monitor.h" |
| 18 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
| 23 | 24 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (armed_ || suspended_) | 202 if (armed_ || suspended_) |
| 202 return; | 203 return; |
| 203 | 204 |
| 204 // Must set armed before posting the task. This task might be the only task | 205 // Must set armed before posting the task. This task might be the only task |
| 205 // that will activate the TaskObserver on the watched thread and it must not | 206 // that will activate the TaskObserver on the watched thread and it must not |
| 206 // miss the false -> true transition. | 207 // miss the false -> true transition. |
| 207 armed_ = true; | 208 armed_ = true; |
| 208 | 209 |
| 209 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
| 210 arm_cpu_time_ = GetWatchedThreadTime(); | 211 arm_cpu_time_ = GetWatchedThreadTime(); |
| 212 |
| 213 QueryUnbiasedInterruptTime(&arm_interrupt_time_); |
| 211 #endif | 214 #endif |
| 212 | 215 |
| 213 check_time_ = base::Time::Now(); | 216 check_time_ = base::Time::Now(); |
| 217 check_timeticks_ = base::TimeTicks::Now(); |
| 214 // Immediately after the computer is woken up from being suspended it might | 218 // Immediately after the computer is woken up from being suspended it might |
| 215 // be pretty sluggish, so allow some extra time before the next timeout. | 219 // be pretty sluggish, so allow some extra time before the next timeout. |
| 216 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1); | 220 base::TimeDelta timeout = timeout_ * (after_suspend ? 3 : 1); |
| 217 suspension_timeout_ = check_time_ + timeout * 2; | 221 suspension_timeout_ = check_time_ + timeout * 2; |
| 218 | 222 |
| 219 // Post a task to the monitored thread that does nothing but wake up the | 223 // Post a task to the monitored thread that does nothing but wake up the |
| 220 // TaskObserver. Any other tasks that are pending on the watched thread will | 224 // TaskObserver. Any other tasks that are pending on the watched thread will |
| 221 // also wake up the observer. This simply ensures there is at least one. | 225 // also wake up the observer. This simply ensures there is at least one. |
| 222 watched_message_loop_->task_runner()->PostTask(FROM_HERE, | 226 watched_message_loop_->task_runner()->PostTask(FROM_HERE, |
| 223 base::Bind(&base::DoNothing)); | 227 base::Bind(&base::DoNothing)); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (tty_file_ && | 330 if (tty_file_ && |
| 327 !fseek(tty_file_, 0, SEEK_SET) && | 331 !fseek(tty_file_, 0, SEEK_SET) && |
| 328 fread(tty_string, 1, 7, tty_file_)) { | 332 fread(tty_string, 1, 7, tty_file_)) { |
| 329 int tty_number = -1; | 333 int tty_number = -1; |
| 330 int num_res = sscanf(tty_string, "tty%d", &tty_number); | 334 int num_res = sscanf(tty_string, "tty%d", &tty_number); |
| 331 if (num_res == 1 && tty_number != 1) | 335 if (num_res == 1 && tty_number != 1) |
| 332 return; | 336 return; |
| 333 } | 337 } |
| 334 #endif | 338 #endif |
| 335 | 339 |
| 340 // Store variables so they're available in crash dumps to help determine the |
| 341 // cause of any hang. |
| 342 #if defined(OS_WIN) |
| 343 ULONGLONG fire_interrupt_time; |
| 344 QueryUnbiasedInterruptTime(&fire_interrupt_time); |
| 345 |
| 346 // This is the time since the watchdog was armed, in 100ns intervals, |
| 347 // ignoring time where the computer is suspended. |
| 348 ULONGLONG interrupt_delay = fire_interrupt_time - arm_interrupt_time_; |
| 349 |
| 350 base::debug::Alias(&interrupt_delay); |
| 351 base::debug::Alias(&time_since_arm); |
| 352 |
| 353 bool using_high_res_timer = base::Time::IsHighResolutionTimerInUse(); |
| 354 base::debug::Alias(&using_high_res_timer); |
| 355 #endif |
| 356 |
| 357 base::Time current_time = base::Time::Now(); |
| 358 base::TimeTicks current_timeticks = base::TimeTicks::Now(); |
| 359 base::debug::Alias(¤t_time); |
| 360 base::debug::Alias(¤t_timeticks); |
| 361 |
| 336 LOG(ERROR) << "The GPU process hung. Terminating after " | 362 LOG(ERROR) << "The GPU process hung. Terminating after " |
| 337 << timeout_.InMilliseconds() << " ms."; | 363 << timeout_.InMilliseconds() << " ms."; |
| 338 | 364 |
| 339 // Deliberately crash the process to create a crash dump. | 365 // Deliberately crash the process to create a crash dump. |
| 340 *((volatile int*)0) = 0x1337; | 366 *((volatile int*)0) = 0x1337; |
| 341 | 367 |
| 342 terminated = true; | 368 terminated = true; |
| 343 } | 369 } |
| 344 | 370 |
| 345 #if defined(USE_X11) | 371 #if defined(USE_X11) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // not increasing. The other is where either the kernel hangs and never | 444 // not increasing. The other is where either the kernel hangs and never |
| 419 // returns to user level or where user level code | 445 // returns to user level or where user level code |
| 420 // 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 |
| 421 // tracked, for example a loop that repeatedly Sleeps. | 447 // tracked, for example a loop that repeatedly Sleeps. |
| 422 return base::TimeDelta::FromMilliseconds(static_cast<int64_t>( | 448 return base::TimeDelta::FromMilliseconds(static_cast<int64_t>( |
| 423 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); | 449 (user_time64.QuadPart + kernel_time64.QuadPart) / 10000)); |
| 424 } | 450 } |
| 425 #endif | 451 #endif |
| 426 | 452 |
| 427 } // namespace content | 453 } // namespace content |
| OLD | NEW |