threads: fix issue with setting main-core to 0 16/13416/2
authorDamjan Marion <damarion@cisco.com>
Wed, 11 Jul 2018 08:51:00 +0000 (10:51 +0200)
committerDamjan Marion <dmarion@me.com>
Wed, 11 Jul 2018 11:02:18 +0000 (11:02 +0000)
Change-Id: Id3ccfcfa2a88cf7aa106f1202af7cd677de32575
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vlib/threads.c
src/vlib/threads.h
src/vpp/conf/startup.conf

index c17fde4..a946326 100644 (file)
@@ -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;
 
index aaba218..f78ec1b 100644 (file)
@@ -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;
index c1ac123..34631aa 100644 (file)
@@ -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