Fix problems with getMonotonicNSec on OS X
authorIan Lynagh <igloo@earth.li>
Sat, 26 May 2012 10:41:12 +0000 (11:41 +0100)
committerIan Lynagh <igloo@earth.li>
Sat, 26 May 2012 10:47:21 +0000 (11:47 +0100)
We were incorrectly multiplying by 1e9, which (a) meant we were
getting values that were far too large, and (b) meant that when
we casted from double to StgWord64 the result was 0, as the value
was out of range.

We now do all the work as StgWord64.

rts/posix/GetTime.c

index da8d0fa..fabc404 100644 (file)
@@ -34,7 +34,8 @@
 // separately, using getrusage() and gettimeofday() respectively
 
 #ifdef darwin_HOST_OS
-static double timer_scaling_factor_ns = 0.0;
+static uint64_t timer_scaling_factor_numer = 0;
+static uint64_t timer_scaling_factor_denom = 0;
 #endif
 
 void initializeTimer()
@@ -42,7 +43,8 @@ void initializeTimer()
 #ifdef darwin_HOST_OS
     mach_timebase_info_data_t info;
     (void) mach_timebase_info(&info);
-    timer_scaling_factor_ns = (double)info.numer / (double)info.denom * 1e9;
+    timer_scaling_factor_numer = (uint64_t)info.numer;
+    timer_scaling_factor_denom = (uint64_t)info.denom;
 #endif
 }
 
@@ -87,7 +89,7 @@ StgWord64 getMonotonicNSec(void)
            (StgWord64)ts.tv_nsec;
 #elif defined(darwin_HOST_OS)
     uint64_t time = mach_absolute_time();
-    return (double)time * timer_scaling_factor_ns;
+    return (time * timer_scaling_factor_numer) / timer_scaling_factor_denom;
 #else
     struct timeval tv;