2 #include "muster-config.h"
8 #if defined(MUSTER_BLUEGENE_L)
17 static double get_ns_per_cycle() {
18 BGLPersonality personality;
19 if (rts_get_personality(&personality,
sizeof(personality)) != 0)
21 return 1.0e9/((double) personality.clockHz);
26 static double ns_per_cycle = get_ns_per_cycle();
27 return (
timing_t)(ns_per_cycle * rts_get_timebase());
31 #elif defined(MUSTER_BLUEGENE_P)
35 #define SPRN_TBRL 0x10C // Time Base Read Lower Register (user & sup R/O)
36 #define SPRN_TBRU 0x10D // Time Base Read Upper Register (user & sup R/O)
37 #define BGP_NS_PER_CYCLE (1.0/0.85) // Nanoseconds per cycle on BGP (850Mhz clock)
39 #define _bgp_mfspr(SPRN) ({ \
42 asm volatile ("mfspr %0,%1" : "=&r" (tmp) : "i" (SPRN) : "memory" ); \
49 unsigned long long ull;
52 static inline unsigned long long timebase() {
57 utmp = _bgp_mfspr(SPRN_TBRU);
58 reg.ul[1] = _bgp_mfspr(SPRN_TBRL);
59 reg.ul[0] = _bgp_mfspr(SPRN_TBRU);
61 while( utmp != reg.ul[0] );
67 return llround(BGP_NS_PER_CYCLE * timebase());
72 #elif (defined(MUSTER_HAVE_CLOCK_GETTIME))
82 clock_gettime(CLOCK_MONOTONIC, &ts);
83 return (ts.tv_sec * 1000000000ll + ts.tv_nsec);
86 #elif defined(MUSTER_HAVE_MACH_TIME)
88 #include <mach/mach.h>
89 #include <mach/mach_time.h>
92 static mach_timebase_info_data_t timebase_info;
93 if (timebase_info.denom == 0) {
94 mach_timebase_info(&timebase_info);
96 timing_t machtime = mach_absolute_time();
97 return machtime * timebase_info.numer / timebase_info.denom;
100 #elif defined(MUSTER_HAVE_GETTIMEOFDAY)
106 #include <sys/time.h>
110 gettimeofday(&tv, NULL);
111 return tv.tv_sec * 1000000000ll + tv.tv_usec * 1000ll;
115 #else // if we get to here, we don't even have gettimeofday.
116 #error "NO SUPPORTED TIMING FUNCTIONS FOUND!"
117 #endif // types of timers
unsigned long long timing_t
Size for timings reported by get_time_ns.
timing_t get_time_ns()
This is defined differently depending on compile-time timing options and on the platform we're using...