diff --git a/include/common/standard.h b/include/common/standard.h index d0d5065df..bb63535f7 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -959,4 +960,23 @@ static inline unsigned char utf8_return_length(unsigned char code) return code & 0x0f; } +/* returns a 64-bit a timestamp with the finest resolution available. The + * unit is intentionally not specified. It's mostly used to compare dates. + */ +#if defined(__i386__) || defined(__x86_64__) +static inline unsigned long long rdtsc() +{ + unsigned int a, d; + asm volatile("rdtsc" : "=a" (a), "=d" (d)); + return a + ((unsigned long long)d << 32); +} +#else +static inline unsigned long long rdtsc() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000000 + tv.tv_usec; +} +#endif + #endif /* _COMMON_STANDARD_H */