Use CLOCK_MONOTONIC_COARSE in GetTickCount64
authorStephen Toub <stoub@microsoft.com>
Thu, 10 Dec 2015 15:45:59 +0000 (10:45 -0500)
committerStephen Toub <stoub@microsoft.com>
Thu, 10 Dec 2015 17:27:51 +0000 (12:27 -0500)
commit79b6d5df3dee969ebf89559c90ccc8636783d01b
treeafe270262b287af9032df2cf232f81336bbafce2
parentcb25307b3022b67cf240ff534f05778845090921
Use CLOCK_MONOTONIC_COARSE in GetTickCount64

Today, GetTickCount64 is implemented to use clock_gettime with CLOCK_MONOTONIC if it's available.  This provides for high-resolution, however it trades off that accuracy for some efficiency.

This commit changes it to prefer CLOCK_MONOTONIC_COARSE if it's available (QueryPerformanceCounter still uses CLOCK_MONOTONIC).  GetTickCount is typically used for coarse timings, e.g. used in a loop to determine whether more than 10 seconds have passed, and can have lower resolution in exchange for higher efficiency.  For Windows, the MSDN docs explicitly state that it's likely to have no better than 10-15 millisecond resolution. Using CLOCK_MONOTONIC_COARSE instead of CLOCK_MONOTIC maps better to this notion, and improves Environment.TickCount throughput on my machine by ~20x.  At the same time, on my machine it still provides well better than 10-15ms resolution, closer to ~4ms.
src/pal/src/config.h.in
src/pal/src/configure.cmake
src/pal/src/misc/time.cpp