From patchwork Tue Jun 21 20:32:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 55240 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08AB63857033 for ; Tue, 21 Jun 2022 20:35:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08AB63857033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655843719; bh=dxq6KxSsANmdsSAWWqp7RPQs8rkh1tK0bIl4hdnigt0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=M3ZKBom14p0Cyzkwhf6MFEV1C0WL1W9tpnSslRhg/sVd/plINlVkn2dM+uCQBtj3t zXES2PFz6zjAmm+wRctV2ge3+Fjpl6WEaWGDmeVhtMUrGCALE+GZBNE/bCMffRkSD3 CNpvkiq0bANFM1xK9SR5yJ5q7PutrHmqrQ0ttGpo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 823DE3856DC5 for ; Tue, 21 Jun 2022 20:32:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 823DE3856DC5 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-fb6b4da1dfso19860024fac.4 for ; Tue, 21 Jun 2022 13:32:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dxq6KxSsANmdsSAWWqp7RPQs8rkh1tK0bIl4hdnigt0=; b=hg1jQBHYgJ0Cj7zVtuyuNmMTre5ALbOacozUBtrDaBqDQ6r/5GI47DRDy2KVxYQPEs HT9VZO//ndEY2Ci57kWj2W7oVyGGr4gbKDAHAsn+P1GKW+eTWrRFyK94LC7wFtekaNAc f2Rh6UzJpus75qmRRW88mnp5Z6IM6yk9gjaeimv2Z/rExFzqSzD/WKYy8nn7r/moe0Is FlIoJNlWv+r2NN3tucGNmxxeB0AgEmH0EOwIB9U3wSgGSdPvxysUd7bMOoF2zjPxnDwh qGqbVbW1pwP40UMLUPEagYEETRKdHoSY9Ge2xIpgHs6uKP3CazicOQNmMMtX5dthLzl0 v2XQ== X-Gm-Message-State: AJIora/WuBw2JvZHQ8uepqE7m7ejxM5s3OwKgxdhcRdPGzIgb8o1sFa5 NOq7fN6PVGrcWczMOKE8exU6sIdRC0g9Aw== X-Google-Smtp-Source: AGRyM1sc/0R4Jn6koCYxalLQiIThwJJ++jT2vWiTbKWtifAk5qzoGe/h1909wWHgcJvLzRY0H9hUAQ== X-Received: by 2002:a05:6870:a9a4:b0:e6:4451:f4b0 with SMTP id ep36-20020a056870a9a400b000e64451f4b0mr22784036oab.252.1655843552730; Tue, 21 Jun 2022 13:32:32 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:6d95:e2fc:bea2:ccdc:f4a]) by smtp.gmail.com with ESMTPSA id v21-20020a056870e49500b00101f9e87b39sm3779567oag.11.2022.06.21.13.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 13:32:32 -0700 (PDT) To: libc-alpha@sourceware.org, Wilco Dijkstra , Fangrui Song Subject: [PATCH v3 2/4] Replace __libc_multiple_threads with __libc_single_threaded Date: Tue, 21 Jun 2022 17:32:23 -0300 Message-Id: <20220621203225.714328-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220621203225.714328-1-adhemerval.zanella@linaro.org> References: <20220621203225.714328-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" And also fixes the SINGLE_THREAD_P macro for SINGLE_THREAD_BY_GLOBAL, since header inclusion single-thread.h is in the wrong order, the define needs to come before including sysdeps/unix/sysdep.h. The macro is now moved to a per-arch single-threade.h header. The SINGLE_THREAD_P is used on some more places. Checked on aarch64-linux-gnu and x86_64-linux-gnu. --- nptl/Makefile | 1 - nptl/allocatestack.c | 6 ---- nptl/libc_multiple_threads.c | 28 ------------------- nptl/pthread_cancel.c | 2 +- posix/fork.c | 2 +- sysdeps/nptl/setxid.h | 2 +- .../unix/sysv/linux/aarch64/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/aarch64/sysdep.h | 2 -- sysdeps/unix/sysv/linux/alpha/sysdep.h | 2 -- sysdeps/unix/sysv/linux/arc/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/arc/sysdep.h | 2 -- sysdeps/unix/sysv/linux/arm/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/arm/sysdep.h | 2 -- sysdeps/unix/sysv/linux/hppa/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/hppa/sysdep.h | 2 -- .../sysv/linux/microblaze/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/microblaze/sysdep.h | 2 -- sysdeps/unix/sysv/linux/s390/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/s390/sysdep.h | 3 -- sysdeps/unix/sysv/linux/single-thread.h | 11 ++++---- .../unix/sysv/linux/x86_64/single-thread.h | 2 ++ sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 -- 22 files changed, 22 insertions(+), 61 deletions(-) delete mode 100644 nptl/libc_multiple_threads.c create mode 100644 sysdeps/unix/sysv/linux/aarch64/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/arc/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/arm/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/hppa/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/microblaze/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/s390/single-thread.h create mode 100644 sysdeps/unix/sysv/linux/x86_64/single-thread.h diff --git a/nptl/Makefile b/nptl/Makefile index b585663974..3d2ce8af8a 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -50,7 +50,6 @@ routines = \ events \ futex-internal \ libc-cleanup \ - libc_multiple_threads \ lowlevellock \ nptl-stack \ nptl_deallocate_tsd \ diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 01a282f3f6..98f5f6dd85 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -292,9 +292,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* This is at least the second thread. */ pd->header.multiple_threads = 1; -#ifndef TLS_MULTIPLE_THREADS_IN_TCB - __libc_multiple_threads = 1; -#endif #ifdef NEED_DL_SYSINFO SETUP_THREAD_SYSINFO (pd); @@ -413,9 +410,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* This is at least the second thread. */ pd->header.multiple_threads = 1; -#ifndef TLS_MULTIPLE_THREADS_IN_TCB - __libc_multiple_threads = 1; -#endif #ifdef NEED_DL_SYSINFO SETUP_THREAD_SYSINFO (pd); diff --git a/nptl/libc_multiple_threads.c b/nptl/libc_multiple_threads.c deleted file mode 100644 index 0c2dc33d0d..0000000000 --- a/nptl/libc_multiple_threads.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2002-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#if IS_IN (libc) -# ifndef TLS_MULTIPLE_THREADS_IN_TCB -/* Variable set to a nonzero value either if more than one thread runs or ran, - or if a single-threaded process is trying to cancel itself. See - nptl/descr.h for more context on the single-threaded process case. */ -int __libc_multiple_threads; -libc_hidden_data_def (__libc_multiple_threads) -# endif -#endif diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index e67b2df5cc..459317df49 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -161,7 +161,7 @@ __pthread_cancel (pthread_t th) points get executed. */ THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); #ifndef TLS_MULTIPLE_THREADS_IN_TCB - __libc_multiple_threads = 1; + __libc_single_threaded_internal = 0; #endif } while (!atomic_compare_exchange_weak_acquire (&pd->cancelhandling, &oldval, diff --git a/posix/fork.c b/posix/fork.c index 987916a175..cee5ae83c8 100644 --- a/posix/fork.c +++ b/posix/fork.c @@ -45,7 +45,7 @@ __libc_fork (void) requirement for fork (Austin Group tracker issue #62) this is best effort to make is async-signal-safe at least for single-thread case. */ - bool multiple_threads = __libc_single_threaded_internal == 0; + bool multiple_threads = !SINGLE_THREAD_P; uint64_t lastrun; lastrun = __run_prefork_handlers (multiple_threads); diff --git a/sysdeps/nptl/setxid.h b/sysdeps/nptl/setxid.h index b87cad7b18..3a412179ac 100644 --- a/sysdeps/nptl/setxid.h +++ b/sysdeps/nptl/setxid.h @@ -29,7 +29,7 @@ #define INLINE_SETXID_SYSCALL(name, nr, args...) \ ({ \ int __result; \ - if (!__libc_single_threaded_internal) \ + if (!SINGLE_THREAD_P) \ { \ struct xid_command __cmd; \ __cmd.syscall_no = __NR_##name; \ diff --git a/sysdeps/unix/sysv/linux/aarch64/single-thread.h b/sysdeps/unix/sysv/linux/aarch64/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h index 3b230dccf1..f1853e012f 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h @@ -164,8 +164,6 @@ # define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime" # define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday" -# define SINGLE_THREAD_BY_GLOBAL 1 - # undef INTERNAL_SYSCALL_RAW # define INTERNAL_SYSCALL_RAW(name, nr, args...) \ ({ long _sys_result; \ diff --git a/sysdeps/unix/sysv/linux/alpha/sysdep.h b/sysdeps/unix/sysv/linux/alpha/sysdep.h index 3051a744b4..77ec2b5400 100644 --- a/sysdeps/unix/sysv/linux/alpha/sysdep.h +++ b/sysdeps/unix/sysv/linux/alpha/sysdep.h @@ -32,8 +32,6 @@ #undef SYS_ify #define SYS_ify(syscall_name) __NR_##syscall_name -#define SINGLE_THREAD_BY_GLOBAL 1 - #ifdef __ASSEMBLER__ #include #include diff --git a/sysdeps/unix/sysv/linux/arc/single-thread.h b/sysdeps/unix/sysv/linux/arc/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arc/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h index 29b0e0161c..d0c1a78381 100644 --- a/sysdeps/unix/sysv/linux/arc/sysdep.h +++ b/sysdeps/unix/sysv/linux/arc/sysdep.h @@ -132,8 +132,6 @@ L (call_syscall_err): ASM_LINE_SEP \ #else /* !__ASSEMBLER__ */ -# define SINGLE_THREAD_BY_GLOBAL 1 - # if IS_IN (libc) extern long int __syscall_error (long int); hidden_proto (__syscall_error) diff --git a/sysdeps/unix/sysv/linux/arm/single-thread.h b/sysdeps/unix/sysv/linux/arm/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/arm/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h index 7bdd218063..1f270b961e 100644 --- a/sysdeps/unix/sysv/linux/arm/sysdep.h +++ b/sysdeps/unix/sysv/linux/arm/sysdep.h @@ -408,8 +408,6 @@ __local_syscall_error: \ #define INTERNAL_SYSCALL_NCS(number, nr, args...) \ INTERNAL_SYSCALL_RAW (number, nr, args) -#define SINGLE_THREAD_BY_GLOBAL 1 - #endif /* __ASSEMBLER__ */ #endif /* linux/arm/sysdep.h */ diff --git a/sysdeps/unix/sysv/linux/hppa/single-thread.h b/sysdeps/unix/sysv/linux/hppa/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/hppa/sysdep.h b/sysdeps/unix/sysv/linux/hppa/sysdep.h index 42f7705852..2f339a4bd6 100644 --- a/sysdeps/unix/sysv/linux/hppa/sysdep.h +++ b/sysdeps/unix/sysv/linux/hppa/sysdep.h @@ -474,6 +474,4 @@ L(pre_end): ASM_LINE_SEP \ #define PTR_MANGLE(var) (void) (var) #define PTR_DEMANGLE(var) (void) (var) -#define SINGLE_THREAD_BY_GLOBAL 1 - #endif /* _LINUX_HPPA_SYSDEP_H */ diff --git a/sysdeps/unix/sysv/linux/microblaze/single-thread.h b/sysdeps/unix/sysv/linux/microblaze/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/microblaze/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h index dfd6312506..fda78f6467 100644 --- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h +++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h @@ -308,8 +308,6 @@ SYSCALL_ERROR_LABEL_DCL: \ # define PTR_MANGLE(var) (void) (var) # define PTR_DEMANGLE(var) (void) (var) -# define SINGLE_THREAD_BY_GLOBAL 1 - #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1 diff --git a/sysdeps/unix/sysv/linux/s390/single-thread.h b/sysdeps/unix/sysv/linux/s390/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/s390/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/s390/sysdep.h b/sysdeps/unix/sysv/linux/s390/sysdep.h index 78c7e8c7e2..2d0a26779c 100644 --- a/sysdeps/unix/sysv/linux/s390/sysdep.h +++ b/sysdeps/unix/sysv/linux/s390/sysdep.h @@ -93,9 +93,6 @@ #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6) #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7) -#define SINGLE_THREAD_BY_GLOBAL 1 - - #define VDSO_NAME "LINUX_2.6.29" #define VDSO_HASH 123718585 diff --git a/sysdeps/unix/sysv/linux/single-thread.h b/sysdeps/unix/sysv/linux/single-thread.h index 4529a906d2..30dde4e81a 100644 --- a/sysdeps/unix/sysv/linux/single-thread.h +++ b/sysdeps/unix/sysv/linux/single-thread.h @@ -19,6 +19,10 @@ #ifndef _SINGLE_THREAD_H #define _SINGLE_THREAD_H +#ifndef __ASSEMBLER__ +# include +#endif + /* The default way to check if the process is single thread is by using the pthread_t 'multiple_threads' field. However, for some architectures it is faster to either use an extra field on TCB or global variables (the TCB @@ -27,16 +31,11 @@ The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single thread check to use global variables instead of the pthread_t field. */ -#ifndef __ASSEMBLER__ -extern int __libc_multiple_threads; -libc_hidden_proto (__libc_multiple_threads) -#endif - #if !defined SINGLE_THREAD_BY_GLOBAL || IS_IN (rtld) # define SINGLE_THREAD_P \ (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0) #else -# define SINGLE_THREAD_P (__libc_multiple_threads == 0) +# define SINGLE_THREAD_P (__libc_single_threaded_internal != 0) #endif #define RTLD_SINGLE_THREAD_P SINGLE_THREAD_P diff --git a/sysdeps/unix/sysv/linux/x86_64/single-thread.h b/sysdeps/unix/sysv/linux/x86_64/single-thread.h new file mode 100644 index 0000000000..a5d3a2aaf4 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86_64/single-thread.h @@ -0,0 +1,2 @@ +#define SINGLE_THREAD_BY_GLOBAL +#include_next diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h index e1ce3b62eb..740abefcfd 100644 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h @@ -379,8 +379,6 @@ # define HAVE_CLONE3_WRAPPER 1 -# define SINGLE_THREAD_BY_GLOBAL 1 - #endif /* __ASSEMBLER__ */