rdtsc, too many cycles

后端 未结 5 951
梦毁少年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:41

    Instruction cache miss? (this is my guess)

    Also, possibly,

    Switch to hypervisor in a virtualized system? Remnants of program bootstrap (including network activity on same CPU)?

    To Thanatos: On systems more recent than 2008, rdtsc() is a wall clock and does not vary with frequency steps.

    Can you try this little code?

    int main()
    {   
        long long res;
    
        fflush(stdout);           // chnage the exact timing of stdout, in case there is something to write in a ssh connection, together with its interrupts
    
        for (int pass = 0; pass < 2; pass++)
        {
        res=tick();
        res=tick()-res;
        }
        printf("%d",res);     // ignore result on first pass, display the result on second pass.
        return 0;
    }
    

提交回复
热议问题