summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vlib/threads.c21
-rw-r--r--src/vlib/threads.h2
-rw-r--r--src/vpp/conf/startup.conf3
3 files changed, 17 insertions, 9 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index c17fde4bfec..a946326f239 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -337,10 +337,6 @@ vlib_thread_init (vlib_main_t * vm)
avail_cpu = clib_bitmap_dup (tm->cpu_core_bitmap);
- /* by default we skip core 0, unless it is the only one available */
- if (tm->skip_cores == ~0)
- tm->skip_cores = (clib_bitmap_count_set_bits (avail_cpu) < 2) ? 0 : 1;
-
/* skip cores */
for (i = 0; i < tm->skip_cores; i++)
{
@@ -352,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");
@@ -376,6 +376,13 @@ vlib_thread_init (vlib_main_t * vm)
{
tm->cb.vlib_thread_set_lcore_cb (0, tm->main_lcore);
}
+ else
+ {
+ cpu_set_t cpuset;
+ CPU_ZERO (&cpuset);
+ CPU_SET (tm->main_lcore, &cpuset);
+ 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,
@@ -1259,7 +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->skip_cores = ~0;
+ tm->main_lcore = ~0;
tr = tm->next;
diff --git a/src/vlib/threads.h b/src/vlib/threads.h
index aaba218ffd3..f78ec1b9fa5 100644
--- a/src/vlib/threads.h
+++ b/src/vlib/threads.h
@@ -323,7 +323,7 @@ typedef struct
u8 *thread_prefix;
/* main thread lcore */
- u8 main_lcore;
+ u32 main_lcore;
/* Bitmap of available CPU cores */
uword *cpu_core_bitmap;
diff --git a/src/vpp/conf/startup.conf b/src/vpp/conf/startup.conf
index c1ac1235861..34631aa8e0f 100644
--- a/src/vpp/conf/startup.conf
+++ b/src/vpp/conf/startup.conf
@@ -38,7 +38,8 @@ cpu {
## Manual pinning of thread(s) to CPU core(s)
- ## Set logical CPU core where main thread runs
+ ## Set logical CPU core where main thread runs, if main core is not set
+ ## VPP will use core 1 if available
# main-core 1
## Set logical CPU core(s) where worker threads are running