[GHC] #8939: Should check the return value of clock_gettime

GHC ghc-devs at haskell.org
Fri Mar 28 21:29:46 UTC 2014


#8939: Should check the return value of clock_gettime
-------------------------------------------+-------------------------------
       Reporter:  uznx                     |             Owner:  simonmar
           Type:  bug                      |            Status:  new
       Priority:  normal                   |         Milestone:
      Component:  Runtime System           |           Version:  7.6.3
       Keywords:                           |  Operating System:
   Architecture:  Unknown/Multiple         |  Unknown/Multiple
     Difficulty:  Easy (less than 1 hour)  |   Type of failure:
     Blocked By:                           |  None/Unknown
Related Tickets:                           |         Test Case:
                                           |          Blocking:
-------------------------------------------+-------------------------------
 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)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8939>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list