[0/4] Simplify internal single-threaded usage
Message ID | 20220608164941.3325089-1-adhemerval.zanella@linaro.org |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 279B63850215 for <patchwork@sourceware.org>; Wed, 8 Jun 2022 16:50:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 279B63850215 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1654707052; bh=Ii1g158KPJCjcbOWvKU3LBrLCYRSY2OzVGm7iB2qx28=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nMv28SQwvA9JJXgT9Bxg9kNbeoiWlA9z3JSraJE1ZU/elM7SMP9KTcZAqLSvPTv5G Tj/uLWiQqZs3SNNc8x/0oxVpemYAfim5lc6b+/DBsp2cy5cn+0b7mV33/BJ4kNMMhg /LvAgdOmAjwcIwH8dJuvDfvkZ5OesOdC4pWhXjww= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 9F1C0385C312 for <libc-alpha@sourceware.org>; Wed, 8 Jun 2022 16:49:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F1C0385C312 Received: by mail-oi1-x22f.google.com with SMTP id w16so18912915oie.5 for <libc-alpha@sourceware.org>; Wed, 08 Jun 2022 09:49:46 -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:mime-version :content-transfer-encoding; bh=Ii1g158KPJCjcbOWvKU3LBrLCYRSY2OzVGm7iB2qx28=; b=DShKGfMM0gKbb3SniKXKTgO9PKb+eg1xnW5Knlo/Fzpfh1TLc400mlynuiKvfpnG0i 3hBiPNqWndPtj34aFRYj997AP5QE13RdmTbN57Hzefs3FRgH60bU9S+ZPLeM2e1b3WS1 eeFLzIn3yxcjgEx4/PsHabiuBjFbggcM+qeSj0fZekPBVJSEJV0H7mFQ0JYEf3gk2Zr5 ymWsD6+XUng/rsl9YBFI5axCmyJstB8pTTjlJz2mcAEA6Dv9XheBQsbExpqjJoNmx9m8 /pHlONMhAd+LZJ4SMOhO3DnX+DGR9fnG4dmPX0KHP41IDDh2sMxma+9U+f8+Z2mpSoYa lbcw== X-Gm-Message-State: AOAM533xNhl8zN64qlssbnDkVWHVE4wa1zwC+MWZ3YCWqZ05pwcJKlsC 9e4w2IAYItzxz923rX5+LXF5FDb1JVyYQQ== X-Google-Smtp-Source: ABdhPJwsxjkYOL9G+CMWFwcpJ+dK5a8RdoUBbGsaSEmqG3wFsBq38QSWlZqgAlHZh3+Yu5b68w1jTA== X-Received: by 2002:a05:6808:10c1:b0:326:de29:1fb8 with SMTP id s1-20020a05680810c100b00326de291fb8mr2897229ois.62.1654706985645; Wed, 08 Jun 2022 09:49:45 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:a613:9260:25f7:781e:1ec9]) by smtp.gmail.com with ESMTPSA id j22-20020a056808035600b0032e3cca8561sm7064451oie.21.2022.06.08.09.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:49:45 -0700 (PDT) To: libc-alpha@sourceware.org, Wilco Dijkstra <Wilco.Dijkstra@arm.com> Subject: [PATCH 0/4] Simplify internal single-threaded usage Date: Wed, 8 Jun 2022 13:49:37 -0300 Message-Id: <20220608164941.3325089-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Adhemerval Zanella <adhemerval.zanella@linaro.org> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Message
Adhemerval Zanella Netto
June 8, 2022, 4:49 p.m. UTC
Glibc currently has three different internal ways to check if a process is single-threaded: the exported global variable __libc_single_threaded, the internal-only __libc_multiple_threads, and the variant used by some architectures and allocated on TCB, multiple_threads. Also each port can define SINGLE_THREAD_BY_GLOBAL to either use __libc_multiple_threads or multiple_threads. The __libc_single_threaded and __libc_multiple_threads have essentially the semantic: both are global variables where the value is not reset if/when the process becomes single-threaded. The issue of using __libc_single_threaded internally is since it is accessed through copy relocation, both values must be updated. This is fixed in the first patch. The second replaces __libc_multiple_threads with __libc_single_threaded, while also fixing a bug where architecture that defines SINGLE_THREAD_BY_GLOBAL did not actually enable the optimization. The third patch replaces multiple_threads with __libc_single_threaded, to simplify a possible single-thread lock optimization. On most architectures, accessing an internal global variable should be as fast as through the TCB (it seems that only legacy ABIs that require extra code sequence to materialize global access, such as i686 and sparc, using the TCB would be faster). The i686 seems to be the only architecture that optimizes the lock access directly by reimplementing the atomic operations. In this case some as rewritten using compiler builtins along with SINGLE_THREAD_P macro, while other unused macros are just removed (for instance atomic_add_zero). The idea is to just phase out this specific atomic implementation in favor of compiler builtins and move the single-thread optimization to be arch-neutral. The last patch just remove the single-thread.h header and move the definition to internal sys/single_threaded.h, so now there is only one place to add such optimization. Adhemerval Zanella (4): misc: Optimize internal usage of __libc_single_threaded Replace __libc_multiple_threads with __libc_single_threaded Remove usage of TLS_MULTIPLE_THREADS_IN_TCB Remove single-thread.h dlfcn/dlsym.c | 1 + elf/libc_early_init.c | 9 + include/dlfcn.h | 4 + include/sys/single_threaded.h | 20 +- misc/single_threaded.c | 2 + misc/tst-atomic.c | 1 + nptl/Makefile | 1 - nptl/allocatestack.c | 12 - nptl/descr.h | 17 +- nptl/libc_multiple_threads.c | 28 -- nptl/pthread_cancel.c | 9 +- nptl/pthread_create.c | 11 +- sysdeps/generic/single-thread.h | 25 -- sysdeps/i386/htl/tcb-offsets.sym | 1 - sysdeps/i386/nptl/tcb-offsets.sym | 1 - sysdeps/i386/nptl/tls.h | 4 +- sysdeps/ia64/nptl/tcb-offsets.sym | 1 - sysdeps/ia64/nptl/tls.h | 2 - sysdeps/mach/hurd/i386/tls.h | 4 +- sysdeps/mach/hurd/sysdep-cancel.h | 5 - sysdeps/nios2/nptl/tcb-offsets.sym | 1 - sysdeps/or1k/nptl/tls.h | 2 - sysdeps/powerpc/nptl/tcb-offsets.sym | 3 - sysdeps/powerpc/nptl/tls.h | 3 - sysdeps/s390/nptl/tcb-offsets.sym | 1 - sysdeps/s390/nptl/tls.h | 6 +- sysdeps/sh/nptl/tcb-offsets.sym | 1 - sysdeps/sh/nptl/tls.h | 2 - sysdeps/sparc/nptl/tcb-offsets.sym | 1 - sysdeps/sparc/nptl/tls.h | 2 +- sysdeps/unix/sysdep.h | 2 +- sysdeps/unix/sysv/linux/aarch64/sysdep.h | 2 - sysdeps/unix/sysv/linux/alpha/sysdep.h | 2 - sysdeps/unix/sysv/linux/arc/sysdep.h | 2 - sysdeps/unix/sysv/linux/arm/sysdep.h | 2 - sysdeps/unix/sysv/linux/hppa/sysdep.h | 2 - sysdeps/unix/sysv/linux/microblaze/sysdep.h | 2 - sysdeps/unix/sysv/linux/s390/sysdep.h | 3 - sysdeps/unix/sysv/linux/single-thread.h | 44 --- sysdeps/unix/sysv/linux/x86_64/sysdep.h | 2 - sysdeps/x86/atomic-machine.h | 327 +++----------------- sysdeps/x86_64/nptl/tcb-offsets.sym | 1 - 42 files changed, 96 insertions(+), 475 deletions(-) delete mode 100644 nptl/libc_multiple_threads.c delete mode 100644 sysdeps/generic/single-thread.h delete mode 100644 sysdeps/unix/sysv/linux/single-thread.h