From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: timo.myyra@bittivirhe.fi (Timo =?utf-8?Q?Myyr=C3=A4?=) Newsgroups: gmane.emacs.devel Subject: Re: add pthread_set_name_np support Date: Sat, 27 Jun 2020 15:51:50 +0300 Message-ID: <87v9jcpt7d.fsf@asteroid.bittivirhe.fi> References: <875zbcrdfv.fsf@asteroid.bittivirhe.fi> <83r1u03gtt.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="39090"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jun 27 16:29:20 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jpBpX-000A11-Rr for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jun 2020 16:29:19 +0200 Original-Received: from localhost ([::1]:57106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpBpW-0001h0-TW for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jun 2020 10:29:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpAJK-0004Uq-Db for emacs-devel@gnu.org; Sat, 27 Jun 2020 08:51:58 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:55591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpAJG-0001Eg-6K; Sat, 27 Jun 2020 08:51:58 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id ADF0A5C00C3; Sat, 27 Jun 2020 08:51:52 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 27 Jun 2020 08:51:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bittivirhe.fi; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; s=fm3; bh= sA+UaIb7Wt6hk5+/DrF/2BEaqpwGIGj1RuWiVXH3V24=; b=XyB5OpMUO3jKLbbx GVdzJ8+ZDnzaJBjA1wiAOGdgcR2spxRlPvZL1ylvWnuP5PO542sguGWULmGE+hcr fdMtCUMulXSVbmbrLFM1l/O1m8hYOzN3tmD+RzgvoZ8pKyWufdCWoCJwoEJVgLPK Nj7RbVlwKugL8wCTaR8Le8dDO60/35Aq2YeVbr/6vSDVQD0o/WhnEdIMxLdnveER 18isKbQ3n8mQ1IUDXqY+SdBpBWQJgRmgdNDxfkQfUQwFHXoN3LWlqpnoE68eCcSD 44LIlQPiKAuMtlvOf6MtRgyQt7U1XUq8PzJI3Mp8PKeljfRTP0JSw9LGPqnRKjaP SPoe1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=sA+UaIb7Wt6hk5+/DrF/2BEaqpwGIGj1RuWiVXH3V 24=; b=JWpW6Oyx6SczIlfdBwtRFWosxmqOXmoT5yAuxAHo7ekl5saB9btF3c/JC no+lI5v+6/ClED1vtN5ZOzJCMJTi3cAiaxrR7tw86elubyiLRowPdxY6NwZTGkt6 LQDkaV/SifpckRDfCwhquXgp9Ogold80lrrejISQ3Ab0drn59vAchcqxJi0UznrB UfPnOTT+B+dR4M2igDn1mAYUjmGvHo/WUOkkoWd7IIe1Wq40AYGNG4USTL+OjOYs efgTt0UwTq3C6vyq2Fl4lgtwhhYeu2OglhexEG7c/rSl/L0Cmv5T69jjEvC2wLzB vWdfDv1Ldtcy2191H/uFjPONnZJZw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudelfedgheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufhfffgjkfgfgggtgfesthhqredttderjeenucfhrhhomhepthhimhho rdhmhiihrhgrsegsihhtthhivhhirhhhvgdrfhhiucdlvfhimhhoucfohiihrhommdenuc ggtffrrghtthgvrhhnpeekleehgfevtddtjeduheetfeetgfekheeileejhfelvdevjedt jeetffethfdtfeenucfkphepledurdduhedvrdejhedrudekkeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehtihhmohdrmhihhihrrgessghi thhtihhvihhrhhgvrdhfih X-ME-Proxy: Original-Received: from asteroid.bittivirhe.fi.bittivirhe.fi (91-152-75-188.elisa-laajakaista.fi [91.152.75.188]) by mail.messagingengine.com (Postfix) with ESMTPA id CAD1F328005E; Sat, 27 Jun 2020 08:51:51 -0400 (EDT) In-Reply-To: <83r1u03gtt.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 27 Jun 2020 14:10:06 +0300") Received-SPF: pass client-ip=66.111.4.28; envelope-from=timo.myyra@bittivirhe.fi; helo=out4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 08:51:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Sat, 27 Jun 2020 10:28:46 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252549 Archived-At: Eli Zaretskii writes: >> From: timo.myyra@bittivirhe.fi (Timo Myyr=C3=A4) >> Date: Sat, 27 Jun 2020 13:49:24 +0300 >>=20 >> While browsing the emacs code I noticed that pthread_set_name_np is not >> supported by emacs currently. Here's simple diff to add it. >> I'm not that well versed in autoconf, probably should check pthread_set_= name_np >> within the pthread_setname_np block so both won't get enabled at the sam= e time. >>=20 >> Also I'm not sure if name should be padded, quickly looking OpenBSD sour= ces >> didn't indicate that padding would be required. LLVM code base seems to = pad name >> argument to max 16 chars on FreeBSD and 32 on OpenBSD. >>=20 >> Thoughts? > > Thanks, we already have support for pthread_setname_np in what is soon > going to be released as Emacs 27.1. Please take a look at the > emacs-27 branch of the Emacs Git repository. Hi, OpenBSD and seems that FreeBSD don't have pthread_setname_np, they use pthread_set_name_np instead. But I got feedback that previous diff had typos so here is a better diff. I included the padding of max process name though it doesn't seem necessary= on OpenBSD. Timo diff --git a/configure.ac b/configure.ac index b1b8c846e1..f198894e02 100644 --- a/configure.ac +++ b/configure.ac @@ -4187,7 +4187,8 @@ AC_DEFUN sendto recvfrom getsockname getifaddrs freeifaddrs \ gai_strerror sync \ getpwent endpwent getgrent endgrent \ -cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np) +cfmakeraw cfsetspeed __executable_start log2 pthread_setname_np \ +pthread_set_name_np) LIBS=3D$OLD_LIBS =20 if test "$ac_cv_func_pthread_setname_np" =3D "yes"; then @@ -4222,6 +4223,23 @@ AC_DEFUN fi fi =20 +if test "$ac_cv_func_pthread_set_name_np" =3D "yes"; then + AC_CACHE_CHECK( + [whether pthread_set_name_np is supported], + [emacs_cv_pthread_set_name_np], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include ][#include ]], + [[pthread_setname_np (1, "a");]])], + [emacs_cv_pthread_set_name_np=3Dyes], + [emacs_cv_pthread_set_name_np=3Dno])]) + if test "$emacs_cv_pthread_set_name_np" =3D "yes"; then + AC_DEFINE( + HAVE_PTHREAD_SET_NAME_NP, 1, + [Define to 1 if pthread_set_name_np is supported.]) + fi +fi + dnl No need to check for posix_memalign if aligned_alloc works. AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break]) AC_CHECK_DECLS([aligned_alloc], [], [], [[#include ]]) diff --git a/src/systhread.c b/src/systhread.c index 0d600d6895..57005bacc3 100644 --- a/src/systhread.c +++ b/src/systhread.c @@ -26,6 +26,10 @@ Copyright (C) 2012-2020 Free Software Foundation, Inc. #include "nsterm.h" #endif =20 +#ifdef HAVE_PTHREAD_SET_NAME_NP +#include +#endif + #ifndef THREADS_ENABLED =20 void @@ -206,7 +210,7 @@ sys_thread_equal (sys_thread_t t, sys_thread_t u) void sys_thread_set_name (const char *name) { -#ifdef HAVE_PTHREAD_SETNAME_NP +#if defined HAVE_PTHREAD_SETNAME_NP || defined HAVE_PTHREAD_SET_NAME_NP /* We need to truncate here otherwise pthread_setname_np fails to set the name. TASK_COMM_LEN is what the length is called in the Linux kernel headers (Bug#38632). */ @@ -218,10 +222,13 @@ #define TASK_COMM_LEN 16 pthread_setname_np (p_name); # elif defined HAVE_PTHREAD_SETNAME_NP_3ARG pthread_setname_np (pthread_self (), "%s", p_name); +# elif HAVE_PTHREAD_SET_NAME_NP + pthread_set_name_np (pthread_self (), p_name); # else pthread_setname_np (pthread_self (), p_name); # endif #endif + } =20 bool