Calculating CPU frequency in C with RDTSC always returns 0

前端 未结 5 1081
情深已故
情深已故 2021-01-13 13:01

The following piece of code was given to us from our instructor so we could measure some algorithms performance:

#include 
#include 

        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-13 13:42

    As for VMWare, take a look at the time keeping spec (PDF Link), as well as this thread. TSC instructions are (depending on the guest OS):

    • Passed directly to the real hardware (PV guest)
    • Count cycles while the VM is executing on the host processor (Windows / etc)

    Note, in #2 the while the VM is executing on the host processor. The same phenomenon would go for Xen, as well, if I recall correctly. In essence, you can expect that the code should work as expected on a paravirtualized guest. If emulated, its entirely unreasonable to expect hardware like consistency.

提交回复
热议问题