Chromium Code Reviews| Index: src/platform/time.cc |
| diff --git a/src/platform/time.cc b/src/platform/time.cc |
| index de0ca16473f6b5106485508653cfe797f6632c37..6d95ed2a3f2641edccb86ac8a2b4b4535cbdd653 100644 |
| --- a/src/platform/time.cc |
| +++ b/src/platform/time.cc |
| @@ -43,6 +43,10 @@ |
| #include "win32-headers.h" |
| #endif |
| +#if V8_OS_LINUX && !defined(CLOCK_MONOTONIC_COARSE) |
| +#define CLOCK_MONOTONIC_COARSE 6 // 2.6.32 and up. |
| +#endif |
| + |
| namespace v8 { |
| namespace internal { |
| @@ -570,7 +574,23 @@ TimeTicks TimeTicks::HighResolutionNow() { |
| ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); |
| #elif V8_OS_POSIX |
| struct timespec ts; |
| +#if V8_OS_LINUX |
| + // Prefer CLOCK_MONOTONIC_COARSE, a high-res clock that's available in |
| + // 2.6.32 and can be fully serviced from the vDSO, even on virtualized |
| + // systems. Check that it's not *too* coarse though. |
| + static clock_t clock_id = -1; |
|
Benedikt Meurer
2013/10/31 06:44:50
I think we can safely use zero here, i.e. no expli
bnoordhuis
2013/10/31 12:22:24
I wrote it that way because 0 is a valid clock (CL
Benedikt Meurer
2013/11/04 09:09:57
Please just use 0 here.
|
| + if (clock_id == -1) { |
| + if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts) == 0 && |
|
Benedikt Meurer
2013/10/31 06:44:50
This won't compile on non-Linux systems that miss
bnoordhuis
2013/10/31 12:22:24
If it weren't for the #if V8_OS_LINUX a few lines
Benedikt Meurer
2013/11/04 09:09:57
Ups, right. Ok, that's fine.
|
| + ts.tv_nsec <= 1 * 1000 * 1000) { // 1 ms granularity or less. |
| + clock_id = CLOCK_MONOTONIC_COARSE; |
| + } else { |
| + clock_id = CLOCK_MONOTONIC; |
| + } |
| + } |
| + int result = clock_gettime(clock_id, &ts); |
| +#else |
| int result = clock_gettime(CLOCK_MONOTONIC, &ts); |
| +#endif // V8_OS_LINUX |
| ASSERT_EQ(0, result); |
| USE(result); |
| ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + |