summaryrefslogtreecommitdiff
path: root/rts/posix
diff options
context:
space:
mode:
authorPaolo Capriotti <p.capriotti@gmail.com>2012-05-08 13:05:14 +0100
committerPaolo Capriotti <p.capriotti@gmail.com>2012-05-08 13:05:14 +0100
commitc04619769d5a09325d9e7f28b1382f52df6051b4 (patch)
tree9fd0679f5c60743886f49d2b8f64b23f3bf2cb28 /rts/posix
parentd7bb8cd2c7d2806d01b732c412f99937240d9d02 (diff)
downloadhaskell-c04619769d5a09325d9e7f28b1382f52df6051b4.tar.gz
Move getMonotonicUSec from base to the RTS.
Diffstat (limited to 'rts/posix')
-rw-r--r--rts/posix/GetTime.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index 549b3b0878..da8d0fa629 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -33,6 +33,19 @@
// we'll implement getProcessCPUTime() and getProcessElapsedTime()
// separately, using getrusage() and gettimeofday() respectively
+#ifdef darwin_HOST_OS
+static double timer_scaling_factor_ns = 0.0;
+#endif
+
+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;
+#endif
+}
+
Time getProcessCPUTime(void)
{
#if !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_CPUTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) && defined(HAVE_SYSCONF)
@@ -64,32 +77,31 @@ Time getProcessCPUTime(void)
}
}
-Time getProcessElapsedTime(void)
+StgWord64 getMonotonicNSec(void)
{
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_ID, &ts);
- return SecondsToTime(ts.tv_sec) + NSToTime(ts.tv_nsec);
+ return (StgWord64)ts.tv_sec * 1000000000 +
+ (StgWord64)ts.tv_nsec;
#elif defined(darwin_HOST_OS)
uint64_t time = mach_absolute_time();
- static double scaling_factor = 0.0;
-
- if (scaling_factor == 0.0) {
- mach_timebase_info_data_t info;
- (void) mach_timebase_info(&info);
- scaling_factor = (double)info.numer / (double)info.denom;
- }
-
- return (Time)((double)time * scaling_factor);
+ return (double)time * timer_scaling_factor_ns;
#else
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
- return SecondsToTime(tv.tv_sec) + USToTime(tv.tv_usec);
+ return (StgWord64)tv.tv_sec * 1000000000 +
+ (StgWord64)tv.tv_usec * 1000;
#endif
}
+Time getProcessElapsedTime(void)
+{
+ return NSToTime(getMonotonicNSec());
+}
+
void getProcessTimes(Time *user, Time *elapsed)
{
*user = getProcessCPUTime();