From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 20F133857823 for ; Thu, 28 Apr 2022 16:56:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20F133857823 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-61-xwfAq7KuOVmi9VEFMm0ZIA-1; Thu, 28 Apr 2022 12:56:12 -0400 X-MC-Unique: xwfAq7KuOVmi9VEFMm0ZIA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CC871014A66; Thu, 28 Apr 2022 16:56:12 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 402AE41615C; Thu, 28 Apr 2022 16:56:11 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH v2 3/4] Move libio lock single-thread optimization to generic libc-lock (BZ #27842) References: <20220426191523.833171-1-adhemerval.zanella@linaro.org> <20220426191523.833171-4-adhemerval.zanella@linaro.org> <87k0bahcwh.fsf@oldenburg.str.redhat.com> <40a536b8-32ac-51e3-0ac4-bc3d189c0711@linaro.org> <29e0538f-7f80-5e5b-9090-38b29c8fa23a@linaro.org> Date: Thu, 28 Apr 2022 18:56:09 +0200 In-Reply-To: <29e0538f-7f80-5e5b-9090-38b29c8fa23a@linaro.org> (Adhemerval Zanella's message of "Thu, 28 Apr 2022 13:39:18 -0300") Message-ID: <87a6c587va.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thu, 28 Apr 2022 16:56:15 -0000 * Adhemerval Zanella: >>>> (NAME).owner = NULL; \ >>>> - lll_unlock ((NAME).lock, LLL_PRIVATE); \ >>>> + if (!SINGLE_THREAD_P) \ >>>> + lll_unlock ((NAME).lock, LLL_PRIVATE); \ >>>> } \ >>>> } while (0) >>>> #else >>> >>> I don't think this is correct if threads are created in the lock region. >> >> I was not sure about this one and I think we the main issue in fact there is >> we can't use the single-thread optimization on unlock. Maybe a better option >> would to use a different scheme as proposed by >> https://hal.inria.fr/hal-01236734/document, where we can embedded lock and >> cnt in only one variable (as the lll_lock already does). > > Don't 99f841c441feeaa9a3d97fd91bb3d6ec8073c982 have the issue for pthread_mutex_lock ? No, that optimization follows our documented guidance, namely: | Most applications should perform the same actions whether or not | @code{__libc_single_threaded} is true, except with less | synchronization. If this rule is followed, a process that | subsequently becomes multi-threaded is already in a consistent state. Thanks, Florian