From patchwork Fri Dec 4 18:09:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 41311 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 136823982436; Fri, 4 Dec 2020 18:10:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 136823982436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607105401; bh=z2PuZZyF52PbcV1T1SVY5r3C1jVugGfL/3wjbDSHDbM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=c2tw2TzKGNhzKmbLK6ElJnSP6BvDQLXw3713WLhjUIYnB6fmd0i966mjOEOR+ivrQ b2O6ukv1Uhcy5BpRdwDzP6lyalbsOXUqhMFdAFAN4sh7cZOeixDY1mKEoagyIuf5Ux txuSplp25mwj17Hk8kaBJl6q3b221dGf5jqvbztI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id 1E3D0398242C for ; Fri, 4 Dec 2020 18:09:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1E3D0398242C Received: by mail-qk1-x742.google.com with SMTP id x25so6286216qkj.3 for ; Fri, 04 Dec 2020 10:09:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z2PuZZyF52PbcV1T1SVY5r3C1jVugGfL/3wjbDSHDbM=; b=M/Yj0XEYZr38JZ+Iqprm3lMcCCqEKZEJ3aD7/ItStu7TQGER1f46F/QDt+5Cqw0F1y VnetTJnWLz1seJbZXMykObrp1zmkVcdSHLveTcMjkPvWw53cr/BRUTvcKwrbt+v4CAFq C08kK5QDkrQxOLu7yDR/QrlWn0OcfHyaW77Jme9dz6ojAZtfwT4sJJ4PdLsWoi+KH/gD ek/fjoeuItrVcqOOEQhOjCaN7IU01uDj0hTAtuBis7Ow7BuE5m64It4KC015tlQULekp PSZjYb4Fi+TPkRQQUDcbp6PCZMWOFngLeCONmhXgIxmJnF53OLWwDmOVyX/mzlDq9IQe xqBg== X-Gm-Message-State: AOAM530/w3poYTBpPr/fbmI5Iz/RQfwp0k/hARvFjdF1Fe3syNH2Rc9L iXezcSX1+5Yofu+qhN8TV3DhFZRSYLg6gw== X-Google-Smtp-Source: ABdhPJy6dJ5sO7MmfTaTWPi6J303emqhpJLGrgvkO6L2uRNnsrqjPSwXH8xXgEx8moN9QJXg13rVWw== X-Received: by 2002:ae9:f816:: with SMTP id x22mr10084283qkh.291.1607105396225; Fri, 04 Dec 2020 10:09:56 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id b33sm6179827qta.62.2020.12.04.10.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 10:09:55 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 4/6] nptl: Initialize tid earlier Date: Fri, 4 Dec 2020 15:09:42 -0300 Message-Id: <20201204180944.3774769-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204180944.3774769-1-adhemerval.zanella@linaro.org> References: <20201204180944.3774769-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Reply-To: Adhemerval Zanella Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It sets the PD tid value as once pthread is initialized, the idea is to allow raise being implemented by pthread_kill and avoid a gettid call. Checked on x86_64-linux-gnu. --- csu/libc-tls.c | 3 +++ elf/rtld.c | 3 +++ nptl/nptl-init.c | 5 ++--- {nptl => sysdeps/htl}/pthread-pids.h | 13 +++---------- sysdeps/{unix/sysv/linux => nptl}/pthread-pids.h | 11 +++++++---- 5 files changed, 18 insertions(+), 17 deletions(-) rename {nptl => sysdeps/htl}/pthread-pids.h (61%) rename sysdeps/{unix/sysv/linux => nptl}/pthread-pids.h (70%) diff --git a/csu/libc-tls.c b/csu/libc-tls.c index c3589f0a7d..54fd085420 100644 --- a/csu/libc-tls.c +++ b/csu/libc-tls.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef SHARED #error makefile bug, this file is for static only @@ -219,4 +220,6 @@ __libc_setup_tls (void) #endif init_static_tls (memsz, MAX (TLS_TCB_ALIGN, max_align)); + + pthread_initialize_pids (THREAD_SELF); } diff --git a/elf/rtld.c b/elf/rtld.c index c4ffc8d4b7..d01ba55a57 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -805,6 +806,8 @@ cannot allocate TLS data structures for initial thread\n"); #endif tls_init_tp_called = true; + pthread_initialize_pids (THREAD_SELF); + return tcbp; } diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index 53b817715d..489023dee6 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #ifndef TLS_MULTIPLE_THREADS_IN_TCB @@ -225,9 +224,9 @@ static bool __nptl_initial_report_events __attribute_used__; void __pthread_initialize_minimal_internal (void) { - /* Minimal initialization of the thread descriptor. */ + /* Minimal initialization of the thread descriptor. + pd->tid was set during TLS initialization. */ struct pthread *pd = THREAD_SELF; - __pthread_initialize_pids (pd); THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]); THREAD_SETMEM (pd, user_stack, true); diff --git a/nptl/pthread-pids.h b/sysdeps/htl/pthread-pids.h similarity index 61% rename from nptl/pthread-pids.h rename to sysdeps/htl/pthread-pids.h index b2a8349d0e..54c9cbca2e 100644 --- a/nptl/pthread-pids.h +++ b/sysdeps/htl/pthread-pids.h @@ -1,5 +1,5 @@ -/* Initialize pid and tid fields of struct pthread. Stub version. - Copyright (C) 2015-2020 Free Software Foundation, Inc. +/* Initialize pid and tid fields of struct pthread. Hurd version. + Copyright (C) 2020 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 @@ -16,14 +16,7 @@ License along with the GNU C Library; if not, see . */ -#include - -/* Initialize PD->pid and PD->tid for the initial thread. If there is - setup required to arrange that __exit_thread causes PD->tid to be - cleared and futex-woken, then this function should do that as well. */ static inline void -__pthread_initialize_pids (struct pthread *pd) +pthread_initialize_pids (tcbhead_t *pd) { -#error "sysdeps pthread-pids.h file required" - pd->pid = pd->tid = -1; } diff --git a/sysdeps/unix/sysv/linux/pthread-pids.h b/sysdeps/nptl/pthread-pids.h similarity index 70% rename from sysdeps/unix/sysv/linux/pthread-pids.h rename to sysdeps/nptl/pthread-pids.h index 0b8ca4ec06..32fb2d937d 100644 --- a/sysdeps/unix/sysv/linux/pthread-pids.h +++ b/sysdeps/nptl/pthread-pids.h @@ -16,14 +16,17 @@ License along with the GNU C Library; if not, see . */ -#include #include -/* Initialize PD->pid and PD->tid for the initial thread. If there is - setup required to arrange that __exit_thread causes PD->tid to be +/* Initialize only as much of the initial thread's descriptor as is necessary + even when libpthread is not loaded. More will be done by + __pthread_initialize_minimal if libpthread is loaded. This needs to happen + before anything that could possibly call raise, but cannot happen before + TLS is initialized. + If there is setup required to that __exit_thread causes PD->tid to be cleared and futex-woken, then this function should do that as well. */ static inline void -__pthread_initialize_pids (struct pthread *pd) +pthread_initialize_pids (struct pthread *pd) { pd->tid = INTERNAL_SYSCALL_CALL (set_tid_address, &pd->tid); }