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 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#ifndef ARMCI_TESTING_TIMER_H_
#define ARMCI_TESTING_TIMER_H_
#if (defined(__i386__) || defined(__x86_64__) || defined(__powerpc__))
# define HAVE_RDTSC 1
# if defined(__i386__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int x;
__asm__ volatile(".byte 0x0f, 0x31" : "=A"(x));
return x;
}
# elif defined(__x86_64__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}
# elif defined(__powerpc__)
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int result = 0;
unsigned long int upper, lower, tmp;
__asm__ volatile(
"0: \n"
"\tmftbu %0 \n"
"\tmftb %1 \n"
"\tmftbu %2 \n"
"\tcmpw %2,%0 \n"
"\tbne 0b \n"
: "=r"(upper), "=r"(lower), "=r"(tmp)
);
result = upper;
result = result << 32;
result = result | lower;
return(result);
}
# endif
#elif HAVE_SYS_TIME_H
# include <sys/time.h>
#elif HAVE_WINDOWS_H
# include <windows.h>
static LARGE_INTEGER frequency;
#endif
static unsigned long long timer_start()
{
#if HAVE_RDTSC
return rdtsc();
#elif HAVE_SYS_TIME_H
struct timeval timer;
(void)gettimeofday(&timer, NULL);
return timer.tv_sec * 1000000 + timer.tv_usec;
#elif HAVE_WINDOWS_H
LARGE_INTEGER timer;
QueryPerformanceCounter(&timer);
return timer.QuadPart * 1000 / frequency.QuadPart;
#else
return 0;
#endif
}
static unsigned long long timer_end(unsigned long long begin)
{
return timer_start() - begin;
}
static void timer_init()
{
#if HAVE_RDTSC
#elif HAVE_SYS_TIME_H
#elif HAVE_WINDOWS_H
QueryPerformanceFrequency(&frequency);
#else
#endif
}
static const char *timer_name()
{
#if HAVE_RDTSC
return "rdtsc";
#elif HAVE_SYS_TIME_H
return "gettimeofday";
#elif HAVE_WINDOWS_H
return "windows QueryPerformanceCounter";
#else
return "no timers";
#endif
}
#endif /* ARMCI_TESTING_TIMER_H_ */
|