From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id 56FCC3858D28 for ; Wed, 27 Apr 2022 16:32:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56FCC3858D28 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-e5e433d66dso2504976fac.5 for ; Wed, 27 Apr 2022 09:32:35 -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:to:references:from:in-reply-to :content-transfer-encoding; bh=RwyyMijfJXw1hFSNkk7unDG4qEPz97n8fZK/KYauLTw=; b=LZHAe9vWh3GI0SNRKgNW4AnQfGsOAkpG0ufFPJh/tVa3ttsIeqMhdnnLEedV8qBrGR /O4lcR69Uque3kvhJHOdNOjJdrs1PrsqHpRp7rVteCRg3ItQJlGsMwMuThKSw4kd1HnA emdpDN/qv+ZC0oWOCSgxngwwV22fDxSC0/LvDlHrsUHvTkxv5i4i+JSe4AvutQHa+de7 WOVlxmTtQ2gqK3xlgwsTwADDfb7e/yChtfhjkpF7JJeGVahSzPfXL2l/N02NPSNMLPkN QtfXMJ8QOY7ok6yOrYzMpuo98Knss49RE/GrG/eFk40uj/FDLCnSKLOtHkCbMhziCJkJ /ZXw== X-Gm-Message-State: AOAM532d4IzU8ga7O0qzgWOXr0krDxHjq2mkUwjwdrq7R1HNFJyZ4XPB iUG5UQAWm2b9kIL6krweZ/gHiA== X-Google-Smtp-Source: ABdhPJxfwd/efzq/wN5UPV/oeXubUM4b8+YpeELUeIwdJ4bFs6ciFhPmWKHzjAsVxcwIlhHu0FG7LA== X-Received: by 2002:a05:6870:e991:b0:de:e86c:99be with SMTP id r17-20020a056870e99100b000dee86c99bemr11867080oao.278.1651077154561; Wed, 27 Apr 2022 09:32:34 -0700 (PDT) Received: from ?IPV6:2804:431:c7ca:4214:b613:182d:cdde:5f86? ([2804:431:c7ca:4214:b613:182d:cdde:5f86]) by smtp.gmail.com with ESMTPSA id z16-20020a9d65d0000000b00605e45cfda6sm168683oth.34.2022.04.27.09.32.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 09:32:33 -0700 (PDT) Message-ID: <40a536b8-32ac-51e3-0ac4-bc3d189c0711@linaro.org> Date: Wed, 27 Apr 2022 13:32:31 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v2 3/4] Move libio lock single-thread optimization to generic libc-lock (BZ #27842) Content-Language: en-US To: Florian Weimer , Adhemerval Zanella via Libc-alpha References: <20220426191523.833171-1-adhemerval.zanella@linaro.org> <20220426191523.833171-4-adhemerval.zanella@linaro.org> <87k0bahcwh.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87k0bahcwh.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Wed, 27 Apr 2022 16:32:38 -0000 On 27/04/2022 10:30, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> diff --git a/sysdeps/nptl/libc-lock.h b/sysdeps/nptl/libc-lock.h >> index 6c2d6acfd1..abd84e71b4 100644 >> --- a/sysdeps/nptl/libc-lock.h >> +++ b/sysdeps/nptl/libc-lock.h >> @@ -86,7 +86,7 @@ typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t; >> # define __libc_lock_lock_recursive(NAME) \ >> do { \ >> void *self = THREAD_SELF; \ >> - if ((NAME).owner != self) \ >> + if (!SINGLE_THREAD_P && (NAME).owner != self) \ >> { \ >> lll_lock ((NAME).lock, LLL_PRIVATE); \ >> (NAME).owner = self; \ >> @@ -104,7 +104,7 @@ typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t; >> ({ \ >> int result = 0; \ >> void *self = THREAD_SELF; \ >> - if ((NAME).owner != self) \ >> + if (!SINGLE_THREAD_P && (NAME).owner != self) \ >> { \ >> if (lll_trylock ((NAME).lock) == 0) \ >> { \ >> @@ -131,7 +131,8 @@ typedef struct { int lock; int cnt; void *owner; } __libc_lock_recursive_t; >> if (--(NAME).cnt == 0) \ >> { \ >> (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).