aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/main.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2021-03-06 12:26:28 +0100
committerDamjan Marion <damarion@cisco.com>2021-03-26 16:33:42 +0100
commitfd8deb48c7ad63b47c5d7465ceefcadef0316f93 (patch)
tree3e5f319c7c57f526a6e571fd96847563bedf2706 /src/vlib/main.c
parentf553a2cbbb8cca84ebf033335ebd2cd26dc19d69 (diff)
vlib: split vlib_main_t into global and per-thread
Type: refactor Change-Id: I8b273bc3bf16aa360f031f1b2692f766e5fc4613 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/main.c')
-rw-r--r--src/vlib/main.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/vlib/main.c b/src/vlib/main.c
index 62da7b9ff0a..bee63970f3d 100644
--- a/src/vlib/main.c
+++ b/src/vlib/main.c
@@ -614,7 +614,7 @@ vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
if (n->type == VLIB_NODE_TYPE_PROCESS)
{
/* Nothing to do for PROCESS nodes except in main thread */
- if (vm != &vlib_global_main)
+ if (vm != vlib_get_first_main ())
return;
vlib_process_t *p = vlib_get_process_from_node (vm, n);
@@ -747,10 +747,10 @@ elog_save_buffer (vlib_main_t * vm,
void
vlib_post_mortem_dump (void)
{
- vlib_main_t *vm = &vlib_global_main;
+ vlib_global_main_t *vgm = vlib_get_global_main ();
- for (int i = 0; i < vec_len (vm->post_mortem_callbacks); i++)
- (vm->post_mortem_callbacks[i]) ();
+ for (int i = 0; i < vec_len (vgm->post_mortem_callbacks); i++)
+ (vgm->post_mortem_callbacks[i]) ();
}
/* *INDENT-OFF* */
@@ -901,7 +901,7 @@ vlib_elog_main_loop_event (vlib_main_t * vm,
u32 node_index,
u64 time, u32 n_vectors, u32 is_return)
{
- vlib_main_t *evm = &vlib_global_main;
+ vlib_main_t *evm = vlib_get_first_main ();
elog_main_t *em = vlib_get_elog_main ();
int enabled = evm->elog_trace_graph_dispatch |
evm->elog_trace_graph_circuit;
@@ -1091,7 +1091,8 @@ dispatch_node (vlib_main_t * vm,
nm->input_node_counts_by_state[VLIB_NODE_STATE_INTERRUPT] -= 1;
nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] += 1;
- if (PREDICT_FALSE (vlib_global_main.elog_trace_graph_dispatch))
+ if (PREDICT_FALSE (
+ vlib_get_first_main ()->elog_trace_graph_dispatch))
{
vlib_worker_thread_t *w = vlib_worker_threads
+ vm->thread_index;
@@ -1126,7 +1127,8 @@ dispatch_node (vlib_main_t * vm,
+ vm->thread_index;
node->flags |=
VLIB_NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
- if (PREDICT_FALSE (vlib_global_main.elog_trace_graph_dispatch))
+ if (PREDICT_FALSE (
+ vlib_get_first_main ()->elog_trace_graph_dispatch))
{
ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e,
w->elog_track);
@@ -1794,26 +1796,26 @@ vlib_worker_loop (vlib_main_t * vm)
vlib_main_or_worker_loop (vm, /* is_main */ 0);
}
-vlib_main_t vlib_global_main;
+vlib_global_main_t vlib_global_main;
void
vlib_add_del_post_mortem_callback (void *cb, int is_add)
{
- vlib_main_t *vm = &vlib_global_main;
+ vlib_global_main_t *vgm = vlib_get_global_main ();
int i;
if (is_add == 0)
{
- for (i = vec_len (vm->post_mortem_callbacks) - 1; i >= 0; i--)
- if (vm->post_mortem_callbacks[i] == cb)
- vec_del1 (vm->post_mortem_callbacks, i);
+ for (i = vec_len (vgm->post_mortem_callbacks) - 1; i >= 0; i--)
+ if (vgm->post_mortem_callbacks[i] == cb)
+ vec_del1 (vgm->post_mortem_callbacks, i);
return;
}
- for (i = 0; i < vec_len (vm->post_mortem_callbacks); i++)
- if (vm->post_mortem_callbacks[i] == cb)
+ for (i = 0; i < vec_len (vgm->post_mortem_callbacks); i++)
+ if (vgm->post_mortem_callbacks[i] == cb)
return;
- vec_add1 (vm->post_mortem_callbacks, cb);
+ vec_add1 (vgm->post_mortem_callbacks, cb);
}
static void
@@ -1836,6 +1838,7 @@ elog_post_mortem_dump (void)
static clib_error_t *
vlib_main_configure (vlib_main_t * vm, unformat_input_t * input)
{
+ vlib_global_main_t *vgm = vlib_get_global_main ();
int turn_on_mem_trace = 0;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -1844,9 +1847,9 @@ vlib_main_configure (vlib_main_t * vm, unformat_input_t * input)
turn_on_mem_trace = 1;
else if (unformat (input, "elog-events %d",
- &vm->configured_elog_ring_size))
- vm->configured_elog_ring_size =
- 1 << max_log2 (vm->configured_elog_ring_size);
+ &vgm->configured_elog_ring_size))
+ vgm->configured_elog_ring_size =
+ 1 << max_log2 (vgm->configured_elog_ring_size);
else if (unformat (input, "elog-post-mortem-dump"))
vlib_add_del_post_mortem_callback (elog_post_mortem_dump,
/* is_add */ 1);
@@ -1923,21 +1926,22 @@ vl_api_get_elog_trace_api_messages (void)
int
vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
{
+ vlib_global_main_t *vgm = vlib_get_global_main ();
clib_error_t *volatile error;
vlib_node_main_t *nm = &vm->node_main;
vm->queue_signal_callback = placeholder_queue_signal_callback;
/* Reconfigure event log which is enabled very early */
- if (vm->configured_elog_ring_size &&
- vm->configured_elog_ring_size != vm->elog_main.event_ring_size)
- elog_resize (&vm->elog_main, vm->configured_elog_ring_size);
+ if (vgm->configured_elog_ring_size &&
+ vgm->configured_elog_ring_size != vgm->elog_main.event_ring_size)
+ elog_resize (&vgm->elog_main, vgm->configured_elog_ring_size);
vl_api_set_elog_main (vlib_get_elog_main ());
(void) vl_api_set_elog_trace_api_messages (1);
/* Default name. */
- if (!vm->name)
- vm->name = "VLIB";
+ if (!vgm->name)
+ vgm->name = "VLIB";
if ((error = vlib_physmem_init (vm)))
{
@@ -2005,8 +2009,8 @@ vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
}
/* See unix/main.c; most likely already set up */
- if (vm->init_functions_called == 0)
- vm->init_functions_called = hash_create (0, /* value bytes */ 0);
+ if (vgm->init_functions_called == 0)
+ vgm->init_functions_called = hash_create (0, /* value bytes */ 0);
if ((error = vlib_call_all_init_functions (vm)))
goto done;
@@ -2048,7 +2052,7 @@ vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
vm->damping_constant = exp (-1.0 / 20.0);
/* Sort per-thread init functions before we start threads */
- vlib_sort_init_exit_functions (&vm->worker_init_function_registrations);
+ vlib_sort_init_exit_functions (&vgm->worker_init_function_registrations);
/* Call all main loop enter functions. */
{