This source file includes following definitions.
- opal_sys_timer_get_cycles
- opal_sys_timer_is_monotonic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifndef OPAL_SYS_ARCH_TIMER_H
23 #define OPAL_SYS_ARCH_TIMER_H 1
24
25
26 typedef uint64_t opal_timer_t;
27
28
29 #undef OPAL_TIMER_MONOTONIC
30 #define OPAL_TIMER_MONOTONIC 0
31
32 #if OPAL_GCC_INLINE_ASSEMBLY
33
34
35 static inline opal_timer_t
36 opal_sys_timer_get_cycles(void)
37 {
38 uint32_t l, h;
39 __asm__ __volatile__ ("lfence\n\t"
40 "rdtsc\n\t"
41 : "=a" (l), "=d" (h));
42 return ((opal_timer_t)l) | (((opal_timer_t)h) << 32);
43 }
44
45 static inline bool opal_sys_timer_is_monotonic (void)
46 {
47 int64_t tmp;
48 int32_t cpuid1, cpuid2;
49 const int32_t level = 0x80000007;
50
51
52
53 __asm__ volatile ("xchg %%rbx, %2\n"
54 "cpuid\n"
55 "xchg %%rbx, %2\n":
56 "=a" (cpuid1), "=d" (cpuid2), "=r" (tmp) :
57 "a" (level) :
58 "ecx", "ebx");
59
60 return !!(cpuid2 & (1 << 8));
61 }
62
63 #define OPAL_HAVE_SYS_TIMER_GET_CYCLES 1
64 #define OPAL_HAVE_SYS_TIMER_IS_MONOTONIC 1
65
66 #else
67
68 #define OPAL_HAVE_SYS_TIMER_GET_CYCLES 0
69
70 #endif
71
72 #endif