DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: Ciara Power <ciara.power@intel.com>,
	Bruce Richardson <bruce.richardson@intel.com>,
	"Min Hu (Connor)" <humin29@huawei.com>,
	Chengwen Feng <fengchengwen@huawei.com>
Subject: [dpdk-dev] [PATCH] telemetry: fix build on FreeBSD < 12.2
Date: Wed, 21 Apr 2021 20:11:57 +0200	[thread overview]
Message-ID: <20210421181157.1634301-1-thomas@monjalon.net> (raw)

The function pthread_setname_np() was originally not available on
FreeBSD. It has been added in FreeBSD 12.2:
https://svnweb.freebsd.org/base?view=revision&revision=362264

The EAL implementation of rte_thread_setname() is duplicated
in the telemetry library, which does not depend on EAL,
so the compilation is safe in all systems.

Fixes: 5da7736f8c53 ("telemetry: set socket listener thread name")

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 lib/telemetry/telemetry.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/telemetry/telemetry.c b/lib/telemetry/telemetry.c
index 0b2993396a..386d0080bc 100644
--- a/lib/telemetry/telemetry.c
+++ b/lib/telemetry/telemetry.c
@@ -432,6 +432,18 @@ create_socket(char *path)
 	return -1;
 }
 
+static void
+set_thread_name(pthread_t id __rte_unused, const char *name __rte_unused)
+{
+#if defined RTE_EXEC_ENV_LINUX && defined __GLIBC__ && defined __GLIBC_PREREQ
+#if __GLIBC_PREREQ(2, 12)
+	pthread_setname_np(id, name);
+#endif
+#elif defined RTE_EXEC_ENV_FREEBSD
+	pthread_set_name_np(id, name);
+#endif
+}
+
 static int
 telemetry_legacy_init(void)
 {
@@ -463,7 +475,7 @@ telemetry_legacy_init(void)
 		return -1;
 	}
 	pthread_setaffinity_np(t_old, sizeof(*thread_cpuset), thread_cpuset);
-	pthread_setname_np(t_old, "telemetry-v1");
+	set_thread_name(t_old, "telemetry-v1");
 	TMTY_LOG(DEBUG, "Legacy telemetry socket initialized ok\n");
 	return 0;
 }
@@ -502,7 +514,7 @@ telemetry_v2_init(void)
 		return -1;
 	}
 	pthread_setaffinity_np(t_new, sizeof(*thread_cpuset), thread_cpuset);
-	pthread_setname_np(t_new, "telemetry-v2");
+	set_thread_name(t_new, "telemetry-v2");
 	atexit(unlink_sockets);
 
 	return 0;
-- 
2.31.1


             reply	other threads:[~2021-04-21 18:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 18:11 Thomas Monjalon [this message]
2021-04-21 18:14 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210421181157.1634301-1-thomas@monjalon.net \
    --to=thomas@monjalon.net \
    --cc=bruce.richardson@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=humin29@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).