summaryrefslogtreecommitdiff
path: root/sysdep/unix
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/unix')
-rw-r--r--sysdep/unix/io.c42
-rw-r--r--sysdep/unix/main.c2
2 files changed, 44 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 0cf48c9d..ebd380ba 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -37,6 +37,7 @@
#include "sysdep/unix/timer.h"
#include "lib/socket.h"
#include "lib/event.h"
+#include "lib/timer.h"
#include "lib/string.h"
#include "nest/iface.h"
@@ -479,6 +480,47 @@ tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t)
}
+/*
+ * Time clock
+ */
+
+void
+times_init(struct timeloop *loop)
+{
+ struct timespec ts;
+ int rv;
+
+ rv = clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (rv < 0)
+ die("Monotonic clock is missing");
+
+ if ((ts.tv_sec < 0) || (((s64) ts.tv_sec) > ((s64) 1 << 40)))
+ log(L_WARN "Monotonic clock is crazy");
+
+ loop->last_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+ loop->real_time = 0;
+}
+
+void
+times_update(struct timeloop *loop)
+{
+ struct timespec ts;
+ int rv;
+
+ rv = clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (rv < 0)
+ die("clock_gettime: %m");
+
+ btime new_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000);
+
+ if (new_time < loop->last_time)
+ log(L_ERR "Monotonic clock is broken");
+
+ loop->last_time = new_time;
+ loop->real_time = 0;
+}
+
+
/**
* DOC: Sockets
*
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index c1b92b7e..396310fd 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -27,6 +27,7 @@
#include "lib/resource.h"
#include "lib/socket.h"
#include "lib/event.h"
+#include "lib/timer.h"
#include "lib/string.h"
#include "nest/route.h"
#include "nest/protocol.h"
@@ -820,6 +821,7 @@ main(int argc, char **argv)
log_switch(debug_flag, NULL, NULL);
resource_init();
+ timer_init();
olock_init();
io_init();
rt_init();