MPS issue job003969

TitleEvent clock implementation may not be reliable
Assigned userGareth Rees
DescriptionThe event clock implementation reads the Time Stamp Counter via the RDTSC instruction. But this may not be reliable.

Wikipedia says [1]: "With the advent of multi-core/hyper-threaded CPUs, systems with multiple CPUs, and hibernating operating systems, the TSC cannot be relied on to provide accurate results. ... There is no promise that the timestamp counters of multiple CPUs on a single motherboard will be synchronized. In such cases, programmers can only get reliable results by locking their code to a single CPU."

Windows documentation says [2]: "We strongly discourage using the RDTSC or RDTSCP processor instruction to directly query the TSC because you won't get reliable results on some versions of Windows, across live migrations of virtual machines, and on hardware systems without invariant or tightly synchronized TSCs."
AnalysisIt looks as if QueryPerformanceCounter [3] may be the right API on Windows, and clock_gettime(CLOCK_MONOTONIC) [4] on POSIX. But are these fast enough? If they use system calls then there are not so good.

See "Pitfalls of TSC usage" [5], which discusses the situation on Linux.
How foundinspection
Evidence[1] <>
[2] <>
[3] <>
[4] <>
Created byGareth Rees
Created on2016-03-06 21:51:32
Last modified byGareth Rees
Last modified on2016-09-18 20:35:57
History2016-03-06 GDR Created.