Commit d0d0c36a authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Fix problems with getMonotonicNSec on OS X

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.
parent 05289c2a
......@@ -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;
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;
......@@ -87,7 +89,7 @@ StgWord64 getMonotonicNSec(void)
#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;
struct timeval tv;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment