X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FGetTime.c;h=626882b205a3baeb6bb93a2fea33fbc41aeb7b85;hb=c6eadadbefe2ec5709e9d31893f79c4ff78754b4;hp=db7378d62b21923a84f9753fa80117dc04615f0c;hpb=fe07f054d7ae5e10b14d5fed730fe4424dabd587;p=ghc-hetmet.git diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c index db7378d..626882b 100644 --- a/rts/posix/GetTime.c +++ b/rts/posix/GetTime.c @@ -134,15 +134,17 @@ Ticks getThreadCPUTime(void) } return ((usec * TICKS_PER_SECOND) / 1000000); -#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_THREAD_CPUTIME_ID) - // clock_gettime() gives us per-thread CPU time. It isn't - // reliable on Linux, but it's the best we have. - struct timespec ts; - int res; - res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); - if (res == 0) { - return ((Ticks)ts.tv_sec * TICKS_PER_SECOND + - ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000); +#elif defined(HAVE_CLOCK_GETTIME) && defined (_POSIX_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF) + if (sysconf(_POSIX_THREAD_CPUTIME) != -1) { + // clock_gettime() gives us per-thread CPU time. It isn't + // reliable on Linux, but it's the best we have. + struct timespec ts; + int res; + res = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + if (res == 0) { + return ((Ticks)ts.tv_sec * TICKS_PER_SECOND + + ((Ticks)ts.tv_nsec * TICKS_PER_SECOND) / 1000000000); + } } #endif return getProcessCPUTime();