Commit edc059a4 authored by Austin Seipp's avatar Austin Seipp

Fix autoconf's check for create_timer()

GHC build system have custom autoconf check for `create_timer()`
function from librt. Check description says that it checks for
`CLOCK_REALTIME` timer, but checking code also checks for
`CLOCK_PROCESS_CPUTIME_ID` timer, which is not commonly present (for
example, FreeBSD doesn't have it). This makes whole check fail despite
the fact that FreeBSD have `create_timer()` call and supports
`CLOCK_REALTIME`. As a consequence, GHC RTS falls back to using SIGALRM
for its timing machinery. Not only it's very ancient codepath, it also
break some FFI bindings to C code that isn't prepared for syscall
interruption caused by SIGALRM delivery.

Grepping through ghc source code reveals that `USE_TIMER_CREATE`
defininition in the config.h doesn't imply having
`CLOCK_PROCESS_CPUTIME_ID`. The only place where
`CLOCK_PROCESS_CPUTIME_ID` is used is rts/posix/GetTime.c and this code
handles the absence of `CLOCK_PROCESS_CPUTIME_ID` gracefully.

This patch makes autoconf checking code to check only for
`timer_create(CLOCK_REALTIME, ...)` and fixes check description.

Reviewed By: austin

Differential Revision:
parent 485dba86
......@@ -1654,7 +1654,7 @@ then
# We can't test timer_create when we're cross-compiling, so we
# optimistiaclly assume that it actually works properly.
AC_DEFINE([USE_TIMER_CREATE], 1, [Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)])
AC_DEFINE([USE_TIMER_CREATE], 1, [Define to 1 if we can use timer_create(CLOCK_REALTIME,...)])
AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)],
......@@ -1715,36 +1715,6 @@ int main(int argc, char *argv[])
if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &timer) != 0) {
fprintf(stderr,"No CLOCK_PROCESS_CPUTIME_ID timer\n");
it.it_value.tv_sec = 0;
it.it_value.tv_nsec = 1;
it.it_interval = it.it_value;
if (timer_settime(timer, 0, &it, NULL) != 0) {
fprintf(stderr,"settime problem\n");
tock = 0;
for(n = 3; n < 20000; n++){
for(m = 2; m <= n/2; m++){
if (!(n%m)) count++;
if (tock) goto out;
if (!tock) {
fprintf(stderr,"no CLOCK_PROCESS_CPUTIME_ID signal\n");
if (timer_create(CLOCK_REALTIME, &ev, &timer) != 0) {
fprintf(stderr,"No CLOCK_REALTIME timer\n");
......@@ -1777,7 +1747,7 @@ out:
case $fptools_cv_timer_create_works in
[Define to 1 if we can use timer_create(CLOCK_PROCESS_CPUTIME_ID,...)]);;
[Define to 1 if we can use timer_create(CLOCK_REALTIME,...)]);;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment