23688

Is QueryUnbiasedInterruptTime monotonic?

Question:

I'm trying to find a decent replacement on Windows for clock_gettime(CLOCK_MONOTONIC) and mach_absolute_time.

GetTickCount is annoying because it's deliberately biased: when the system resumes from suspend or hibernation, it seems Windows works out how long it was suspended (from motherboard) then adds that to the tick count to make it look like the tick carried on while the system was powered down.

QueryUnbiasedInterruptTime is friendlier: it's a simple, seemingly-reliable counter that just returns the time the system has been running since boot.

Now, I've experimented with QueryUnbiasedInterruptTime to see what happens when the computer enters each of: sleep, hybrid sleep, and hibernation. It appears that it's correctly updated so that it appears to be monotonic (ie, the system stashes it before hibernation and restores it so that applications aren't confused).

But, there's a note <a href="http://www.python.org/dev/peps/pep-0418/#sleep" rel="nofollow">here on the Python dev pages</a> (which, by the way, are a very helpful resource for time function reference!):

<blockquote>

QueryUnbiasedInterruptTime() is not monotonic.

</blockquote>

I presume someone did a test to determine that. Is that information accurate? If so, out of interest I wonder what you have to do to get the return value to go backwards.

Answer1:

QueryUnbiasedInterruptTime is guaranteed to be monotonic. The interrupt time has no skew added to it, so it always ticks forward although the rate may sometimes differ a little from the wall clock.

I couldn't find any good references for this in MSDN, but I'm now convinced that Hans is right in his comment, the CPython developers must have simply got confused.

Answer2:

The main problem with GetTickCount is the value being only 32 bits, i.e. it resets to zero every 50 days of uptime.

You probably need QueryPerformanceCounter API.

Recommend

  • Multiselect using mouse in TListview?
  • Using the Built in Visual Studio Diff Tool to View P4VS's Diffs
  • How do I make Paypal to send IPN to my server with simple HTTP authentication?
  • selenium server launching two test execution tabs in firefox
  • XML request in PHP NuSoap - “HTTP/1.1 400 Bad Request”
  • Java EE: Proxy cannot be cast to Local Interface, maybe classloading issue?
  • Does Cocoa connection binding to NSToolbarItem prevent deinitializing?
  • GraphicsPath and OutOfMemoryException
  • Rounding returned float values from a DB to their 'correct' values
  • Conflict between Facebook Sign In and Google Sign In - iOS
  • How to check whether a command can be executed?
  • Erratic data cursor behavior for triangulated 3d surfaces in MATLAB R2011b
  • Raising numbers to fractional powers in SQL
  • Using c2hs on Windows
  • Uploading image using Codeigniter (API)
  • HTML file fetched using 'wget' reported as binary by 'less'
  • Assignment of Allocatables of Different Shapes in Fortran [duplicate]
  • How does Skobbler prioritize which POIs to show?
  • Having trouble creating a list based on function arguments
  • R h2o.glm - issue with max_active_predictors
  • get all processes in parallel
  • Should I be afraid to use UDP to make a client/server broadcast talk?
  • Center align outputs in ipython notebook
  • How VBA declared Volatility works
  • How to run “Deployd” on port 80 instead of port 5000 in webserver.
  • Reading JSON from a file using C++ REST SDK (Casablanca)
  • Regex thinks I'm nesting, but I'm not
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Fill an image in a square container while keeping aspect ratio
  • How to handle AllServersUnavailable Exception
  • ActionScript 2 vs ActionScript 3 performance
  • How can I estimate amount of memory left with calling System.gc()?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Apache 2.4 - remove | delete | uninstall
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Reading document lines to the user (python)