1
#ifndef ARMCI_TESTING_TIMER_H_
2
#define ARMCI_TESTING_TIMER_H_
4
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
7
static __inline__ unsigned long long rdtsc(void)
9
unsigned long long int x;
10
__asm__ volatile(".byte 0x0f, 0x31" : "=A"(x));
13
# elif defined(__x86_64__)
14
static __inline__ unsigned long long rdtsc(void)
17
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
18
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
20
# elif defined(__powerpc__)
21
static __inline__ unsigned long long rdtsc(void)
23
unsigned long long int result = 0;
24
unsigned long int upper, lower, tmp;
32
: "=r"(upper), "=r"(lower), "=r"(tmp)
35
result = result << 32;
36
result = result | lower;
42
# include <sys/time.h>
45
static LARGE_INTEGER frequency;
48
static unsigned long long timer_start()
54
(void)gettimeofday(&timer, NULL);
55
return timer.tv_sec * 1000000 + timer.tv_usec;
58
QueryPerformanceCounter(&timer);
59
return timer.QuadPart * 1000 / frequency.QuadPart;
65
static unsigned long long timer_end(unsigned long long begin)
67
return timer_start() - begin;
70
static void timer_init()
75
QueryPerformanceFrequency(&frequency);
80
static const char *timer_name()
85
return "gettimeofday";
87
return "windows QueryPerformanceCounter";
93
#endif /* ARMCI_TESTING_TIMER_H_ */