diff --git a/aclocal.m4 b/aclocal.m4 index ffe67706..48285b21 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -120,6 +120,31 @@ AC_DEFUN([BIRD_CHECK_MPLS_KERNEL], ) ]) +AC_DEFUN([BIRD_CHECK_CLOCK], +[ + AC_CACHE_CHECK( + [for $1], + [bird_cv_clock_$1], + [ + AC_COMPILE_IFELSE( + [ + AC_LANG_PROGRAM( + [ + #include + ], + [ + struct timespec tv; + clock_gettime($1, &tv); + ] + ) + ], + [bird_cv_clock_$1=yes], + [bird_cv_clock_$1=no] + ) + ] + ) +]) + AC_DEFUN([BIRD_CHECK_ANDROID_GLOB], [ AC_CACHE_CHECK( diff --git a/configure.ac b/configure.ac index 68e8b312..ae8c81f7 100644 --- a/configure.ac +++ b/configure.ac @@ -308,6 +308,18 @@ if test "$enable_mpls_kernel" != no ; then fi fi +BIRD_CHECK_CLOCK(CLOCK_MONOTONIC) +if test "$bird_cv_clock_CLOCK_MONOTONIC" != yes ; then + AC_MSG_ERROR([Monotonic clock not supported]) +fi + +BIRD_CHECK_CLOCK(CLOCK_MONOTONIC_COARSE) +if test "$bird_cv_clock_CLOCK_MONOTONIC_COARSE" != yes ; then + AC_DEFINE([HAVE_CLOCK_MONOTONIC_COARSE], [0], [Define to 1 if coarse clock is available]) +else + AC_DEFINE([HAVE_CLOCK_MONOTONIC_COARSE], [1], [Define to 1 if coarse clock is available]) +fi + # temporarily removed "mrt" from all_protocols to speed up 3.0-alpha1 release all_protocols="aggregator bfd babel bgp l3vpn ospf pipe radv rip rpki static" all_protocols=`echo $all_protocols | sed 's/ /,/g'` diff --git a/sysdep/unix/io-loop.c b/sysdep/unix/io-loop.c index 0ee5718d..ec8aa729 100644 --- a/sysdep/unix/io-loop.c +++ b/sysdep/unix/io-loop.c @@ -42,11 +42,15 @@ static struct birdloop *birdloop_new_no_pickup(pool *pp, uint order, const char * BIRD for such a long time, please implement some means of overflow prevention. */ +#if ! HAVE_CLOCK_MONOTONIC_COARSE +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC +#endif + static struct timespec ns_begin; static void ns_init(void) { - if (clock_gettime(CLOCK_MONOTONIC, &ns_begin)) + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ns_begin)) bug("clock_gettime: %m"); } @@ -55,7 +59,7 @@ static void ns_init(void) u64 ns_now(void) { struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts)) + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts)) bug("clock_gettime: %m"); return (u64) (ts.tv_sec - ns_begin.tv_sec) * NSEC_IN_SEC + ts.tv_nsec - ns_begin.tv_nsec;