vlib: Skip core 0 if workers are configured.
[vpp.git] / src / vlib / threads.c
index a827e35..b2a2f69 100644 (file)
@@ -255,6 +255,21 @@ vlib_thread_init (vlib_main_t * vm)
     }
   avail_cpu = clib_bitmap_set (avail_cpu, tm->main_lcore, 0);
 
+  /*
+   * Determine if the number of workers is greater than 0.
+   * If so, mark CPU 0 unavailable so workers will be numbered after main.
+   */
+  u32 n_workers = 0;
+  uword *p = hash_get_mem (tm->thread_registrations_by_name, "workers");
+  if (p != 0)
+    {
+      vlib_thread_registration_t *tr = (vlib_thread_registration_t *) p[0];
+      int worker_thread_count = tr->count;
+      n_workers = worker_thread_count;
+    }
+  if (tm->skip_cores == 0 && n_workers)
+    avail_cpu = clib_bitmap_set (avail_cpu, 0, 0);
+
   /* assume that there is socket 0 only if there is no data from sysfs */
   if (!tm->cpu_socket_bitmap)
     tm->cpu_socket_bitmap = clib_bitmap_set (0, 0, 1);
@@ -283,6 +298,8 @@ vlib_thread_init (vlib_main_t * vm)
   w->thread_id = pthread_self ();
   tm->n_vlib_mains = 1;
 
+  vlib_get_thread_core_numa (w, w->cpu_id);
+
   if (tm->sched_policy != ~0)
     {
       struct sched_param sched_param;
@@ -587,9 +604,8 @@ vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id)
   p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, cpu_id, 0);
   clib_sysfs_read ((char *) p, "%d", &core_id);
   vec_reset_length (p);
-  p =
-    format (p, "%s%u/topology/physical_package_id%c", sys_cpu_path, cpu_id,
-           0);
+  p = format (p, "%s%u/topology/physical_package_id%c", sys_cpu_path,
+             cpu_id, 0);
   clib_sysfs_read ((char *) p, "%d", &numa_id);
   vec_free (p);
 
@@ -606,7 +622,6 @@ vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
 
   w->cpu_id = cpu_id;
   vlib_get_thread_core_numa (w, cpu_id);
-  os_set_numa_index (w->numa_id);
 
   /* Set up NUMA-bound heap if indicated */
   if (clib_per_numa_mheaps[w->numa_id] == 0)
@@ -615,7 +630,7 @@ vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
       if (tm->numa_heap_size)
        {
          numa_heap = clib_mem_init_thread_safe_numa
-           (0 /* DIY */ , tm->numa_heap_size);
+           (0 /* DIY */ , tm->numa_heap_size, w->numa_id);
          clib_per_numa_mheaps[w->numa_id] = numa_heap;
        }
       else