diff options
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/io.c | 42 | ||||
-rw-r--r-- | sysdep/unix/krt.c | 6 | ||||
-rw-r--r-- | sysdep/unix/main.c | 2 | ||||
-rw-r--r-- | sysdep/unix/timer.h | 91 |
4 files changed, 60 insertions, 81 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 13635586..d3506d75 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -122,11 +122,13 @@ tracked_fopen(pool *p, char *name, char *mode) * for the other fields see |timer.h|. */ +#if 0 #define NEAR_TIMER_LIMIT 4 static list near_timers, far_timers; static bird_clock_t first_far_timer = TIME_INFINITY; + /* now must be different from 0, because 0 is a special value in timer->expires */ bird_clock_t now = 1, now_real, boot_time; @@ -183,7 +185,6 @@ init_times(void) log(L_WARN "Monotonic timer is missing"); } - static void tm_free(resource *r) { @@ -382,6 +383,7 @@ tm_shot(void) t->hook(t); } } +#endif /** * tm_parse_datetime - parse a date and time @@ -484,6 +486,8 @@ tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t) * Time clock */ +btime boot_time; + void times_init(struct timeloop *loop) { @@ -520,6 +524,19 @@ times_update(struct timeloop *loop) loop->real_time = 0; } +void +times_update_real_time(struct timeloop *loop) +{ + struct timespec ts; + int rv; + + rv = clock_gettime(CLOCK_REALTIME, &ts); + if (rv < 0) + die("clock_gettime: %m"); + + loop->real_time = ((s64) ts.tv_sec S) + (ts.tv_nsec / 1000); +} + /** * DOC: Sockets @@ -2349,9 +2366,6 @@ io_update_time(void) struct timespec ts; int rv; - if (!clock_monotonic_available) - return; - /* * This is third time-tracking procedure (after update_times() above and * times_update() in BFD), dedicated to internal event log and latency @@ -2490,14 +2504,12 @@ volatile int async_shutdown_flag; void io_init(void) { - init_list(&near_timers); - init_list(&far_timers); init_list(&sock_list); init_list(&global_event_list); krt_io_init(); - init_times(); - update_times(); - boot_time = now; + // XXX init_times(); + // XXX update_times(); + boot_time = current_time(); srandom((int) now_real); } @@ -2508,7 +2520,6 @@ void io_loop(void) { int poll_tout, timeout; - time_t tout; int nfds, events, pout; timer2 *t; sock *s; @@ -2522,17 +2533,10 @@ io_loop(void) times_update(&main_timeloop); events = ev_run_list(&global_event_list); timers_fire(&main_timeloop); - timers: - update_times(); - tout = tm_first_shot(); - if (tout <= now) - { - tm_shot(); - goto timers; - } io_close_event(); - poll_tout = (events ? 0 : MIN(tout - now, 3)) * 1000; /* Time in milliseconds */ + // FIXME + poll_tout = (events ? 0 : 3000); /* Time in milliseconds */ if (t = timers_first(&main_timeloop)) { times_update(&main_timeloop); diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index 0349a09f..a5ec8a39 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -122,7 +122,7 @@ kif_force_scan(void) void kif_request_scan(void) { - if (kif_proto && kif_scan_timer->expires > now) + if (kif_proto && (kif_scan_timer->expires TO_S > (now + 1))) tm_start(kif_scan_timer, 1); } @@ -147,7 +147,7 @@ kif_start(struct proto *P) kif_scan_timer = tm_new(P->pool); kif_scan_timer->hook = kif_scan; kif_scan_timer->data = p; - kif_scan_timer->recurrent = KIF_CF->scan_time; + kif_scan_timer->recurrent = KIF_CF->scan_time S; kif_scan(kif_scan_timer); tm_start(kif_scan_timer, KIF_CF->scan_time); @@ -178,7 +178,7 @@ kif_reconfigure(struct proto *p, struct proto_config *new) if (o->scan_time != n->scan_time) { tm_stop(kif_scan_timer); - kif_scan_timer->recurrent = n->scan_time; + kif_scan_timer->recurrent = n->scan_time S; kif_scan(kif_scan_timer); tm_start(kif_scan_timer, n->scan_time); } diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 396310fd..6cab21ac 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -57,7 +57,7 @@ async_dump(void) rdump(&root_pool); sk_dump_all(); - tm_dump_all(); + // XXXX tm_dump_all(); if_dump_all(); neigh_dump_all(); rta_dump_all(); diff --git a/sysdep/unix/timer.h b/sysdep/unix/timer.h index aa3ed143..1c4f6e3b 100644 --- a/sysdep/unix/timer.h +++ b/sysdep/unix/timer.h @@ -11,58 +11,38 @@ #include <time.h> -#include "lib/resource.h" - -typedef time_t bird_clock_t; /* Use instead of time_t */ - -typedef struct timer { - resource r; - void (*hook)(struct timer *); - void *data; - uint randomize; /* Amount of randomization */ - uint recurrent; /* Timer recurrence */ - node n; /* Internal link */ - bird_clock_t expires; /* 0=inactive */ -} timer; - -timer *tm_new(pool *); -void tm_start(timer *, uint after); -void tm_stop(timer *); -void tm_dump_all(void); - -extern bird_clock_t now; /* Relative, monotonic time in seconds */ -extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ -extern bird_clock_t boot_time; - -static inline int -tm_active(timer *t) -{ - return t->expires != 0; -} - -static inline bird_clock_t -tm_remains(timer *t) -{ - return t->expires ? t->expires - now : 0; -} - -static inline void -tm_start_max(timer *t, bird_clock_t after) -{ - bird_clock_t rem = tm_remains(t); - tm_start(t, (rem > after) ? rem : after); -} - -static inline timer * -tm_new_set(pool *p, void (*hook)(struct timer *), void *data, uint rand, uint rec) -{ - timer *t = tm_new(p); - t->hook = hook; - t->data = data; - t->randomize = rand; - t->recurrent = rec; - return t; -} +#include "lib/birdlib.h" +#include "lib/timer.h" + + +typedef struct timer2 timer; + +static inline timer *tm_new(pool *p) +{ return (void *) tm2_new(p); } + +static inline void tm_start(timer *t, bird_clock_t after) +{ tm2_start(t, after S_); } + +static inline void tm_stop(timer *t) +{ tm2_stop(t); } + +// void tm_dump_all(void); + +//extern bird_clock_t now; /* Relative, monotonic time in seconds */ +//extern bird_clock_t now_real; /* Time in seconds since fixed known epoch */ +//extern bird_clock_t boot_time; + +static inline int tm_active(timer *t) +{ return tm2_active(t); } + +static inline bird_clock_t tm_remains(timer *t) +{ return tm2_remains(t) TO_S; } + +static inline void tm_start_max(timer *t, bird_clock_t after) +{ tm2_start_max(t, after S_); } + +static inline timer * tm_new_set(pool *p, void (*hook)(timer *), void *data, uint rand, uint rec) +{ return tm2_new_init(p, hook, data, rec S_, rand S_); } struct timeformat { @@ -77,12 +57,7 @@ bird_clock_t tm_parse_datetime(char *); /* Convert date to bird_clock_t */ void tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t); -#define TIME_T_IS_64BIT (sizeof(time_t) == 8) -#define TIME_T_IS_SIGNED ((time_t) -1 < 0) +#define TIME_INFINITY ((s64) 0x7fffffffffffffff) -#define TIME_INFINITY \ - ((time_t) (TIME_T_IS_SIGNED ? \ - (TIME_T_IS_64BIT ? 0x7fffffffffffffff : 0x7fffffff): \ - (TIME_T_IS_64BIT ? 0xffffffffffffffff : 0xffffffff))) #endif |