Bug 1487778 - Protect QueryPerformanceCounter against going backward, r=froydnj
authorHonza Bambas <honzab.moz@firemni.cz>
Mon, 26 Nov 2018 03:08:00 +0200
changeset 507226 c766f7eaa9f940c6bd075fb0e87c2ee9b19fcb57
parent 507225 79b57272e805a27451a9ace83ee3cfed172ff8d5
child 507227 8a05e30b76c481fd9da971c7ec15a8ca42445530
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1487778
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1487778 - Protect QueryPerformanceCounter against going backward, r=froydnj
mozglue/misc/TimeStamp_windows.cpp
--- a/mozglue/misc/TimeStamp_windows.cpp
+++ b/mozglue/misc/TimeStamp_windows.cpp
@@ -157,29 +157,25 @@ namespace mozilla {
 
 // Result is in [mt]
 static inline ULONGLONG
 PerformanceCounter()
 {
   LARGE_INTEGER pc;
   ::QueryPerformanceCounter(&pc);
 
-  // As an experiment, we want to have a monotonicity sentinel
-  // even if the TSC is reported as stable.
-  if (true || !sHasStableTSC) {
-    // This is a simple go-backward protection for faulty hardware
-    AutoCriticalSection lock(&sTimeStampLock);
+  // QueryPerformanceCounter may slightly jitter (not be 100% monotonic.)
+  // This is a simple go-backward protection for such a faulty hardware.
+  AutoCriticalSection lock(&sTimeStampLock);
 
-    static decltype(LARGE_INTEGER::QuadPart) last;
-    if (last > pc.QuadPart) {
-      return last * 1000ULL;
-    }
-    last = pc.QuadPart;
+  static decltype(LARGE_INTEGER::QuadPart) last;
+  if (last > pc.QuadPart) {
+    return last * 1000ULL;
   }
-
+  last = pc.QuadPart;
   return pc.QuadPart * 1000ULL;
 }
 
 static void
 InitThresholds()
 {
   DWORD timeAdjustment = 0, timeIncrement = 0;
   BOOL timeAdjustmentDisabled;