From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 1B0DE3810AC2 for ; Wed, 8 Jun 2022 19:00:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B0DE3810AC2 Received: by mail-oi1-x22b.google.com with SMTP id i66so29192139oia.11 for ; Wed, 08 Jun 2022 12:00:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:from:to:cc:references:in-reply-to :content-transfer-encoding; bh=0P1XOHlRJt/KhKmUbeQDOXvCGzxMbzZK8SSZ/mFG2CI=; b=5N91GVJvUgjxXoLUo0z7a5ZPMEiTa9uYDeE9aBF2uyhqKnpZHjRAU+hLnS54kYJskd XC+QwShdQeFFLtYPj7gb77V4sIDJBQIOTYDD1yh/+vUZGiHc/kyTz3BMc7dnP6dK+IJ8 OW6KEPnFSo8cEE2rTmg/NZ/ZLSH3TpSAzF/JHTsBOsb8p/GUcAh/rd8OE+qOSs5qLGUa uzeRsYnaeWS/6WP2I7hkfWHslgU724oCGweNUDR4+8v4KJzu4Egohx9Doj7ctSO15OSJ U4rIvhaNlfAAN0wuwmPQ2R/0fz3JHf67PfOizbEb85LAib/sNWufgIye6f3fXoTUcqNy 04mA== X-Gm-Message-State: AOAM532Q7i0Gtip/wQ1GE/EzyI/R43InhBp/GGYzPgHIdEAJ02JvOAen aGSwxp8X1ZqlAMDULvBD7IhFQQ== X-Google-Smtp-Source: ABdhPJzGGnVTKR9nc/wXfhtHYyrxr76fH5LtfMZaoKwZAJXOOvrIajz5AonXWysVYSaZ6Qld6FuHkA== X-Received: by 2002:a05:6808:140e:b0:32e:b362:34f with SMTP id w14-20020a056808140e00b0032eb362034fmr3348351oiv.276.1654714806991; Wed, 08 Jun 2022 12:00:06 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:a613:9260:25f7:781e:1ec9? ([2804:431:c7cb:a613:9260:25f7:781e:1ec9]) by smtp.gmail.com with ESMTPSA id 71-20020a9d014d000000b0060be71204casm7009688otu.53.2022.06.08.12.00.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 12:00:06 -0700 (PDT) Message-ID: Date: Wed, 8 Jun 2022 16:00:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 1/4] misc: Optimize internal usage of __libc_single_threaded Content-Language: en-US From: Adhemerval Zanella To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: Wilco Dijkstra References: <20220608164941.3325089-1-adhemerval.zanella@linaro.org> <20220608164941.3325089-2-adhemerval.zanella@linaro.org> <87wndrdp7p.fsf@oldenburg.str.redhat.com> <2bc8cf9f-7776-a32d-2c83-f34720f10d9f@linaro.org> In-Reply-To: <2bc8cf9f-7776-a32d-2c83-f34720f10d9f@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, 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-List-Received-Date: Wed, 08 Jun 2022 19:00:11 -0000 On 08/06/2022 15:14, Adhemerval Zanella wrote: > > > On 08/06/2022 14:44, Florian Weimer wrote: >> * Adhemerval Zanella via Libc-alpha: >> >>> diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c >>> index 3c4a19cf6b..18966900c4 100644 >>> --- a/elf/libc_early_init.c >>> +++ b/elf/libc_early_init.c >>> @@ -16,7 +16,9 @@ >>> License along with the GNU C Library; if not, see >>> . */ >>> >>> +#include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> @@ -38,6 +40,13 @@ __libc_early_init (_Bool initial) >>> __libc_single_threaded = initial; >>> >>> #ifdef SHARED >>> + /* _libc_single_thread can be accessed through copy relocations, so it >>> + requires to update the external copy. */ >>> + __libc_external_single_threaded = ___dlsym (RTLD_DEFAULT, >>> + "__libc_single_threaded"); >>> + assert (__libc_external_single_threaded != NULL); >>> + *__libc_external_single_threaded = initial; >>> + >>> __libc_initial = initial; >>> #endif >> >> Typo in the comment: [_]_libc_single_thread. > > Ack. > >> >> You must use __libc_dlsym, to avoid clobbering dlerror. No need to add >> ___dlsym. > > In fact we do need to use ___dlsym so we can use RTLD_DEFAULT, __libc_dlsym > does not support it and I am not sure how easy it would be do to it (I am > checking, but running in some issues). > Ok, I could make __libc_dlsym work with RTLD_DEFAULT, the trick is we need to use global cope instead of local one. >> >> Is it necessary to cache the address? > > Not really, but it a duplicated effort when pthread_create is called. > >> >>> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c >>> index e7a099acb7..5633d01c62 100644 >>> --- a/nptl/pthread_create.c >>> +++ b/nptl/pthread_create.c >>> @@ -627,7 +627,11 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, >>> if (__libc_single_threaded) >>> { >>> late_init (); >>> - __libc_single_threaded = 0; >>> + __libc_single_threaded = >>> +#ifdef SHARED >>> + *__libc_external_single_threaded = >>> +#endif >>> + 0; >>> } >>> >>> const struct pthread_attr *iattr = (struct pthread_attr *) attr; >> >> I think you can call __libc_dlsym here. >> >> Thanks, >> Florian >>