Should check the return value of clock_gettime
In ghc-7.6.3/rts/posix/GetTime.c
, function StgWord64 getMonotonicNSec(void)
:
The return value of clock_gettime
should be checked, and if the value is not 0 (success), it should fall back to gettimeofday
. The following patch demonstrates a possible fix:
--- pre/rts/posix/GetTime.c 2013-04-18 17:22:47.000000000 -0400
+++ ghc-7.6.3/rts/posix/GetTime.c 2014-03-28 09:52:08.537125998 -0400
@@ -84,19 +82,22 @@
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
+ int res=
clock_gettime(CLOCK_ID, &ts);
+ if(res==0)
return (StgWord64)ts.tv_sec * 1000000000 +
(StgWord64)ts.tv_nsec;
#elif defined(darwin_HOST_OS)
uint64_t time = mach_absolute_time();
return (time * timer_scaling_factor_numer) / timer_scaling_factor_denom;
-#else
+#endif
+ { //fallback
struct timeval tv;
gettimeofday(&tv, (struct timezone *) NULL);
return (StgWord64)tv.tv_sec * 1000000000 +
(StgWord64)tv.tv_usec * 1000;
-#endif
+ }
}
Time getProcessElapsedTime(void)
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | simonmar |
Operating system | |
Architecture |