X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fthreads.c;h=a946326f2396945552747afa6ca0e12d508cc0b0;hb=858151ff84848b3803f37983e4fe8bc450cb45ce;hp=50056462d1a53dca65aba3832659871026202089;hpb=d1274cb207a48f0142a5a6cbcd22d61c22dbc230;p=vpp.git diff --git a/src/vlib/threads.c b/src/vlib/threads.c index 50056462d1a..a946326f239 100644 --- a/src/vlib/threads.c +++ b/src/vlib/threads.c @@ -348,9 +348,13 @@ vlib_thread_init (vlib_main_t * vm) } /* grab cpu for main thread */ - if (!tm->main_lcore) + if (tm->main_lcore == ~0) { - tm->main_lcore = clib_bitmap_first_set (avail_cpu); + /* if main-lcore is not set, we try to use lcore 1 */ + if (clib_bitmap_get (avail_cpu, 1)) + tm->main_lcore = 1; + else + tm->main_lcore = clib_bitmap_first_set (avail_cpu); if (tm->main_lcore == (u8) ~ 0) return clib_error_return (0, "no available cpus to be used for the" " main thread"); @@ -821,12 +825,12 @@ start_workers (vlib_main_t * vm) /* Fork vlib_global_main et al. Look for bugs here */ oldheap = clib_mem_set_heap (w->thread_mheap); - vm_clone = clib_mem_alloc (sizeof (*vm_clone)); + vm_clone = clib_mem_alloc_aligned (sizeof (*vm_clone), + CLIB_CACHE_LINE_BYTES); clib_memcpy (vm_clone, vlib_mains[0], sizeof (*vm_clone)); vm_clone->thread_index = worker_thread_index; vm_clone->heap_base = w->thread_mheap; - vm_clone->mbuf_alloc_list = 0; vm_clone->init_functions_called = hash_create (0, /* value bytes */ 0); vm_clone->pending_rpc_requests = 0; @@ -838,7 +842,8 @@ start_workers (vlib_main_t * vm) nm = &vlib_mains[0]->node_main; nm_clone = &vm_clone->node_main; /* fork next frames array, preserving node runtime indices */ - nm_clone->next_frames = vec_dup (nm->next_frames); + nm_clone->next_frames = vec_dup_aligned (nm->next_frames, + CLIB_CACHE_LINE_BYTES); for (j = 0; j < vec_len (nm_clone->next_frames); j++) { vlib_next_frame_t *nf = &nm_clone->next_frames[j]; @@ -875,7 +880,8 @@ start_workers (vlib_main_t * vm) n++; } nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL] = - vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]); + vec_dup_aligned (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL], + CLIB_CACHE_LINE_BYTES); vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]) { @@ -889,7 +895,8 @@ start_workers (vlib_main_t * vm) } nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT] = - vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT]); + vec_dup_aligned (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT], + CLIB_CACHE_LINE_BYTES); vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]) { vlib_node_t *n = vlib_get_node (vm, rt->node_index); @@ -901,7 +908,8 @@ start_workers (vlib_main_t * vm) n->runtime_data_bytes)); } - nm_clone->processes = vec_dup (nm->processes); + nm_clone->processes = vec_dup_aligned (nm->processes, + CLIB_CACHE_LINE_BYTES); /* zap the (per worker) frame freelists, etc */ nm_clone->frame_sizes = 0; @@ -912,10 +920,11 @@ start_workers (vlib_main_t * vm) clib_mem_set_heap (oldheap); vec_add1_aligned (vlib_mains, vm_clone, CLIB_CACHE_LINE_BYTES); - vm_clone->error_main.counters = - vec_dup (vlib_mains[0]->error_main.counters); - vm_clone->error_main.counters_last_clear = - vec_dup (vlib_mains[0]->error_main.counters_last_clear); + vm_clone->error_main.counters = vec_dup_aligned + (vlib_mains[0]->error_main.counters, CLIB_CACHE_LINE_BYTES); + vm_clone->error_main.counters_last_clear = vec_dup_aligned + (vlib_mains[0]->error_main.counters_last_clear, + CLIB_CACHE_LINE_BYTES); /* Fork the vlib_buffer_main_t free lists, etc. */ orig_freelist_pool = vm_clone->buffer_free_list_pool; @@ -1093,7 +1102,8 @@ vlib_worker_thread_node_refork (void) nm_clone = &vm_clone->node_main; vec_free (nm_clone->next_frames); - nm_clone->next_frames = vec_dup (nm->next_frames); + nm_clone->next_frames = vec_dup_aligned (nm->next_frames, + CLIB_CACHE_LINE_BYTES); for (j = 0; j < vec_len (nm_clone->next_frames); j++) { @@ -1161,7 +1171,8 @@ vlib_worker_thread_node_refork (void) /* re-clone internal nodes */ old_rt = nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]; nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL] = - vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]); + vec_dup_aligned (nm->nodes_by_type[VLIB_NODE_TYPE_INTERNAL], + CLIB_CACHE_LINE_BYTES); vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INTERNAL]) { @@ -1187,7 +1198,8 @@ vlib_worker_thread_node_refork (void) /* re-clone input nodes */ old_rt = nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]; nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT] = - vec_dup (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT]); + vec_dup_aligned (nm->nodes_by_type[VLIB_NODE_TYPE_INPUT], + CLIB_CACHE_LINE_BYTES); vec_foreach (rt, nm_clone->nodes_by_type[VLIB_NODE_TYPE_INPUT]) { @@ -1210,7 +1222,8 @@ vlib_worker_thread_node_refork (void) vec_free (old_rt); - nm_clone->processes = vec_dup (nm->processes); + nm_clone->processes = vec_dup_aligned (nm->processes, + CLIB_CACHE_LINE_BYTES); } void @@ -1253,6 +1266,7 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input) tm->n_thread_stacks = 1; /* account for main thread */ tm->sched_policy = ~0; tm->sched_priority = ~0; + tm->main_lcore = ~0; tr = tm->next; @@ -1483,6 +1497,18 @@ vlib_worker_thread_barrier_sync_int (vlib_main_t * vm) } +void vlib_stat_segment_lock (void) __attribute__ ((weak)); +void +vlib_stat_segment_lock (void) +{ +} + +void vlib_stat_segment_unlock (void) __attribute__ ((weak)); +void +vlib_stat_segment_unlock (void) +{ +} + void vlib_worker_thread_barrier_release (vlib_main_t * vm) { @@ -1512,6 +1538,13 @@ vlib_worker_thread_barrier_release (vlib_main_t * vm) /* Update (all) node runtimes before releasing the barrier, if needed */ if (vm->need_vlib_worker_thread_node_runtime_update) { + /* + * Lock stat segment here, so we's safe when + * rebuilding the stat segment node clones from the + * stat thread... + */ + vlib_stat_segment_lock (); + /* Do stats elements on main thread */ worker_thread_node_runtime_update_internal (); vm->need_vlib_worker_thread_node_runtime_update = 0; @@ -1553,6 +1586,7 @@ vlib_worker_thread_barrier_release (vlib_main_t * vm) os_panic (); } } + vlib_stat_segment_unlock (); } t_closed_total = now - vm->barrier_epoch;