From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5C9474247D; Tue, 24 Jan 2023 16:21:20 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 085D840150; Tue, 24 Jan 2023 16:21:20 +0100 (CET) Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by mails.dpdk.org (Postfix) with ESMTP id EA053400EF for ; Tue, 24 Jan 2023 16:21:17 +0100 (CET) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 8F0675C053D; Tue, 24 Jan 2023 10:21:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 24 Jan 2023 10:21:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1674573677; x= 1674660077; bh=HdHXoGuJIt5pe1Aw7ZYsjAalaptsfR/8KmcA71ZdJvA=; b=l AVblRgMOcn3OkuHO5Hr4JcZRtIX/xmXyJ1HAtbF+QW3YL8p1VwHMQV+aMW4VhV9i rfA/xa/1o86eN4JzlenkqNs1GAo4bI7aWdJHvAfIc2NeVGxOxsl5jFPRhpcRnTKQ WD2p+YpJ0r0slLWe5lGeu3dkGkkmnwt+bjDmW8Kw6DwzYuyjBBpaOeemDTN6DF+q fNRY634EBQqdmTdHWhP8QqyqYKo6/B27G2lHA3Yc30gJnYAuPls0MZuVCSWHaw0y VoSLccxfJWgNxGzf92xK5khYCjUNIK+vRbMR9wENSOfjS60lF8NvxXWChWpdG291 lKlHZp9Ofr9YUW1VIgbIg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1674573677; x= 1674660077; bh=HdHXoGuJIt5pe1Aw7ZYsjAalaptsfR/8KmcA71ZdJvA=; b=S YVQfb5BqkiuTLoqkJgdY9R/ukRLatZl0Epy6e1pLI6dIF+rFbnNUURCvPCCanEWO wuszUUsxjzmz23i8SLwWzi4MF8HEz1JYKUqkec9PyN7LE3pDajd1ibHQAJYFdO23 UWw6SNCX+d0w4Hse9i9lI4/tGeT6YBySpRE0PuxK03MVS7ERMq96RFYIhyowWBMR UFoxlvT10sgxJzi+o2Dnrc8xwaJYnsp1u4/EdMNntDJwiOM4geijAPHefppRfKgz Jb/c+GfLrUKJ6lvbxRxoh7LvaF2/aWziUtP4vHWDzAc84CQ2KWRVkQ2GvWmuWY/o VYbS/4Kcv2K/fS1tv27xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvtddgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkfgjfhgggfgtsehtqh ertddttddunecuhfhrohhmpefvhhhomhgrshcuofhonhhjrghlohhnuceothhhohhmrghs sehmohhnjhgrlhhonhdrnhgvtheqnecuggftrfgrthhtvghrnhepfefhjeeluedvvedtud dtuedtvefhieejtefhffeujefhteduudevtdektdeikeffnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhhonh drnhgvth X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Jan 2023 10:21:16 -0500 (EST) From: Thomas Monjalon To: Tyler Retzlaff Cc: dev@dpdk.org, david.marchand@redhat.com, jerinjacobk@gmail.com, mb@smartsharesystems.com Subject: Re: [PATCH v7 1/5] eal: add thread set name API operating on rte thread Date: Tue, 24 Jan 2023 16:21:14 +0100 Message-ID: <4509245.24cOQSKZR9@thomas> In-Reply-To: <1674502774-20253-2-git-send-email-roretzla@linux.microsoft.com> References: <1670439617-9054-1-git-send-email-roretzla@linux.microsoft.com> <1674502774-20253-1-git-send-email-roretzla@linux.microsoft.com> <1674502774-20253-2-git-send-email-roretzla@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 23/01/2023 20:39, Tyler Retzlaff: > Add a rte_thread_set_name that sets the name of an rte_thread_t thread. > This is a replacement for the rte_thread_setname(pthread_t, ...) which > exposes platform-specific details. >=20 > Signed-off-by: Tyler Retzlaff >=20 > Acked-by: Morten Br=F8rup >=20 > --- > lib/eal/common/eal_common_thread.c | 8 ++----- > lib/eal/freebsd/eal.c | 3 +-- > lib/eal/freebsd/eal_thread.c | 11 ++++++++++ > lib/eal/include/rte_thread.h | 17 +++++++++++++++ > lib/eal/linux/eal.c | 6 +----- > lib/eal/linux/eal_thread.c | 22 +++++++++++++++++++ > lib/eal/version.map | 3 +++ > lib/eal/windows/rte_thread.c | 43 ++++++++++++++++++++++++++++++++= ++++++ > 8 files changed, 100 insertions(+), 13 deletions(-) >=20 > diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_comm= on_thread.c > index 38d83a6..3181515 100644 > --- a/lib/eal/common/eal_common_thread.c > +++ b/lib/eal/common/eal_common_thread.c > @@ -288,12 +288,8 @@ static void *ctrl_thread_init(void *arg) > return -ret; > } > =20 > - if (name !=3D NULL) { > - ret =3D rte_thread_setname(*thread, name); > - if (ret < 0) > - RTE_LOG(DEBUG, EAL, > - "Cannot set name for ctrl thread\n"); > - } > + if (name !=3D NULL) > + rte_thread_set_name((rte_thread_t){(uintptr_t)*thread}, name); > =20 > /* Wait for the control thread to initialize successfully */ > while ((ctrl_thread_status =3D > diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c > index 8db5007..9303401 100644 > --- a/lib/eal/freebsd/eal.c > +++ b/lib/eal/freebsd/eal.c > @@ -817,8 +817,7 @@ static void rte_eal_init_alert(const char *msg) > /* Set thread_name for aid in debugging. */ > snprintf(thread_name, sizeof(thread_name), > "rte-worker-%d", i); > - rte_thread_setname((pthread_t)lcore_config[i].thread_id.opaque_id, > - thread_name); > + rte_thread_set_name(lcore_config[i].thread_id, thread_name); > =20 > ret =3D rte_thread_set_affinity_by_id(lcore_config[i].thread_id, > &lcore_config[i].cpuset); > diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c > index ab81b52..b69f5d3 100644 > --- a/lib/eal/freebsd/eal_thread.c > +++ b/lib/eal/freebsd/eal_thread.c > @@ -32,6 +32,17 @@ int rte_sys_gettid(void) > return (int)lwpid; > } > =20 > +void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) > +{ > + char truncated[RTE_MAX_THREAD_NAME_LEN]; > + const size_t truncatedsz =3D sizeof(truncated); > + > + if (strlcpy(truncated, thread_name, truncatedsz) >=3D truncatedsz) > + RTE_LOG(DEBUG, EAL, "Truncated thread name\n"); > + > + pthread_set_name_np((pthread_t)thread_id.opaque_id, truncated); > +} > + > int rte_thread_setname(pthread_t id, const char *name) > { > /* this BSD function returns no error */ > diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h > index b9edf70..8a63a52 100644 > --- a/lib/eal/include/rte_thread.h > +++ b/lib/eal/include/rte_thread.h > @@ -146,6 +146,23 @@ int rte_thread_create(rte_thread_t *thread_id, > * @warning > * @b EXPERIMENTAL: this API may change without prior notice. > * > + * Set the name of the thread. We need to explain that it can fail. > + * > + * @param thread_id > + * The id of the thread to set name. > + * > + * @param thread_name > + * The name to set. Truncated to RTE_MAX_THREAD_NAME_LEN, > + * including terminating NUL if necessary. > + */ > +__rte_experimental > +void > +rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); [...] > --- a/lib/eal/linux/eal_thread.c > +++ b/lib/eal/linux/eal_thread.c > +void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) > +{ > + int ret =3D ENOSYS; > +#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) > +#if __GLIBC_PREREQ(2, 12) > + char truncated[RTE_MAX_THREAD_NAME_LEN]; > + const size_t truncatedsz =3D sizeof(truncated); > + > + if (strlcpy(truncated, thread_name, truncatedsz) >=3D truncatedsz) > + RTE_LOG(DEBUG, EAL, "Truncated thread name\n"); > + > + ret =3D pthread_setname_np((pthread_t)thread_id.opaque_id, truncated); > +#endif > +#endif > + RTE_SET_USED(thread_id); > + RTE_SET_USED(thread_name); > + > + if (ret !=3D 0) > + RTE_LOG(DEBUG, EAL, "Failed to set thread name\n"); > +} It is very close to rte_thread_setname with few differences. OK > --- a/lib/eal/windows/rte_thread.c > +++ b/lib/eal/windows/rte_thread.c > +void > +rte_thread_set_name(rte_thread_t thread_id, const char *thread_name) > +{ > + int ret =3D 0; > + wchar_t wname[RTE_MAX_THREAD_NAME_LEN]; > + mbstate_t state =3D {0}; > + size_t rv; > + HANDLE thread_handle; > + > + thread_handle =3D OpenThread(THREAD_ALL_ACCESS, FALSE, > + thread_id.opaque_id); > + if (thread_handle =3D=3D NULL) { > + ret =3D thread_log_last_error("OpenThread()"); > + goto cleanup; > + } > + > + memset(wname, 0, sizeof(wname)); > + rv =3D mbsrtowcs(wname, &thread_name, RTE_DIM(wname) - 1, &state); > + if (rv =3D=3D (size_t)-1) { > + ret =3D EILSEQ; > + goto cleanup; > + } > + > +#ifndef RTE_TOOLCHAIN_GCC > + if (FAILED(SetThreadDescription(thread_handle, wname))) { > + ret =3D EINVAL; > + goto cleanup; > + } > +#else > + ret =3D ENOTSUP; > + goto cleanup; > +#endif > + > +cleanup: > + if (thread_handle !=3D NULL) > + CloseHandle(thread_handle); > + > + if (ret !=3D 0) > + RTE_LOG(DEBUG, EAL, "Failed to set thread name\n"); > +} This is a new function for Windows, right? It should be noted in the commit log.