From 832342e3a4c25520ea95b4bac9402798832dfaf2 Mon Sep 17 00:00:00 2001 From: hsandid Date: Wed, 20 Dec 2023 15:41:54 +0100 Subject: vlib: add error checks to thread pinning Type: fix Added error checks around pthread_setaffinity_np calls to stop vpp launch if pinning fails. Change-Id: Iec391c485d1832b6c2ff20fbf789608f6bcf7b57 Signed-off-by: hsandid --- src/vlib/threads.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/vlib') diff --git a/src/vlib/threads.c b/src/vlib/threads.c index 4b70642d3cb..7e6ac25f109 100644 --- a/src/vlib/threads.c +++ b/src/vlib/threads.c @@ -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); -- cgit 1.2.3-korg