快速获取时间的函数

it2024-07-12  38

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; }

在x86-64下,用RDTSC指令从寄存器中直接读取。 union在这用的也很漂亮,直接赋值转换,根本不用计算。

最新回复(0)