Use clock_gettime(CLOCK_REALTIME) in DateTime.UtcNow (dotnet/coreclr#9772)
authorStephen Toub <stoub@microsoft.com>
Sat, 25 Feb 2017 01:39:44 +0000 (20:39 -0500)
committerJan Vorlicek <janvorli@microsoft.com>
Sat, 25 Feb 2017 01:39:44 +0000 (02:39 +0100)
commitef523c251f1c3ce8c9fc04d841fae7b5dd7c2c66
treeb10c36528d212832400255d616a7c8c7ec95b9e4
parent70b6f081d7cefbee92fab86b6e0805483d9a9b50
Use clock_gettime(CLOCK_REALTIME) in DateTime.UtcNow (dotnet/coreclr#9772)

gettimeofday() is currently used in DateTime.UtcNow.  Depending on the system, it may have accuracy and precision in line with either clock_gettime(CLOCK_REALTIME) or clock_gettime(CLOCK_REALTIME_COARSE), but in returning its data it's necessarily limited by struct timeval's tv_usec field (microseconds), whereas clock_gettime uses struct timespec which has tv_nsec (nanoseconds).  This commit switches to use clock_gettime(CLOCK_REALTIME) to gain the additional precision (though the FILETIME through which the data is returned only supports 100-nsec precision).  On my machine, there was no measurable impact to throughput.

Commit migrated from https://github.com/dotnet/coreclr/commit/3fe022eb723479d0b7acf17856e76a1973668ca6
src/coreclr/src/pal/src/file/filetime.cpp