Last active
August 17, 2018 08:38
-
-
Save stevedoyle/45a968d36630b390d0c75f74bd8f4960 to your computer and use it in GitHub Desktop.
RDTSC based timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _TIMESTAMP_H_ | |
#define _TIMESTAMP_H_ | |
static inline uint64_t timestamp_start(void) | |
{ | |
union { | |
uint64_t tsc_64; | |
struct { | |
uint32_t lo_32; | |
uint32_t hi_32; | |
}; | |
} tsc; | |
asm volatile ( | |
"CPUID\n\t"/*serialize*/ | |
"RDTSC\n\t"/*read the clock*/ | |
"mov %%edx, %0\n\t" | |
"mov %%eax, %1\n\t": "=r" (tsc.hi_32), "=r" | |
(tsc.lo_32):: "%rax", "%rbx", "%rcx", "%rdx"); | |
return tsc.tsc_64; | |
} | |
static inline uint64_t timestamp_end(void) | |
{ | |
union { | |
uint64_t tsc_64; | |
struct { | |
uint32_t lo_32; | |
uint32_t hi_32; | |
}; | |
} tsc; | |
asm volatile ( | |
"RDTSCP\n\t"/*read the clock*/ | |
"mov %%edx, %0\n\t" | |
"mov %%eax, %1\n\t" | |
"CPUID\n\t": "=r" (tsc.hi_32), "=r" | |
(tsc.lo_32):: "%rax", "%rbx", "%rcx", "%rdx"); | |
return tsc.tsc_64; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment