vlib: add error checks to thread pinning 25/40125/4
authorhsandid <halsandi@cisco.com>
Wed, 20 Dec 2023 14:41:54 +0000 (15:41 +0100)
committerDamjan Marion <dmarion@0xa5.net>
Fri, 22 Dec 2023 15:45:07 +0000 (15:45 +0000)
Type: fix

Added error checks around pthread_setaffinity_np
calls to stop vpp launch if pinning fails.

Change-Id: Iec391c485d1832b6c2ff20fbf789608f6bcf7b57
Signed-off-by: hsandid <halsandi@cisco.com>
src/vlib/threads.c
src/vpp/vnet/main.c

index 4b70642..7e6ac25 100644 (file)
@@ -222,7 +222,12 @@ vlib_thread_init (vlib_main_t * vm)
       cpu_set_t cpuset;
       CPU_ZERO (&cpuset);
       CPU_SET (tm->main_lcore, &cpuset);
-      pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
+      if (pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t),
+                                 &cpuset))
+       {
+         return clib_error_return (0, "could not pin main thread to cpu %u",
+                                   tm->main_lcore);
+       }
     }
 
   /* Set up thread 0 */
@@ -304,7 +309,8 @@ vlib_thread_init (vlib_main_t * vm)
              if (c == ~0)
                return clib_error_return (0,
                                          "no available cpus to be used for"
-                                         " the '%s' thread", tr->name);
+                                         " the '%s' thread #%u",
+                                         tr->name, tr->count);
 
              avail_cpu = clib_bitmap_set (avail_cpu, 0, avail_c0);
              avail_cpu = clib_bitmap_set (avail_cpu, c, 0);
@@ -801,25 +807,26 @@ start_workers (vlib_main_t * vm)
        {
          for (j = 0; j < tr->count; j++)
            {
+
              w = vlib_worker_threads + worker_thread_index++;
              err = vlib_launch_thread_int (vlib_worker_thread_bootstrap_fn,
                                            w, 0);
              if (err)
-               clib_error_report (err);
+               clib_unix_error ("%U, thread %s init on cpu %d failed",
+                                format_clib_error, err, tr->name, 0);
            }
        }
       else
        {
          uword c;
-          /* *INDENT-OFF* */
           clib_bitmap_foreach (c, tr->coremask)  {
             w = vlib_worker_threads + worker_thread_index++;
            err = vlib_launch_thread_int (vlib_worker_thread_bootstrap_fn,
                                          w, c);
            if (err)
-             clib_error_report (err);
-          }
-          /* *INDENT-ON* */
+             clib_unix_error ("%U, thread %s init on cpu %d failed",
+                              format_clib_error, err, tr->name, c);
+           }
        }
     }
   vlib_worker_thread_barrier_sync (vm);
index be34228..3257d9c 100644 (file)
@@ -325,7 +325,13 @@ defaulted:
     {
       CPU_ZERO (&cpuset);
       CPU_SET (main_core, &cpuset);
-      pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpuset);
+      if (pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t),
+                                 &cpuset))
+       {
+         clib_unix_error (
+           "pthread_setaffinity_np() on cpu %d failed for main thread",
+           main_core);
+       }
     }
 
   /* Set up the plugin message ID allocator right now... */