Go to the documentation of this file.00001 #include "timing.h"
00002 #include "muster-config.h"
00003
00004 #include <cmath>
00005 using namespace std;
00006
00007
00008 #if defined(MUSTER_BLUEGENE_L)
00009
00010
00011
00012 #include <rts.h>
00013
00014
00015
00016
00017 static double get_ns_per_cycle() {
00018 BGLPersonality personality;
00019 if (rts_get_personality(&personality, sizeof(personality)) != 0)
00020 return 0;
00021 return 1.0e9/((double) personality.clockHz);
00022 }
00023
00024
00025 timing_t get_time_ns () {
00026 static double ns_per_cycle = get_ns_per_cycle();
00027 return (timing_t)(ns_per_cycle * rts_get_timebase());
00028 }
00029
00030
00031 #elif defined(MUSTER_BLUEGENE_P)
00032
00033
00034
00035 #define SPRN_TBRL 0x10C // Time Base Read Lower Register (user & sup R/O)
00036 #define SPRN_TBRU 0x10D // Time Base Read Upper Register (user & sup R/O)
00037 #define BGP_NS_PER_CYCLE (1.0/0.85) // Nanoseconds per cycle on BGP (850Mhz clock)
00038
00039 #define _bgp_mfspr(SPRN) ({ \
00040 unsigned int tmp; \
00041 do { \
00042 asm volatile ("mfspr %0,%1" : "=&r" (tmp) : "i" (SPRN) : "memory" ); \
00043 } while(0); \
00044 tmp; \
00045 })
00046
00047 union bgp_time_reg {
00048 unsigned int ul[2];
00049 unsigned long long ull;
00050 };
00051
00052 static inline unsigned long long timebase() {
00053 bgp_time_reg reg;
00054 unsigned int utmp;
00055
00056 do {
00057 utmp = _bgp_mfspr(SPRN_TBRU);
00058 reg.ul[1] = _bgp_mfspr(SPRN_TBRL);
00059 reg.ul[0] = _bgp_mfspr(SPRN_TBRU);
00060 }
00061 while( utmp != reg.ul[0] );
00062
00063 return reg.ull;
00064 }
00065
00066 timing_t get_time_ns() {
00067 return llround(BGP_NS_PER_CYCLE * timebase());
00068 }
00069
00070
00071
00072 #elif (defined(MUSTER_HAVE_CLOCK_GETTIME))
00073
00074
00075
00076
00077 #include <ctime>
00078 #include <sys/time.h>
00079
00080 timing_t get_time_ns() {
00081 struct timespec ts;
00082 clock_gettime(CLOCK_MONOTONIC, &ts);
00083 return (ts.tv_sec * 1000000000ll + ts.tv_nsec);
00084 }
00085
00086
00087 #elif defined(MUSTER_HAVE_GETTIMEOFDAY)
00088
00089
00090
00091
00092 #include <ctime>
00093 #include <sys/time.h>
00094
00095 timing_t get_time_ns() {
00096 struct timeval tv;
00097 gettimeofday(&tv, NULL);
00098 return tv.tv_sec * 1000000000ll + tv.tv_usec * 1000ll;
00099 }
00100
00101
00102 #else // if we get to here, we don't even have gettimeofday.
00103 #error "NO SUPPORTED TIMING FUNCTIONS FOUND!"
00104 #endif // types of timers