[PATCH v5 08/17] eal: warn if thread name is truncated

Stephen Hemminger
2025-12-07T19:13:39Z

Thread name is very short 16 characters and therefore the name
dpdk-worker-%d will overflow with more than 9999 worker cores.
Error should be non-fatal since name only matters for debug.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/eal/freebsd/eal.c | 6 ++++--
lib/eal/linux/eal.c | 6 ++++--
lib/eal/windows/eal.c | 6 ++++--
3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 6215245ad5..beda7e0c5c 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -690,8 +690,10 @@ rte_eal_init(int argc, char **argv)
rte_panic("Cannot create thread\n");

/* Set thread_name for aid in debugging. */
- snprintf(thread_name, sizeof(thread_name),
- "dpdk-worker%d", i);
+ ret = snprintf(thread_name, sizeof(thread_name), "dpdk-worker%d", i);
+ if (ret >= (int)sizeof(thread_name))
+ EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
+
rte_thread_set_name(lcore_config[i].thread_id, thread_name);

ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index b12f325ddd..d848de03d8 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -863,8 +863,10 @@ rte_eal_init(int argc, char **argv)
rte_panic("Cannot create thread\n");

/* Set thread_name for aid in debugging. */
- snprintf(thread_name, sizeof(thread_name),
- "dpdk-worker%d", i);
+ ret = snprintf(thread_name, sizeof(thread_name), "dpdk-worker%d", i);
+ if (ret >= RTE_THREAD_NAME_SIZE)
+ EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
+
rte_thread_set_name(lcore_config[i].thread_id, thread_name);

ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 21fe7cb1d9..8b539f8601 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -378,8 +378,10 @@ rte_eal_init(int argc, char **argv)
rte_panic("Cannot create thread\n");

/* Set thread name for aid in debugging. */
- snprintf(thread_name, sizeof(thread_name),
- "dpdk-worker%d", i);
+ ret = snprintf(thread_name, sizeof(thread_name), "dpdk-worker%d", i);
+ if (ret >= (int)sizeof(thread_name))
+ EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
+
rte_thread_set_name(lcore_config[i].thread_id, thread_name);

ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
--
2.51.0