]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Time accounting must be done by coarse timers
authorMaria Matejka <mq@ucw.cz>
Mon, 10 Jun 2024 21:09:05 +0000 (23:09 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 12 Jun 2024 12:48:33 +0000 (14:48 +0200)
on some ARM, the precise timers are too slow to be actually useful

aclocal.m4
configure.ac
sysdep/unix/io-loop.c

index ffe677060edd349e0baae3ecbf77df8bbf7790a5..48285b21918032c25b1df97753076a9338d04ba3 100644 (file)
@@ -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 <time.h>
+           ],
+           [
+             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(
index 68e8b31266b557fb26af510120b602476a59e610..ae8c81f798301bd2f9779c4923d3bee3883f9ddc 100644 (file)
@@ -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'`
index 0ee5718dfd9181067d37c6bb52a3c2edecaff30a..ec8aa72961cf1e7ffcca526727c9d44ffd2e233f 100644 (file)
@@ -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;