]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c/lowlevel/arch-x86-common/clock.h
Initial checkin from Perforce.
[polintos/scott/priv.git] / include / c / lowlevel / arch-x86-common / clock.h
1 #ifndef _LL_ARCH_X86C_CLOCK_H
2 #define _LL_ARCH_X86C_CLOCK_H
3
4 #include <stdint.h>
5
6 // Return a monotonically increasing 64-bit clock value that wraps
7 // around no more often than once per year, and with a resolution of 1
8 // us or better (if possible).  This function's availability and
9 // privileged status is architecture and configuration dependent; on
10 // x86 and x64, it is normally not privileged.  On some architectures,
11 // and on older (486 and earlier) x86 chips, it will need to be
12 // supplied externally using board or kernel specific code.
13
14 static inline int64_t ll_getclock()
15 {
16         int32_t high;
17         uint32_t low;
18         
19         asm volatile("rdtsc" : "=a" (low), "=d" (high));
20
21         return ((int64_t)high << 32) | low;
22 }
23
24 static inline int32_t ll_getclock32()
25 {
26         uint32_t clock;
27         asm volatile("rdtsc" : "=a" (clock) : : "edx");
28         return clock;
29 }
30
31 #endif