From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 3B1053858407 for ; Thu, 20 Jan 2022 12:54:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B1053858407 Received: by mail-pf1-x436.google.com with SMTP id x37so1498819pfh.8 for ; Thu, 20 Jan 2022 04:54:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KUfxZm/X9Id3o6XhhpiROZ3WCKgBgBwX96bnT6KKJPQ=; b=Ju2VMd5EsUCN64ApryBu3dq9aE7PSDT0kIjsXlLDl+E+re+VhHFyk0ITdaFnnAa5w/ GSa/o3/SdZNcJZZkckHpd/0OrTq4BP4INWkw+1e5h6gtQa/4DqN/TkEEb9u4G9okVDAO 6MjbmZ7nBSY7yWDyr7D1KPykZbBq5LpKZhX1gzhhbnVTPCjBsy+GFWvf4GrwwycpCoWL KSEQjxRdOtzLD67VCS53BKCn5AWVW/7kalvjLb1j4SyScVzh18TDkhR8GK4+JV9utSkW BXYV4KYCXfzmSaiDl80rZQYu2zSYV6/JL3gQfnoAg4MSBgPaC4VngVReDJeFXhtknDKf /Z2A== X-Gm-Message-State: AOAM532W6mRJrzuad4HG/3eK32eWDjtiA3PANtM/bYhJFW+EGGQBGoqu 4KcTSqspSHNeD/tBEDrwX1MtWInRvdiVpDxuLcddy1lA5RI= X-Google-Smtp-Source: ABdhPJzH0UMsm/PTqePxeRVJX45Ii5dGXnu+f+nfQXP95ZyZbLdUemlc5yXFh5ux9jvt1N7syChArWGs/GzqeC1SeSc= X-Received: by 2002:a05:6a00:234e:b0:4ae:2e0d:cc68 with SMTP id j14-20020a056a00234e00b004ae2e0dcc68mr35893319pfj.60.1642683243253; Thu, 20 Jan 2022 04:54:03 -0800 (PST) MIME-Version: 1.0 References: <20211214123051.800-1-6812skiii@gmail.com> In-Reply-To: <20211214123051.800-1-6812skiii@gmail.com> From: "H.J. Lu" Date: Thu, 20 Jan 2022 04:53:27 -0800 Message-ID: Subject: Re: [PATCH v3] nptl: Effectively skip CAS in spinlock loop To: Jangwoong Kim <6812skiii@gmail.com> Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3027.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: Thu, 20 Jan 2022 12:54:05 -0000 On Tue, Dec 14, 2021 at 4:31 AM Jangwoong Kim via Libc-alpha wrote: > > The commit: > "Add LLL_MUTEX_READ_LOCK [BZ #28537]" > SHA1: d672a98a1af106bd68deb15576710cd61363f7a6 > > introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop > if atomic load fails. But, "continue" inside of do-while loop > does not skip the evaluation of escape expression, thus CAS > is not skipped. > > Replace do-while with while and skip LLL_MUTEX_TRYLOCK if > LLL_MUTEX_READ_LOCK fails. > --- > nptl/pthread_mutex_lock.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c > index 47b88a6b5b..06274c68e4 100644 > --- a/nptl/pthread_mutex_lock.c > +++ b/nptl/pthread_mutex_lock.c > @@ -138,7 +138,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex) > int cnt = 0; > int max_cnt = MIN (max_adaptive_count (), > mutex->__data.__spins * 2 + 10); > - do > + while (LLL_MUTEX_READ_LOCK (mutex) != 0 || LLL_MUTEX_TRYLOCK (mutex) != 0) > { > if (cnt++ >= max_cnt) > { > @@ -146,10 +146,7 @@ PTHREAD_MUTEX_LOCK (pthread_mutex_t *mutex) > break; > } > atomic_spin_nop (); > - if (LLL_MUTEX_READ_LOCK (mutex) != 0) > - continue; > } > - while (LLL_MUTEX_TRYLOCK (mutex) != 0); > > mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8; > } > -- > 2.25.1 > LGTM. Reviewed-by: H.J. Lu Thanks. -- H.J.