From 28a115e5e2c3c19b860545f1fcde4317bac3ee2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Tue, 19 Sep 2017 15:09:29 -0400 Subject: base: fdReady(): Improve accuracy and simplify code. This is done by reusing the existing cross-platform `getProcessElapsedTime()` function, which already provides nanosecond monotonic clocks, and fallback for platforms that don't have those. To do this, `getProcessElapsedTime()` had to be moved from a private RTS symbol into the public interface. Accuracy is improved in 2 ways: * Use of the monotonic clock where available * Measuring the total time spent waiting instead of a sum of intervals (between which there are small gaps) Reviewers: bgamari, austin, hvr, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3953 --- includes/rts/Time.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'includes/rts') diff --git a/includes/rts/Time.h b/includes/rts/Time.h index 5fa166e125..12c6d2767d 100644 --- a/includes/rts/Time.h +++ b/includes/rts/Time.h @@ -21,8 +21,10 @@ typedef int64_t Time; #if TIME_RESOLUTION == 1000000000 // I'm being lazy, but it's awkward to define fully general versions of these +#define TimeToMS(t) ((t) / 1000000) #define TimeToUS(t) ((t) / 1000) #define TimeToNS(t) (t) +#define MSToTime(t) ((Time)(t) * 1000000) #define USToTime(t) ((Time)(t) * 1000) #define NSToTime(t) ((Time)(t)) #else @@ -38,3 +40,5 @@ INLINE_HEADER Time fsecondsToTime (double t) { return (Time)(t * TIME_RESOLUTION); } + +Time getProcessElapsedTime (void); -- cgit v1.2.1