eal/linux: truncate thread name
PATCH 1/1 eal/linux: truncate thread name
pthread_setname_np refuses names larger than 16 bytes (\0 included). Rather than return an error, truncate the name to this limit in the rte_thread_setname helper.
Caught with ixgbe which creates control thread with name "ixgbe-link-handler":
Configuring Port 0 (socket 0)
EAL: Cannot set name for ctrl thread
...
EAL: Cannot set name for ctrl thread
Port 0: link state change event
...
EAL: Cannot set name for ctrl thread
Port 0: link state change event
Note: before this change, the thread would keep its original name, which meant in my test for the ixgbe handler either "dpdk-testpmd" or "eal-intr-thread".
--- lib/librte_eal/linux/eal_thread.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/librte_eal/linux/eal_thread.c +4 -1
@@ -153,7 +153,10 @@ int rte_thread_setname(pthread_t id, const char *name)int ret =ENOSYS ;#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)#if __GLIBC_PREREQ (2 ,12 ) - ret =pthread_setname_np (id, name); +char truncated[16 ]; + +strlcpy (truncated, name,sizeof (truncated)); + ret =pthread_setname_np (id, truncated);#endif #endif RTE_SET_USED (id);
Signature · 1 line
2.23.0
10/07/2020 11:45, David Marchand:
Quoted 3 lines
pthread_setname_nprefuses names larger than 16 bytes (\0 included). Rather than return an error, truncate the name to this limit in therte_thread_setnamehelper.
[...]
lib/librte_eal/linux/eal_thread.c int rte_thread_setname(pthread_t id, const char *name) · line 156
Quoted 8 lines
lib/librte_eal/linux/eal_thread.c +1
-1@@ -153,7 +153,10 @@ int rte_thread_setname(pthread_t id, const char *name)int ret =ENOSYS ;#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)#if __GLIBC_PREREQ (2 ,12 ) - ret =pthread_setname_np (id, name); +char truncated[16 ];
That's a pity POSIX is not defining a constant for this limit.
lib/librte_eal/linux/eal_thread.c int rte_thread_setname(pthread_t id, const char *name) · line 161
Quoted 5 lines
lib/librte_eal/linux/eal_thread.c +3
-0+ +strlcpy (truncated, name,sizeof (truncated)); + ret =pthread_setname_np (id, truncated);#endif #endif
Quoted 6 lines · Thomas Monjalon
10/07/2020 11:45, David Marchand:
Quoted 3 lines
pthread_setname_nprefuses names larger than 16 bytes (\0 included). Rather than return an error, truncate the name to this limit in therte_thread_setnamehelper.[...]
Quoted 10 lines
lib/librte_eal/linux/eal_thread.c int rte_thread_setname(pthread_t id, const char *name) · line 156
Quoted 8 lines
lib/librte_eal/linux/eal_thread.c +1
-1@@ -153,7 +153,10 @@ int rte_thread_setname(pthread_t id, const char *name)int ret =ENOSYS ;#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)#if __GLIBC_PREREQ (2 ,12 ) - ret =pthread_setname_np (id, name); +char truncated[16 ];That's a pity POSIX is not defining a constant for this limit.
pthread_setname "_np" :-)
Signature · 1 line
David Marchand
David Marchand
AppliedQuoted 5 lines · Thomas Monjalon
10/07/2020 11:45, David Marchand:
Quoted 3 lines
pthread_setname_nprefuses names larger than 16 bytes (\0 included). Rather than return an error, truncate the name to this limit in therte_thread_setnamehelper.Acked-by Thomas Monjalon <[email protected]>
Applied.
Signature · 1 line
David Marchand