Function to get time quickly

static inline uint64_t
rte_rdtsc(void)
{
    
    
    union {
    
    
        uint64_t tsc_64;
        struct {
    
    
            uint32_t lo_32;
            uint32_t hi_32;
        };
    } tsc;
 
    asm volatile("rdtsc" :
             "=a" (tsc.lo_32),
             "=d" (tsc.hi_32));
    return tsc.tsc_64;
}

Under x86-64, use the RDTSC instruction to read directly from the register.
Union is also used here very beautifully, direct assignment conversion, no calculation at all.

Guess you like

Origin blog.csdn.net/niu91/article/details/109199724