-
Notifications
You must be signed in to change notification settings - Fork 1
/
measure.h
79 lines (56 loc) · 1.39 KB
/
measure.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _TIMING_H_
#define _TIMING_H_
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <map>
#include <vector>
#include <list>
typedef uint64_t pointer;
typedef std::pair<pointer, pointer> addrpair;
static inline __attribute__ ((always_inline))
void mfence()
{
asm volatile ("mfence":::"memory");
}
static inline __attribute__ ((always_inline))
void lfence()
{
asm volatile ("lfence":::"memory");
}
long utime() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
}
static inline __attribute__ ((always_inline))
void cpuid()
{
asm volatile ("cpuid":::"rax", "rbx", "rcx", "rdx");
}
extern inline __attribute__((always_inline))
uint64_t rdtsc() {
uint64_t a, d;
asm volatile ("xor %%rax, %%rax\n" "cpuid"::: "rax", "rbx", "rcx", "rdx");
asm volatile ("rdtscp" : "=a" (a), "=d" (d) : : "rcx");
a = (d << 32) | a;
return a;
}
// ----------------------------------------------
extern inline __attribute__((always_inline))
uint64_t rdtsc2() {
uint64_t a, d;
asm volatile ("rdtscp" : "=a" (a), "=d" (d) : : "rcx");
asm volatile ("cpuid"::: "rax", "rbx", "rcx", "rdx");
a = (d << 32) | a;
return a;
}
static inline __attribute__ ((always_inline))
uint64_t rdtscp(void)
{
uint64_t lo, hi;
asm volatile ("rdtscp\n":"=a" (lo), "=d"(hi)
::"%rcx");
return (hi << 32) | lo;
}
#endif