vlib: add ASSERT to vlib_time_now(...)
Calling vlib_time_now (&vlib_global_main) from a worker thread is a bad
mistake. ASSERT (vm->thread_index == __os_thread_index) will catch it.
Type: improvement
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I55af6de84e06143f8f43adc62103b77267a7a441
diff --git a/src/vlib/main.h b/src/vlib/main.h
index 598c3ba..d6b2d1f 100644
--- a/src/vlib/main.h
+++ b/src/vlib/main.h
@@ -290,6 +290,13 @@
always_inline f64
vlib_time_now (vlib_main_t * vm)
{
+#if CLIB_DEBUG > 0
+ extern __thread uword __os_thread_index;
+#endif
+ /*
+ * Make sure folks don't pass &vlib_global_main from a worker thread.
+ */
+ ASSERT (vm->thread_index == __os_thread_index);
return clib_time_now (&vm->clib_time) + vm->time_offset;
}
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 0270704..0956b2f 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -1676,7 +1676,7 @@
wrk->new_head = clib_llist_make_head (wrk->event_elts, evt_list);
wrk->old_head = clib_llist_make_head (wrk->event_elts, evt_list);
wrk->vm = vlib_mains[i];
- wrk->last_vlib_time = vlib_time_now (vlib_mains[i]);
+ wrk->last_vlib_time = vlib_time_now (vm);
wrk->last_vlib_us_time = wrk->last_vlib_time * CLIB_US_TIME_FREQ;
vec_validate (wrk->session_to_enqueue, smm->last_transport_proto_type);
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index df3d61d..3703a4a 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -1258,13 +1258,14 @@
static void
tcp_initialize_timer_wheels (tcp_main_t * tm)
{
+ vlib_main_t *vm = vlib_get_main ();
tw_timer_wheel_16t_2w_512sl_t *tw;
/* *INDENT-OFF* */
foreach_vlib_main (({
tw = &tm->wrk_ctx[ii].timer_wheel;
tw_timer_wheel_init_16t_2w_512sl (tw, tcp_expired_timers_dispatch,
TCP_TIMER_TICK, ~0);
- tw->last_run_time = vlib_time_now (this_vlib_main);
+ tw->last_run_time = vlib_time_now (vm);
}));
/* *INDENT-ON* */
}