aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhsandid <halsandi@cisco.com>2024-05-22 15:30:24 +0200
committerDamjan Marion <dmarion@0xa5.net>2024-05-24 08:21:14 +0000
commit0b0468cb0fc363483a88b9dfdee82da843e4e9e2 (patch)
tree4dc585e8e273979d9156e808d01b6cf0b29bad13
parent1b053782a51d0bd2b1172b62665520af476d1a54 (diff)
vlib: improvement to automatic core pinning
Type: feature If 'main-core' is not specified, the main thread is pinned by default to the cpu it is running on during initialization. This change does not impact manual core-pinning, which requires the 'main-core' argument e.g. 'cpu {main-core x corelist-workers n}. Change-Id: I874034591bf0acf4d71b231dfbbb0f6de8fe6060 Signed-off-by: hsandid <halsandi@cisco.com>
-rw-r--r--src/vlib/threads.c9
-rw-r--r--src/vpp/vnet/main.c4
2 files changed, 13 insertions, 0 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 854d69448ac..ef2c5616f21 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -205,6 +205,10 @@ vlib_thread_init (vlib_main_t * vm)
avail_cpu = clib_bitmap_set (avail_cpu, c, 0);
}
+ /* if main thread affinity is unspecified, set to current running cpu */
+ if (tm->main_lcore == ~0)
+ tm->main_lcore = sched_getcpu ();
+
/* grab cpu for main thread */
if (tm->main_lcore != ~0)
{
@@ -1134,6 +1138,7 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input)
u8 *name;
uword *bitmap;
u32 count;
+ int use_corelist = 0;
tm->thread_registrations_by_name = hash_create_string (0, sizeof (uword));
@@ -1185,6 +1190,7 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input)
tr->coremask = bitmap;
tr->count = clib_bitmap_count_set_bits (tr->coremask);
+ use_corelist = 1;
}
else
if (unformat
@@ -1214,6 +1220,9 @@ cpu_config (vlib_main_t * vm, unformat_input_t * input)
break;
}
+ if (use_corelist && tm->main_lcore == ~0)
+ return clib_error_return (0, "main-core must be specified when using "
+ "corelist-* or coremask-* attribute");
if (tm->sched_priority != ~0)
{
if (tm->sched_policy == SCHED_FIFO || tm->sched_policy == SCHED_RR)
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index c57efd59a62..dd4f4cc3353 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -329,6 +329,10 @@ defaulted:
unformat_free (&input);
+ /* if main thread affinity is unspecified, set to current running cpu */
+ if (main_core == ~0)
+ main_core = sched_getcpu ();
+
/* set process affinity for main thread */
if (main_core != ~0)
{