summaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-07-11 10:51:00 +0200
committerDamjan Marion <dmarion@me.com>2018-07-11 11:02:18 +0000
commit858151ff84848b3803f37983e4fe8bc450cb45ce (patch)
treee9ed5d03d0786f9eb9d2357e7fb1a5d65c7ad3bc /src/vlib
parent059d1d0e01a59769d2c3f3f978f50120d64a6976 (diff)
threads: fix issue with setting main-core to 0
Change-Id: Id3ccfcfa2a88cf7aa106f1202af7cd677de32575 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/threads.c21
-rw-r--r--src/vlib/threads.h2
2 files changed, 15 insertions, 8 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;