From 025525266f6861437ca54aca2a86eb505a486baf Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Thu, 1 Jun 2017 12:33:20 +0200 Subject: Timers: Replace old timers with microsecond timers The old timer interface is still kept, but implemented by new timers. The plan is to switch from the old inteface to the new interface, then clean it up. --- lib/birdlib.h | 2 +- lib/tbf.c | 1 + lib/timer.c | 11 +++++++++++ lib/timer.h | 12 ++++++++---- 4 files changed, 21 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/birdlib.h b/lib/birdlib.h index 317b5202..a0826aab 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -9,7 +9,6 @@ #ifndef _BIRD_BIRDLIB_H_ #define _BIRD_BIRDLIB_H_ -#include "sysdep/unix/timer.h" #include "lib/alloca.h" /* Ugly structure offset handling macros */ @@ -70,6 +69,7 @@ static inline int u64_cmp(u64 i1, u64 i2) /* Microsecond time */ typedef s64 btime; +typedef s64 bird_clock_t; #define S_ *1000000 #define MS_ *1000 diff --git a/lib/tbf.c b/lib/tbf.c index 39e18e57..c1dafee8 100644 --- a/lib/tbf.c +++ b/lib/tbf.c @@ -8,6 +8,7 @@ */ #include "nest/bird.h" +#include "lib/timer.h" void tbf_update(struct tbf *f) diff --git a/lib/timer.c b/lib/timer.c index 7ca0bdaa..2c08b353 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -56,6 +56,17 @@ current_time(void) return timeloop_current()->last_time; } +btime +current_real_time(void) +{ + struct timeloop *loop = timeloop_current(); + + if (!loop->real_time) + times_update_real_time(loop); + + return loop->real_time; +} + #define TIMER_LESS(a,b) ((a)->expires < (b)->expires) #define TIMER_SWAP(heap,a,b,t) (t = heap[a], heap[a] = heap[b], heap[b] = t, \ diff --git a/lib/timer.h b/lib/timer.h index 88c53547..b70ac48d 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -44,6 +44,11 @@ static inline timer2 *timers_first(struct timeloop *loop) extern struct timeloop main_timeloop; btime current_time(void); +btime current_real_time(void); + +#define now (current_time() TO_S) +#define now_real (current_real_time() TO_S) +extern btime boot_time; timer2 *tm2_new(pool *p); void tm2_set(timer2 *t, btime when); @@ -59,8 +64,8 @@ tm2_active(timer2 *t) static inline btime tm2_remains(timer2 *t) { - btime now = current_time(); - return (t->expires > now) ? (t->expires - now) : 0; + btime now_ = current_time(); + return (t->expires > now_) ? (t->expires - now_) : 0; } static inline timer2 * @@ -81,18 +86,17 @@ tm2_set_max(timer2 *t, btime when) tm2_set(t, when); } -/* static inline void tm2_start_max(timer2 *t, btime after) { btime rem = tm2_remains(t); tm2_start(t, MAX_(rem, after)); } -*/ /* In sysdep code */ void times_init(struct timeloop *loop); void times_update(struct timeloop *loop); +void times_update_real_time(struct timeloop *loop); /* For I/O loop */ void timers_init(struct timeloop *loop, pool *p); -- cgit v1.2.3