Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 5 |
| 6 // Windows Timer Primer | 6 // Windows Timer Primer |
| 7 // | 7 // |
| 8 // A good article: http://www.ddj.com/windows/184416651 | 8 // A good article: http://www.ddj.com/windows/184416651 |
| 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 | 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 |
| 10 // | 10 // |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 | 324 |
| 325 bool IsUsingHighResClock() { | 325 bool IsUsingHighResClock() { |
| 326 return ticks_per_microsecond_ != 0.0; | 326 return ticks_per_microsecond_ != 0.0; |
| 327 } | 327 } |
| 328 | 328 |
| 329 void DisableHighResClock() { | 329 void DisableHighResClock() { |
| 330 ticks_per_microsecond_ = 0.0; | 330 ticks_per_microsecond_ = 0.0; |
| 331 } | 331 } |
| 332 | 332 |
| 333 TimeDelta Now() { | 333 TimeDelta Now() { |
| 334 // Our maximum tolerance for QPC drifting. | 334 if (IsUsingHighResClock()) |
| 335 const int kMaxTimeDriftMicroseconds = 60150; | 335 return TimeDelta::FromMicroseconds(UnreliableNow()); |
| 336 | |
| 337 if (IsUsingHighResClock()) { | |
| 338 int64 now = UnreliableNow(); | |
| 339 | |
| 340 // Verify that QPC does not seem to drift. | |
| 341 DCHECK_LT(abs((now - ReliableNow()) - skew_), kMaxTimeDriftMicroseconds); | |
| 342 | |
| 343 return TimeDelta::FromMicroseconds(now); | |
| 344 } | |
| 345 | 336 |
| 346 // Just fallback to the slower clock. | 337 // Just fallback to the slower clock. |
| 347 return RolloverProtectedNow(); | 338 return RolloverProtectedNow(); |
| 348 } | 339 } |
| 349 | 340 |
| 341 int64 GetQPCDriftMicroseconds() { | |
| 342 if (!IsUsingHighResClock()) | |
| 343 return 0; | |
| 344 | |
| 345 return abs((UnreliableNow() - ReliableNow()) - skew_); | |
|
brettw
2010/08/03 18:17:35
Is this right? It seems like the sign of Unreliabl
cpu_(ooo_6.6-7.5)
2010/08/04 17:44:42
Seems ok to me. You *could* remove the outer abs()
| |
| 346 } | |
| 347 | |
| 350 private: | 348 private: |
| 351 // Synchronize the QPC clock with GetSystemTimeAsFileTime. | 349 // Synchronize the QPC clock with GetSystemTimeAsFileTime. |
| 352 void InitializeClock() { | 350 void InitializeClock() { |
| 353 LARGE_INTEGER ticks_per_sec = {0}; | 351 LARGE_INTEGER ticks_per_sec = {0}; |
| 354 if (!QueryPerformanceFrequency(&ticks_per_sec)) | 352 if (!QueryPerformanceFrequency(&ticks_per_sec)) |
| 355 return; // Broken, we don't guarantee this function works. | 353 return; // Broken, we don't guarantee this function works. |
| 356 ticks_per_microsecond_ = static_cast<float>(ticks_per_sec.QuadPart) / | 354 ticks_per_microsecond_ = static_cast<float>(ticks_per_sec.QuadPart) / |
| 357 static_cast<float>(Time::kMicrosecondsPerSecond); | 355 static_cast<float>(Time::kMicrosecondsPerSecond); |
| 358 | 356 |
| 359 skew_ = UnreliableNow() - ReliableNow(); | 357 skew_ = UnreliableNow() - ReliableNow(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 | 389 |
| 392 // static | 390 // static |
| 393 TimeTicks TimeTicks::Now() { | 391 TimeTicks TimeTicks::Now() { |
| 394 return TimeTicks() + RolloverProtectedNow(); | 392 return TimeTicks() + RolloverProtectedNow(); |
| 395 } | 393 } |
| 396 | 394 |
| 397 // static | 395 // static |
| 398 TimeTicks TimeTicks::HighResNow() { | 396 TimeTicks TimeTicks::HighResNow() { |
| 399 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); | 397 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); |
| 400 } | 398 } |
| 399 | |
| 400 // static | |
| 401 int64 TimeTicks::GetQPCDriftMicroseconds() { | |
| 402 return Singleton<HighResNowSingleton>::get()->GetQPCDriftMicroseconds(); | |
| 403 } | |
| OLD | NEW |