aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/threads.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-05-10 15:25:10 -0400
committerFlorin Coras <florin.coras@gmail.com>2019-05-14 17:50:35 +0000
commit2180baccc1428ffbd64a8312f3c983791a0771ab (patch)
treedee36722337e21f753c315768d34367531f0af1d /src/vlib/threads.c
parent5e8e8dcd71c619b098093e124ccde89ba3590e6f (diff)
Preallocate mhash key_tmps vector
Fix os_get_nthreads() so that it starts returning the correct answer as early as possible. Change-Id: Id5292262f2c3f521b07ffbe6a9f6748dcc4dcb7d Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlib/threads.c')
-rw-r--r--src/vlib/threads.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 52886df37e0..cb1eb5fdba4 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -169,13 +169,7 @@ barrier_trace_release (f64 t_entry, f64 t_closed_total, f64 t_update_main)
uword
os_get_nthreads (void)
{
- u32 len;
-
- len = vec_len (vlib_thread_stacks);
- if (len == 0)
- return 1;
- else
- return len;
+ return vec_len (vlib_thread_stacks);
}
void
@@ -299,11 +293,8 @@ vlib_thread_init (vlib_main_t * vm)
pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
}
- /* as many threads as stacks... */
- vec_validate_aligned (vlib_worker_threads, vec_len (vlib_thread_stacks) - 1,
- CLIB_CACHE_LINE_BYTES);
-
- /* Preallocate thread 0 */
+ /* Set up thread 0 */
+ vec_validate_aligned (vlib_worker_threads, 0, CLIB_CACHE_LINE_BYTES);
_vec_len (vlib_worker_threads) = 1;
w = vlib_worker_threads;
w->thread_mheap = clib_mem_get_heap ();
@@ -358,8 +349,7 @@ vlib_thread_init (vlib_main_t * vm)
avail_cpu = clib_bitmap_set(avail_cpu, c, 0);
}));
-/* *INDENT-ON* */
-
+ /* *INDENT-ON* */
}
else
{
@@ -381,9 +371,14 @@ vlib_thread_init (vlib_main_t * vm)
tm->n_vlib_mains = n_vlib_mains;
+ /*
+ * Allocate the remaining worker threads, and thread stack vector slots
+ * from now on, calls to os_get_nthreads() will return the correct
+ * answer.
+ */
vec_validate_aligned (vlib_worker_threads, first_index - 1,
CLIB_CACHE_LINE_BYTES);
-
+ vec_validate (vlib_thread_stacks, vec_len (vlib_worker_threads) - 1);
return 0;
}