diff options
author | Dave Barach <dave@barachs.net> | 2020-04-28 18:00:21 -0400 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2020-05-07 00:57:02 +0000 |
commit | 9b5d0b7108451d7c81bad113503d00f46b3bb1ea (patch) | |
tree | ea43e7870913ff5d98111a8bdd39312b61483510 | |
parent | 03dd7c08d4d745d936c20c42039e1badb9384e8f (diff) |
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: fix
Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I55af6de84e06143f8f43adc62103b77267a7a441
(cherry picked from commit 77d98382824ca211fb55fcf842931930ccfb3baa)
-rw-r--r-- | src/vlib/main.h | 7 | ||||
-rw-r--r-- | src/vnet/session/session.c | 2 | ||||
-rw-r--r-- | src/vnet/tcp/tcp.c | 3 |
3 files changed, 10 insertions, 2 deletions
diff --git a/src/vlib/main.h b/src/vlib/main.h index af6539efc75..20b8b464e34 100644 --- a/src/vlib/main.h +++ b/src/vlib/main.h @@ -278,6 +278,13 @@ void vlib_worker_loop (vlib_main_t * vm); 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 0b66cf87c4d..39ddf3ff274 100644 --- a/src/vnet/session/session.c +++ b/src/vnet/session/session.c @@ -1520,7 +1520,7 @@ session_manager_main_enable (vlib_main_t * vm) 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; if (num_threads > 1) diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c index 3fa242e6e5f..bbcf671c7b7 100644 --- a/src/vnet/tcp/tcp.c +++ b/src/vnet/tcp/tcp.c @@ -1535,13 +1535,14 @@ tcp_expired_timers_dispatch (u32 * expired_timers) 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* */ } |