diff options
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/buffer.c | 4 | ||||
-rw-r--r-- | src/vlib/buffer_node.h | 5 | ||||
-rw-r--r-- | src/vlib/global_funcs.h | 22 | ||||
-rw-r--r-- | src/vlib/node.c | 9 | ||||
-rw-r--r-- | src/vlib/node_cli.c | 20 | ||||
-rw-r--r-- | src/vlib/threads.c | 55 | ||||
-rw-r--r-- | src/vlib/threads.h | 2 | ||||
-rw-r--r-- | src/vlib/unix/cli.c | 4 | ||||
-rw-r--r-- | src/vlib/unix/input.c | 6 | ||||
-rw-r--r-- | src/vlib/unix/main.c | 2 |
10 files changed, 76 insertions, 53 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index e1c871c2a2a..f8cfb0357fa 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -569,7 +569,7 @@ vlib_buffer_pool_create (vlib_main_t * vm, char *name, u32 data_size, bp->data_size = data_size; bp->numa_node = m->numa_node; - vec_validate_aligned (bp->threads, vec_len (vlib_mains) - 1, + vec_validate_aligned (bp->threads, vlib_get_n_threads () - 1, CLIB_CACHE_LINE_BYTES); alloc_size = vlib_buffer_alloc_size (bm->ext_hdr_size, data_size); @@ -673,7 +673,7 @@ vlib_buffer_worker_init (vlib_main_t * vm) vec_foreach (bp, bm->buffer_pools) { clib_spinlock_lock (&bp->lock); - vec_validate_aligned (bp->threads, vec_len (vlib_mains) - 1, + vec_validate_aligned (bp->threads, vlib_get_n_threads () - 1, CLIB_CACHE_LINE_BYTES); clib_spinlock_unlock (&bp->lock); } diff --git a/src/vlib/buffer_node.h b/src/vlib/buffer_node.h index 0fa18d6dde2..17eb54e48be 100644 --- a/src/vlib/buffer_node.h +++ b/src/vlib/buffer_node.h @@ -545,7 +545,8 @@ vlib_buffer_enqueue_to_thread (vlib_main_t * vm, u32 frame_queue_index, { hf->n_vectors = VLIB_FRAME_SIZE; vlib_put_frame_queue_elt (hf); - vlib_mains[current_thread_index]->check_frame_queues = 1; + vlib_get_main_by_index (current_thread_index)->check_frame_queues = + 1; current_thread_index = ~0; ptd->handoff_queue_elt_by_thread_index[next_thread_index] = 0; hf = 0; @@ -574,7 +575,7 @@ vlib_buffer_enqueue_to_thread (vlib_main_t * vm, u32 frame_queue_index, if (1 || hf->n_vectors == hf->last_n_vectors) { vlib_put_frame_queue_elt (hf); - vlib_mains[i]->check_frame_queues = 1; + vlib_get_main_by_index (i)->check_frame_queues = 1; ptd->handoff_queue_elt_by_thread_index[i] = 0; } else diff --git a/src/vlib/global_funcs.h b/src/vlib/global_funcs.h index 9dd01fbfb0d..b1d636f7ce4 100644 --- a/src/vlib/global_funcs.h +++ b/src/vlib/global_funcs.h @@ -19,15 +19,33 @@ #ifndef included_vlib_global_funcs_h_ #define included_vlib_global_funcs_h_ +always_inline u32 +vlib_get_n_threads () +{ + return vec_len (vlib_mains); +} + always_inline vlib_main_t * -vlib_get_main (void) +vlib_get_main_by_index (u32 thread_index) { vlib_main_t *vm; - vm = vlib_mains[vlib_get_thread_index ()]; + vm = vlib_mains[thread_index]; ASSERT (vm); return vm; } +always_inline vlib_main_t * +vlib_get_main (void) +{ + return vlib_get_main_by_index (vlib_get_thread_index ()); +} + +always_inline vlib_main_t * +vlib_get_first_main (void) +{ + return vlib_get_main_by_index (0); +} + always_inline vlib_thread_main_t * vlib_get_thread_main () { diff --git a/src/vlib/node.c b/src/vlib/node.c index 618baecfde0..3c96d9d2a04 100644 --- a/src/vlib/node.c +++ b/src/vlib/node.c @@ -613,9 +613,9 @@ vlib_node_get_nodes (vlib_main_t * vm, u32 max_threads, int include_stats, if (vec_len (stat_vms) == 0) { - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { - stat_vm = vlib_mains[i]; + stat_vm = vlib_get_main_by_index (i); if (stat_vm) vec_add1 (stat_vms, stat_vm); } @@ -837,10 +837,11 @@ vlib_node_set_march_variant (vlib_main_t *vm, u32 node_index, { n->function = fnr->function; - for (int i = 0; i < vec_len (vlib_mains); i++) + for (int i = 0; i < vlib_get_n_threads (); i++) { vlib_node_runtime_t *nrt; - nrt = vlib_node_get_runtime (vlib_mains[i], n->index); + nrt = + vlib_node_get_runtime (vlib_get_main_by_index (i), n->index); nrt->function = fnr->function; } return 0; diff --git a/src/vlib/node_cli.c b/src/vlib/node_cli.c index 39fca6ea582..8cf57948cc4 100644 --- a/src/vlib/node_cli.c +++ b/src/vlib/node_cli.c @@ -210,14 +210,14 @@ show_node_graphviz (vlib_main_t * vm, /* Updating the stats for multithreaded use cases. * We need to dup the nodes to sum the stats from all threads.*/ nodes = vec_dup (nm->nodes); - for (i = 1; i < vec_len (vlib_mains); i++) + for (i = 1; i < vlib_get_n_threads (); i++) { vlib_node_main_t *nm_clone; vlib_main_t *vm_clone; vlib_node_runtime_t *rt; vlib_node_t *n; - vm_clone = vlib_mains[i]; + vm_clone = vlib_get_main_by_index (i); nm_clone = &vm_clone->node_main; for (j = 0; j < vec_len (nm_clone->nodes); j++) @@ -516,9 +516,9 @@ show_node_runtime (vlib_main_t * vm, || unformat (input, "su")) summary = 1; - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { - stat_vm = vlib_mains[i]; + stat_vm = vlib_get_main_by_index (i); if (stat_vm) vec_add1 (stat_vms, stat_vm); } @@ -592,7 +592,7 @@ show_node_runtime (vlib_main_t * vm, } } - if (vec_len (vlib_mains) > 1) + if (vlib_get_n_threads () > 1) { vlib_worker_thread_t *w = vlib_worker_threads + j; if (j > 0) @@ -665,9 +665,9 @@ clear_node_runtime (vlib_main_t * vm, vlib_main_t **stat_vms = 0, *stat_vm; vlib_node_runtime_t *r; - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { - stat_vm = vlib_mains[i]; + stat_vm = vlib_get_main_by_index (i); if (stat_vm) vec_add1 (stat_vms, stat_vm); } @@ -848,10 +848,10 @@ show_node (vlib_main_t * vm, unformat_input_t * input, s = format (s, "\n%8s %=12s %=12s %=12s %=12s %=12s\n", "Thread", "Calls", "Clocks", "Vectors", "Max Clock", "Max Vectors"); - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { - n = vlib_get_node (vlib_mains[i], node_index); - vlib_node_sync_stats (vlib_mains[i], n); + n = vlib_get_node (vlib_get_main_by_index (i), node_index); + vlib_node_sync_stats (vlib_get_main_by_index (i), n); cl = n->stats_total.clocks - n->stats_last_clear.clocks; ca = n->stats_total.calls - n->stats_last_clear.calls; diff --git a/src/vlib/threads.c b/src/vlib/threads.c index dd7de73ad8c..939f9107556 100644 --- a/src/vlib/threads.c +++ b/src/vlib/threads.c @@ -574,7 +574,8 @@ vlib_worker_thread_bootstrap_fn (void *arg) __os_thread_index = w - vlib_worker_threads; - vlib_process_start_switch_stack (vlib_mains[__os_thread_index], 0); + vlib_process_start_switch_stack (vlib_get_main_by_index (__os_thread_index), + 0); rv = (void *) clib_calljmp ((uword (*)(uword)) w->thread_function, (uword) arg, w->thread_stack + VLIB_THREAD_STACK_SIZE); @@ -1001,7 +1002,7 @@ worker_thread_node_runtime_update_internal (void) ASSERT (vlib_get_thread_index () == 0); - vm = vlib_mains[0]; + vm = vlib_get_first_main (); nm = &vm->node_main; ASSERT (*vlib_worker_threads->wait_at_barrier == 1); @@ -1017,11 +1018,11 @@ worker_thread_node_runtime_update_internal (void) vlib_node_sync_stats (vm, n); } - for (i = 1; i < vec_len (vlib_mains); i++) + for (i = 1; i < vlib_get_n_threads (); i++) { vlib_node_t *n; - vm_clone = vlib_mains[i]; + vm_clone = vlib_get_main_by_index (i); nm_clone = &vm_clone->node_main; for (j = 0; j < vec_len (nm_clone->nodes); j++) @@ -1049,7 +1050,7 @@ vlib_worker_thread_node_refork (void) int j; - vm = vlib_mains[0]; + vm = vlib_get_first_main (); nm = &vm->node_main; vm_clone = vlib_get_main (); nm_clone = &vm_clone->node_main; @@ -1425,7 +1426,7 @@ vlib_worker_thread_initial_barrier_sync_and_release (vlib_main_t * vm) { f64 deadline; f64 now = vlib_time_now (vm); - u32 count = vec_len (vlib_mains) - 1; + u32 count = vlib_get_n_threads () - 1; /* No worker threads? */ if (count == 0) @@ -1451,7 +1452,7 @@ vlib_worker_thread_initial_barrier_sync_and_release (vlib_main_t * vm) u8 vlib_worker_thread_barrier_held (void) { - if (vec_len (vlib_mains) < 2) + if (vlib_get_n_threads () < 2) return (1); return (*vlib_worker_threads->wait_at_barrier == 1); @@ -1469,13 +1470,13 @@ vlib_worker_thread_barrier_sync_int (vlib_main_t * vm, const char *func_name) u32 count; int i; - if (vec_len (vlib_mains) < 2) + if (vlib_get_n_threads () < 2) return; ASSERT (vlib_get_thread_index () == 0); vlib_worker_threads[0].barrier_caller = func_name; - count = vec_len (vlib_mains) - 1; + count = vlib_get_n_threads () - 1; /* Record entry relative to last close */ now = vlib_time_now (vm); @@ -1497,10 +1498,12 @@ vlib_worker_thread_barrier_sync_int (vlib_main_t * vm, const char *func_name) * the barrier hold-down timer. */ max_vector_rate = 0.0; - for (i = 1; i < vec_len (vlib_mains); i++) - max_vector_rate = - clib_max (max_vector_rate, - (f64) vlib_last_vectors_per_main_loop (vlib_mains[i])); + for (i = 1; i < vlib_get_n_threads (); i++) + { + vlib_main_t *ovm = vlib_get_main_by_index (i); + max_vector_rate = clib_max (max_vector_rate, + (f64) vlib_last_vectors_per_main_loop (ovm)); + } vlib_worker_threads[0].barrier_sync_count++; @@ -1562,7 +1565,7 @@ vlib_worker_thread_barrier_release (vlib_main_t * vm) f64 t_update_main = 0.0; int refork_needed = 0; - if (vec_len (vlib_mains) < 2) + if (vlib_get_n_threads () < 2) return; ASSERT (vlib_get_thread_index () == 0); @@ -1594,7 +1597,7 @@ vlib_worker_thread_barrier_release (vlib_main_t * vm) /* Do per thread rebuilds in parallel */ refork_needed = 1; clib_atomic_fetch_add (vlib_worker_threads->node_reforks_required, - (vec_len (vlib_mains) - 1)); + (vlib_get_n_threads () - 1)); now = vlib_time_now (vm); t_update_main = now - vm->barrier_epoch; } @@ -1668,7 +1671,7 @@ vlib_worker_wait_one_loop (void) { ASSERT (vlib_get_thread_index () == 0); - if (vec_len (vlib_mains) < 2) + if (vlib_get_n_threads () < 2) return; if (vlib_worker_thread_barrier_held ()) @@ -1677,7 +1680,7 @@ vlib_worker_wait_one_loop (void) u32 *counts = 0; u32 ii; - vec_validate (counts, vec_len (vlib_mains) - 1); + vec_validate (counts, vlib_get_n_threads () - 1); /* record the current loop counts */ vec_foreach_index (ii, vlib_mains) @@ -1973,24 +1976,24 @@ show_clock_command_fn (vlib_main_t * vm, verbose, format_clib_timebase_time, clib_timebase_now (tb)); - if (vec_len (vlib_mains) == 1) + if (vlib_get_n_threads () == 1) return 0; vlib_cli_output (vm, "Time last barrier release %.9f", vm->time_last_barrier_release); - for (i = 1; i < vec_len (vlib_mains); i++) + for (i = 1; i < vlib_get_n_threads (); i++) { - if (vlib_mains[i] == 0) + vlib_main_t *ovm = vlib_get_main_by_index (i); + if (ovm == 0) continue; - vlib_cli_output (vm, "%d: %U", i, format_clib_time, - &vlib_mains[i]->clib_time, verbose); + vlib_cli_output (vm, "%d: %U", i, format_clib_time, &ovm->clib_time, + verbose); - vlib_cli_output (vm, "Thread %d offset %.9f error %.9f", i, - vlib_mains[i]->time_offset, - vm->time_last_barrier_release - - vlib_mains[i]->time_last_barrier_release); + vlib_cli_output ( + vm, "Thread %d offset %.9f error %.9f", i, ovm->time_offset, + vm->time_last_barrier_release - ovm->time_last_barrier_release); } return 0; } diff --git a/src/vlib/threads.h b/src/vlib/threads.h index 6894cdf8379..eb31edc2706 100644 --- a/src/vlib/threads.h +++ b/src/vlib/threads.h @@ -521,7 +521,7 @@ vlib_get_worker_vlib_main (u32 worker_index) vlib_main_t *vm; vlib_thread_main_t *tm = &vlib_thread_main; ASSERT (worker_index < tm->n_vlib_mains - 1); - vm = vlib_mains[worker_index + 1]; + vm = vlib_get_main_by_index (worker_index + 1); ASSERT (vm); return vm; } diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c index 96e22a25313..6c98867253f 100644 --- a/src/vlib/unix/cli.c +++ b/src/vlib/unix/cli.c @@ -2886,9 +2886,9 @@ unix_cli_file_add (unix_cli_main_t * cm, char *name, int fd) * the same new name. * Then, throw away the old shared name-vector. */ - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { - this_vlib_main = vlib_mains[i]; + this_vlib_main = vlib_get_main_by_index (i); if (this_vlib_main == 0) continue; n = vlib_get_node (this_vlib_main, diff --git a/src/vlib/unix/input.c b/src/vlib/unix/input.c index 63981487049..9c7c54f6b1b 100644 --- a/src/vlib/unix/input.c +++ b/src/vlib/unix/input.c @@ -198,9 +198,9 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } node->input_main_loops_per_call = 0; } - else if (is_main == 0 && vector_rate < 2 - && (vlib_global_main.time_last_barrier_release + 0.5 < now) - && nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0) + else if (is_main == 0 && vector_rate < 2 && + (vlib_get_first_main ()->time_last_barrier_release + 0.5 < now) && + nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0) { timeout = 10e-3; timeout_ms = max_timeout_ms; diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c index e86d421056c..f73f9ca325f 100644 --- a/src/vlib/unix/main.c +++ b/src/vlib/unix/main.c @@ -692,7 +692,7 @@ vlib_thread_stack_init (uword thread_index) int vlib_unix_main (int argc, char *argv[]) { - vlib_main_t *vm = &vlib_global_main; /* one and only time for this! */ + vlib_main_t *vm = vlib_get_first_main (); /* one and only time for this! */ unformat_input_t input; clib_error_t *e; int i; |