rdtsc, too many cycles

后端 未结 5 901
梦毁少年i
梦毁少年i 2021-01-05 03:53
#include 
static inline unsigned long long tick() 
{
        unsigned long long d;
        __asm__ __volatile__ (\"rdtsc\" : \"=A\" (d) );
        ret         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 04:30

    I've tried your code on several Linux distros running on different Intel CPUs (admittedly all more recent than the Pentium 4 HT 630 you appear to be using). In all those tests I got values between 25 and 50 cycles.

    My only hypothesis that's consistent with all the evidence is that you're running your operating system inside a virtual machine rather than on bare metal, and TSC is getting virtualized.

提交回复
热议问题