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. Instead, we encourage you to use QPC to leverage the abstraction, consistency, and portability that it offers.
Discontinuous values. Using RDTSC directly assumes that the thread is always running on the same processor. Multiprocessor and dual-core systems do not guarantee synchronization of their cycle counters between cores. This is exacerbated when combined with modern power management technologies that idle and restore various cores at different times, which results in the cores typically being out of synchronization. For an application, this generally results in glitches or in potential crashes as the thread jumps between the processors and gets timing values that result in large deltas, negative deltas, or halted timing.
cmuratori
__rdtsc is very important and you definitely want to use it _for profiling_. What MSDN is talking about is _shipping_ code that uses __rdtsc to an end user, which is _not_ something you want to do, because you don't know what processor they might be using.
- Casey
QPC uses RDTSC inside.
ryanries
Thanks for the info, everyone.
From what I understand, QPC will use RDTSC *if* Windows had already determined ahead of time that the current platform had an invariant TSC, otherwise, it will fall back to using some other timer with less resolution but still pretty reliable.
For instance, using coreinfo.exe from Sysinternals, I can clearly see that the processor on one of my larger machines has an invariant TSC, however, one of the virtual machines running on that same hardware does not. So, running your software in a virtual machine might produce some surprises if you use a lot of timing-sensitive code and calls to rdtsc.
QueryPerformanceFrequency returned 3579545. 3.579545 MHz is a frequency used by NTSC, so it would not be surprising to see it as QPC's frequency. A frequency of 3579545 means that on your computer, there are 3579545 QPC "ticks" every second