* [dpdk-dev] [PATCH] eal/linux: truncate thread name
@ 2020-07-10 9:45 David Marchand
2020-07-10 12:41 ` Thomas Monjalon
0 siblings, 1 reply; 4+ messages in thread
From: David Marchand @ 2020-07-10 9:45 UTC (permalink / raw)
To: dev; +Cc: thomas
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".
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/librte_eal/linux/eal_thread.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/librte_eal/linux/eal_thread.c b/lib/librte_eal/linux/eal_thread.c
index 48a2c1124b..068de25595 100644
--- a/lib/librte_eal/linux/eal_thread.c
+++ b/lib/librte_eal/linux/eal_thread.c
@@ -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);
--
2.23.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/linux: truncate thread name
2020-07-10 9:45 [dpdk-dev] [PATCH] eal/linux: truncate thread name David Marchand
@ 2020-07-10 12:41 ` Thomas Monjalon
2020-07-10 12:44 ` David Marchand
2020-07-11 13:47 ` David Marchand
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Monjalon @ 2020-07-10 12:41 UTC (permalink / raw)
To: David Marchand; +Cc: dev
10/07/2020 11:45, David Marchand:
> 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.
[...]
> --- a/lib/librte_eal/linux/eal_thread.c
> +++ b/lib/librte_eal/linux/eal_thread.c
> @@ -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.
> +
> + strlcpy(truncated, name, sizeof(truncated));
> + ret = pthread_setname_np(id, truncated);
> #endif
> #endif
Acked-by: Thomas Monjalon <thomas@monjalon.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/linux: truncate thread name
2020-07-10 12:41 ` Thomas Monjalon
@ 2020-07-10 12:44 ` David Marchand
2020-07-11 13:47 ` David Marchand
1 sibling, 0 replies; 4+ messages in thread
From: David Marchand @ 2020-07-10 12:44 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: dev
On Fri, Jul 10, 2020 at 2:41 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 10/07/2020 11:45, David Marchand:
> > 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.
> [...]
> > --- a/lib/librte_eal/linux/eal_thread.c
> > +++ b/lib/librte_eal/linux/eal_thread.c
> > @@ -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" :-)
--
David Marchand
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/linux: truncate thread name
2020-07-10 12:41 ` Thomas Monjalon
2020-07-10 12:44 ` David Marchand
@ 2020-07-11 13:47 ` David Marchand
1 sibling, 0 replies; 4+ messages in thread
From: David Marchand @ 2020-07-11 13:47 UTC (permalink / raw)
To: David Marchand; +Cc: dev, Thomas Monjalon
On Fri, Jul 10, 2020 at 2:41 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> 10/07/2020 11:45, David Marchand:
> > 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.
> Acked-by: Thomas Monjalon <thomas@monjalon.net>
Applied.
--
David Marchand
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-11 13:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-10 9:45 [dpdk-dev] [PATCH] eal/linux: truncate thread name David Marchand
2020-07-10 12:41 ` Thomas Monjalon
2020-07-10 12:44 ` David Marchand
2020-07-11 13:47 ` David Marchand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).