0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

Kernel: Update to new timers

This commit is contained in:
Ondrej Zajicek (work) 2017-06-14 13:15:35 +02:00
parent d3fa9e84e9
commit 21f4f0f4b0
3 changed files with 25 additions and 28 deletions

View File

@ -68,7 +68,7 @@ kern_item:
| PERSIST bool { THIS_KRT->persist = $2; } | PERSIST bool { THIS_KRT->persist = $2; }
| SCAN TIME expr { | SCAN TIME expr {
/* Scan time of 0 means scan on startup only */ /* Scan time of 0 means scan on startup only */
THIS_KRT->scan_time = $3; THIS_KRT->scan_time = $3 S_;
} }
| LEARN bool { | LEARN bool {
THIS_KRT->learn = $2; THIS_KRT->learn = $2;
@ -103,7 +103,7 @@ kif_item:
| INTERFACE kif_iface | INTERFACE kif_iface
| SCAN TIME expr { | SCAN TIME expr {
/* Scan time of 0 means scan on startup only */ /* Scan time of 0 means scan on startup only */
THIS_KIF->scan_time = $3; THIS_KIF->scan_time = $3 S_;
} }
; ;

View File

@ -87,7 +87,7 @@ krt_io_init(void)
struct kif_proto *kif_proto; struct kif_proto *kif_proto;
static struct kif_config *kif_cf; static struct kif_config *kif_cf;
static timer *kif_scan_timer; static timer *kif_scan_timer;
static bird_clock_t kif_last_shot; static btime kif_last_shot;
static struct kif_iface_config kif_default_iface = {}; static struct kif_iface_config kif_default_iface = {};
@ -105,25 +105,25 @@ kif_scan(timer *t)
struct kif_proto *p = t->data; struct kif_proto *p = t->data;
KRT_TRACE(p, D_EVENTS, "Scanning interfaces"); KRT_TRACE(p, D_EVENTS, "Scanning interfaces");
kif_last_shot = now; kif_last_shot = current_time();
kif_do_scan(p); kif_do_scan(p);
} }
static void static void
kif_force_scan(void) kif_force_scan(void)
{ {
if (kif_proto && kif_last_shot + 2 < now) if (kif_proto && ((kif_last_shot + 2 S) < current_time()))
{ {
kif_scan(kif_scan_timer); kif_scan(kif_scan_timer);
tm_start(kif_scan_timer, ((struct kif_config *) kif_proto->p.cf)->scan_time); tm2_start(kif_scan_timer, ((struct kif_config *) kif_proto->p.cf)->scan_time);
} }
} }
void void
kif_request_scan(void) kif_request_scan(void)
{ {
if (kif_proto && (kif_scan_timer->expires TO_S > (now + 1))) if (kif_proto && (kif_scan_timer->expires > (current_time() + 1 S)))
tm_start(kif_scan_timer, 1); tm2_start(kif_scan_timer, 1 S);
} }
static struct proto * static struct proto *
@ -144,12 +144,9 @@ kif_start(struct proto *P)
kif_sys_start(p); kif_sys_start(p);
/* Start periodic interface scanning */ /* Start periodic interface scanning */
kif_scan_timer = tm_new(P->pool); kif_scan_timer = tm2_new_init(P->pool, kif_scan, p, KIF_CF->scan_time, 0);
kif_scan_timer->hook = kif_scan;
kif_scan_timer->data = p;
kif_scan_timer->recurrent = KIF_CF->scan_time S;
kif_scan(kif_scan_timer); kif_scan(kif_scan_timer);
tm_start(kif_scan_timer, KIF_CF->scan_time); tm2_start(kif_scan_timer, KIF_CF->scan_time);
return PS_UP; return PS_UP;
} }
@ -159,7 +156,7 @@ kif_shutdown(struct proto *P)
{ {
struct kif_proto *p = (struct kif_proto *) P; struct kif_proto *p = (struct kif_proto *) P;
tm_stop(kif_scan_timer); tm2_stop(kif_scan_timer);
kif_sys_shutdown(p); kif_sys_shutdown(p);
kif_proto = NULL; kif_proto = NULL;
@ -177,10 +174,10 @@ kif_reconfigure(struct proto *p, struct proto_config *new)
if (o->scan_time != n->scan_time) if (o->scan_time != n->scan_time)
{ {
tm_stop(kif_scan_timer); tm2_stop(kif_scan_timer);
kif_scan_timer->recurrent = n->scan_time S; kif_scan_timer->recurrent = n->scan_time;
kif_scan(kif_scan_timer); kif_scan(kif_scan_timer);
tm_start(kif_scan_timer, n->scan_time); tm2_start(kif_scan_timer, n->scan_time);
} }
if (!EMPTY_LIST(o->iface_list) || !EMPTY_LIST(n->iface_list)) if (!EMPTY_LIST(o->iface_list) || !EMPTY_LIST(n->iface_list))
@ -212,7 +209,7 @@ kif_init_config(int class)
cf_error("Kernel device protocol already defined"); cf_error("Kernel device protocol already defined");
kif_cf = (struct kif_config *) proto_config_new(&proto_unix_iface, class); kif_cf = (struct kif_config *) proto_config_new(&proto_unix_iface, class);
kif_cf->scan_time = 60; kif_cf->scan_time = 60 S;
init_list(&kif_cf->iface_list); init_list(&kif_cf->iface_list);
kif_sys_init_config(kif_cf); kif_sys_init_config(kif_cf);
@ -843,11 +840,11 @@ static void
krt_scan_timer_start(struct krt_proto *p) krt_scan_timer_start(struct krt_proto *p)
{ {
if (!krt_scan_count) if (!krt_scan_count)
krt_scan_timer = tm_new_set(krt_pool, krt_scan, NULL, 0, KRT_CF->scan_time); krt_scan_timer = tm2_new_init(krt_pool, krt_scan, NULL, KRT_CF->scan_time, 0);
krt_scan_count++; krt_scan_count++;
tm_start(krt_scan_timer, 1); tm2_start(krt_scan_timer, 1 S);
} }
static void static void
@ -865,7 +862,7 @@ krt_scan_timer_stop(struct krt_proto *p UNUSED)
static void static void
krt_scan_timer_kick(struct krt_proto *p UNUSED) krt_scan_timer_kick(struct krt_proto *p UNUSED)
{ {
tm_start(krt_scan_timer, 0); tm2_start(krt_scan_timer, 0);
} }
#else #else
@ -885,20 +882,20 @@ krt_scan(timer *t)
static void static void
krt_scan_timer_start(struct krt_proto *p) krt_scan_timer_start(struct krt_proto *p)
{ {
p->scan_timer = tm_new_set(p->p.pool, krt_scan, p, 0, KRT_CF->scan_time); p->scan_timer = tm2_new_init(p->p.pool, krt_scan, p, KRT_CF->scan_time, 0);
tm_start(p->scan_timer, 1); tm2_start(p->scan_timer, 1 S);
} }
static void static void
krt_scan_timer_stop(struct krt_proto *p) krt_scan_timer_stop(struct krt_proto *p)
{ {
tm_stop(p->scan_timer); tm2_stop(p->scan_timer);
} }
static void static void
krt_scan_timer_kick(struct krt_proto *p) krt_scan_timer_kick(struct krt_proto *p)
{ {
tm_start(p->scan_timer, 0); tm2_start(p->scan_timer, 0);
} }
#endif #endif
@ -1174,7 +1171,7 @@ krt_init_config(int class)
#endif #endif
krt_cf = (struct krt_config *) proto_config_new(&proto_unix_kernel, class); krt_cf = (struct krt_config *) proto_config_new(&proto_unix_kernel, class);
krt_cf->scan_time = 60; krt_cf->scan_time = 60 S;
krt_sys_init_config(krt_cf); krt_sys_init_config(krt_cf);
return (struct proto_config *) krt_cf; return (struct proto_config *) krt_cf;

View File

@ -46,8 +46,8 @@ extern struct protocol proto_unix_kernel;
struct krt_config { struct krt_config {
struct proto_config c; struct proto_config c;
struct krt_params sys; /* Sysdep params */ struct krt_params sys; /* Sysdep params */
btime scan_time; /* How often we re-scan routes */
int persist; /* Keep routes when we exit */ int persist; /* Keep routes when we exit */
int scan_time; /* How often we re-scan routes */
int learn; /* Learn routes from other sources */ int learn; /* Learn routes from other sources */
int devroutes; /* Allow export of device routes */ int devroutes; /* Allow export of device routes */
int graceful_restart; /* Regard graceful restart recovery */ int graceful_restart; /* Regard graceful restart recovery */
@ -100,7 +100,7 @@ struct kif_config {
struct kif_params sys; /* Sysdep params */ struct kif_params sys; /* Sysdep params */
list iface_list; /* List of iface configs (struct kif_iface_config) */ list iface_list; /* List of iface configs (struct kif_iface_config) */
int scan_time; /* How often we re-scan interfaces */ btime scan_time; /* How often we re-scan interfaces */
}; };
struct kif_iface_config { struct kif_iface_config {