From patchwork Thu Nov 11 16:24:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 47483 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 B28FD385841A for ; Thu, 11 Nov 2021 16:24:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B28FD385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636647892; bh=9KxeCHlIVkq5yLvmiG6eVQQN5u75eNk3lURi4t8OhVE=; 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=C37/Io6kUa+PU/pw/ykp3dwtg2M2tjhQHDd//9ytAM5D/RanRPoGCDAgxRBywn8VN WuRVTJ4QBBuIBVdNAVhKl9Jv1D+BwZncN1HD/YsV0nriLaHsp28lQ/iajhZzyKVv0D j4wQKO7muAIf/7m2rYzsxHHnsQaad29rvs3f2dgo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 2AE6B3858408 for ; Thu, 11 Nov 2021 16:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2AE6B3858408 Received: by mail-pj1-x1032.google.com with SMTP id np3so4532248pjb.4 for ; Thu, 11 Nov 2021 08:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9KxeCHlIVkq5yLvmiG6eVQQN5u75eNk3lURi4t8OhVE=; b=033E+vWXPQ+YCcQu2iTEDvhDkYvoQX+HMvV0HoKI+jqC/6LvJVxNrJxIk5Cat7o61N mPx28tWtFulNczdIeWo7aGMprFiJIB9G3aTEuwFoB8fgNhomTuHqHcgjzyrm+7dXjH9G C+v3GRsDUhnk3eLJl6uMesry6cl9QWITsrLoVWL6M/LULbEtqpM0Pf7MYpVkCWID35Ys JERPHnQsfpknQILP6Wzp0Btsr6HmKjKdj5Tpj12jkr9mwkhS+1y51ZxDWgWgAZ+P+5f9 baDLnXmcI+Rhnv+mN6HXpmPOhOAQaynypp84nnT0Fwo6fXb3iEQVsTp+6KRG/s2bug13 t0AA== X-Gm-Message-State: AOAM533R93KhXPMYNjwqX+ZgPxyGD4t8WSzLlQxi3MVoegwoMYYhkMv8 3gmv/92V0NQFo6Q3pVc3tQU= X-Google-Smtp-Source: ABdhPJzPRX4WuUIaIxSbcr05RdaRAFaCxav9Co+WOgRyDg8IRlMWGP4plEzBydzrA38JsxsaiYD7Mg== X-Received: by 2002:a17:90a:e54c:: with SMTP id ei12mr27753782pjb.81.1636647870257; Thu, 11 Nov 2021 08:24:30 -0800 (PST) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id j8sm3872923pfu.27.2021.11.11.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 08:24:29 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id EAF5D1A0987; Thu, 11 Nov 2021 08:24:28 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v6 1/4] Add LLL_MUTEX_READ_LOCK [BZ #28537] Date: Thu, 11 Nov 2021 08:24:25 -0800 Message-Id: <20211111162428.2286605-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111162428.2286605-1-hjl.tools@gmail.com> References: <20211111162428.2286605-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , Andreas Schwab , "Paul A . Clarke" , Arjan van de Ven Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" CAS instruction is expensive. From the x86 CPU's point of view, getting a cache line for writing is more expensive than reading. See Appendix A.2 Spinlock in: https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/xeon-lock-scaling-analysis-paper.pdf The full compare and swap will grab the cache line exclusive and cause excessive cache line bouncing. Add LLL_MUTEX_READ_LOCK to do an atomic load and skip CAS in spinlock loop if compare may fail to reduce cache line bouncing on contended locks. --- nptl/pthread_mutex_lock.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 2bd41767e0..72058c719c 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -64,6 +64,11 @@ lll_mutex_lock_optimized (pthread_mutex_t *mutex) # define PTHREAD_MUTEX_VERSIONS 1 #endif +#ifndef LLL_MUTEX_READ_LOCK +# define LLL_MUTEX_READ_LOCK(mutex) \ + atomic_load_relaxed (&(mutex)->__data.__lock) +#endif + static int __pthread_mutex_lock_full (pthread_mutex_t *mutex) __attribute_noinline__; @@ -141,6 +146,8 @@ 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); From patchwork Thu Nov 11 16:24:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 47486 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 414363857C60 for ; Thu, 11 Nov 2021 16:26:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 414363857C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636648019; bh=NttSBrL5KtqYoHMkZABKAPQPOUIx3DhTDj//DhXSvsg=; 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=NGWlvP45q0iU/iqcnYgIhk9VCIImLieo8oJxDRcHbsxdhxVTp11G1ZQ9k7RoNkMM3 Rh7NRHOokm3gaCOlq19Bs6PCRA0a+nNZZPVqz3nVsA1cAf1gsce7OpxqY4eXGER/Fb /Z0LQWiku/aNCA8o1Zhb6cmasH2+4SIKw7F3cLEU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 7DEC8385840E for ; Thu, 11 Nov 2021 16:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DEC8385840E Received: by mail-pl1-x62d.google.com with SMTP id y8so698343plg.1 for ; Thu, 11 Nov 2021 08:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NttSBrL5KtqYoHMkZABKAPQPOUIx3DhTDj//DhXSvsg=; b=vm+0NVnGsC/pURrp33190NFGmQirvqBQPZm31OD5eDJLt7qst0SPsluZi3YlqqAUM1 FWBSK9cBFpbCmHU7Z4PKPaXPL1dl5ZMzjlGu7TtjRaAy+4MYqaCLZRey/yFeTJQVqtPO bO5vQPyCUQYl7fHdcS5BsEYHPV3hlqC2faGODMIWmnatcUu1mmqq7d6My6hbyAZNCr4X FFxOxPVFLnDtQJIGSwvdYDL9pDFDbijvfiUuXaMFASjzXzfp4yhO4Vcr3StaSpOuCGeO CI8WLanBIzEHl9pO30lpYq9Mm8tS++tlti+6TXqYda/iKsUz4LW+m99QFPWIoxouJL99 c0Kw== X-Gm-Message-State: AOAM530xPIfAGULoXHY+YvBCKCdxszK7DZnhX4UZRP2FB2eiiVZts6Fg eSS4lHRQS0i3utxpKmDkdhc= X-Google-Smtp-Source: ABdhPJwupVKO5Evo2+TyEdOGqu5F38Q7yEZNTKuQ57kOv4rYFb22fM9SHGNEAxpIYPLDAH/iZf6wEA== X-Received: by 2002:a17:90a:4812:: with SMTP id a18mr27041266pjh.223.1636647870596; Thu, 11 Nov 2021 08:24:30 -0800 (PST) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id z30sm3503780pfg.30.2021.11.11.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 08:24:29 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 020271A0C53; Thu, 11 Nov 2021 08:24:29 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v6 2/4] Avoid extra load with CAS in __pthread_mutex_lock_full [BZ #28537] Date: Thu, 11 Nov 2021 08:24:26 -0800 Message-Id: <20211111162428.2286605-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111162428.2286605-1-hjl.tools@gmail.com> References: <20211111162428.2286605-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , Andreas Schwab , "Paul A . Clarke" , Arjan van de Ven Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Replace boolean CAS with value CAS to avoid the extra load. Reviewed-by: Szabolcs Nagy --- nptl/pthread_mutex_lock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 72058c719c..762059b230 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -304,12 +304,12 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - if (atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock, - oldval | FUTEX_WAITERS, - oldval) - != 0) + int val; + if ((val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, + oldval)) != oldval) { - oldval = mutex->__data.__lock; + oldval = val; continue; } oldval |= FUTEX_WAITERS; From patchwork Thu Nov 11 16:24:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 47487 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 33FD13857C74 for ; Thu, 11 Nov 2021 16:27:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33FD13857C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636648061; bh=CHbi8Gkak0OQo+95r7WhGr9oXHBLK4yWRFpzZkOBt1o=; 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=sxPreStRJ09HgPzKC0aKLFmUBCyM1ZP5t+VL+82g6B5OwEU4Z39GPaub9GGWVEoEI hGgb/FNsIpHlH4xnuMAMU4i/TrRMmTsc4QA8YGMRpzYCSw4Nvu9WUqaRPPTItSSVT0 Hi7HaDBVg8o3uudtItamtA6seMOHi5xgibu4bJ3A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id C3B1F385841A for ; Thu, 11 Nov 2021 16:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3B1F385841A Received: by mail-pl1-x632.google.com with SMTP id n8so6174708plf.4 for ; Thu, 11 Nov 2021 08:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CHbi8Gkak0OQo+95r7WhGr9oXHBLK4yWRFpzZkOBt1o=; b=MhORD/VdHns7dLZV7KjaEn37Or1QJnORYIjuPISPQiQSspG1FRQQfU7u4RrDGaOOS6 EB4RACAHXNPHKdRMTFx7X2FAGxKfzhrd7U+1r+wkKwjoIDsaqox7Sk1slqjDXntJ20nt PtXQMWXpL6AhghmxAGILZLgEbvem1LCPyOXCSmYvBDTgx7TIwQppGn0w+PQTQlBOz+N1 Kr8jWK4hTb6Up1hcJzODCOXQbqdbOboftoKSb8udX27y0T/TU3pDJRU9Vo/2L7hK6lRl orDRUvinEgnUOYngCw9CNpitYj/pzHbKC+Fn3sxa+rBB4QrPiaOzAoHooHoDiAWZ7Cj6 ek6A== X-Gm-Message-State: AOAM532vLZPgpGrA6ug9uW0YAdpEaetFEqNs5Csuf6mDtmCEWq3eIUYq SFHm/hGBet9NWJu+G11ataM= X-Google-Smtp-Source: ABdhPJzO4bX0ClTSghe51GDQbgbBtoqllj6pGOc1TQLdVnG6hN1g5gdjKJwbLmpxK3pAWN5oml0R4Q== X-Received: by 2002:a17:902:d88b:b0:142:8acf:615b with SMTP id b11-20020a170902d88b00b001428acf615bmr148604plz.62.1636647870892; Thu, 11 Nov 2021 08:24:30 -0800 (PST) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id s25sm3358424pfm.138.2021.11.11.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 08:24:29 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 033201A0EC0; Thu, 11 Nov 2021 08:24:29 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v6 3/4] Reduce CAS in malloc spinlocks Date: Thu, 11 Nov 2021 08:24:27 -0800 Message-Id: <20211111162428.2286605-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111162428.2286605-1-hjl.tools@gmail.com> References: <20211111162428.2286605-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , Andreas Schwab , "Paul A . Clarke" , Arjan van de Ven Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Do an atomic load and check if compare may fail. Skip CAS and spin if compare may fail to reduce cache line bouncing on contended locks. --- malloc/arena.c | 5 +++++ malloc/malloc.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/malloc/arena.c b/malloc/arena.c index 78ef4cf18c..e7fbe7c183 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -899,6 +899,11 @@ arena_get2 (size_t size, mstate avoid_arena) enough address space to create that many arenas. */ if (__glibc_unlikely (n <= narenas_limit - 1)) { + if (atomic_load_relaxed (&narenas) != n) + { + atomic_spin_nop (); + goto repeat; + } if (catomic_compare_and_exchange_bool_acq (&narenas, n + 1, n)) goto repeat; a = _int_new_arena (size); diff --git a/malloc/malloc.c b/malloc/malloc.c index 095d97a3be..403ffb84ef 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3717,6 +3717,11 @@ _int_malloc (mstate av, size_t bytes) pp = REVEAL_PTR (victim->fd); \ if (__glibc_unlikely (pp != NULL && misaligned_chunk (pp))) \ malloc_printerr ("malloc(): unaligned fastbin chunk detected"); \ + if (atomic_load_relaxed (fb) != victim) \ + { \ + atomic_spin_nop (); \ + continue; \ + } \ } \ while ((pp = catomic_compare_and_exchange_val_acq (fb, pp, victim)) \ != victim); \ @@ -4435,6 +4440,11 @@ _int_free (mstate av, mchunkptr p, int have_lock) malloc_printerr ("double free or corruption (fasttop)"); old2 = old; p->fd = PROTECT_PTR (&p->fd, old); + if (atomic_load_relaxed (fb) != old2) + { + atomic_spin_nop (); + continue; + } } while ((old = catomic_compare_and_exchange_val_rel (fb, p, old2)) != old2); From patchwork Thu Nov 11 16:24:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 47485 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 ED8753857C56 for ; Thu, 11 Nov 2021 16:26:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED8753857C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636647977; bh=eM1JTI73m1S4orn7BISQT+W55J2z6/YtOfPGOAmCb0c=; 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=tqU/DUFbx6BVD/qR9TId7N2RJVo90dW1nmyEA1L/JFC8IOBKPwT4MZbZfiQRPMnHj PsED0B+zu2HyKhY+MwudziOcfc5LDauqOxcvHWEhKXV24+1WN4QzNqFlkz7guHW7jv kHiPrV8ce8NOnTG4YVXjzNDPHVgrJc3JuIVwQndE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 8DAF13858410 for ; Thu, 11 Nov 2021 16:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8DAF13858410 Received: by mail-pf1-x42c.google.com with SMTP id z6so6026689pfe.7 for ; Thu, 11 Nov 2021 08:24:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eM1JTI73m1S4orn7BISQT+W55J2z6/YtOfPGOAmCb0c=; b=a0DhYY3bzmn7By/FuPtybWVA9U+OR7DZt3zGApVq3fR8Az2ImJLQJCBqz636J9Px29 CCoHl4Pmhc8GpLzZ3odCqIelvh/izlNrf5k1Z/y9edFcirNGvxjat4D6t2RIXkV4QlwG Ua07lD/HneuhBEiALH2AZQMARlxq7HmMef/oZuIWapitkf6X7DYHkqQjOkMVLCI+LauE lHJ6WyjcM5X2kYhw4IYesCThDrgnKZTEgooHzmAPvAegaylTK/vSSlcd65YwEgtde5qr C5v94NYC4gU4vmrK6vBSiR9jxq1dIgZDt347i/jdoP2v7HNG9V8scvUxONtqmjAzEiq0 IXZQ== X-Gm-Message-State: AOAM531eR51MhrYjF6YEwj+h5pe6gYtSOjCP9oVSiADD0ftcwD7USg7H /DHOMd4nfX5SoGtrRHqf4e0= X-Google-Smtp-Source: ABdhPJz3Pqq7HC9ZLNJfqqhUoGUY0iopTQlj2m8S18iIwbR5QKpsho8q0ER0grWFOQ+MHp2stralmA== X-Received: by 2002:a65:5688:: with SMTP id v8mr5346704pgs.304.1636647870736; Thu, 11 Nov 2021 08:24:30 -0800 (PST) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id c3sm3675005pfm.177.2021.11.11.08.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 08:24:29 -0800 (PST) Received: from gnu-cfl-2.lan (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 101EE1A0EC3; Thu, 11 Nov 2021 08:24:29 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v6 4/4] Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537] Date: Thu, 11 Nov 2021 08:24:28 -0800 Message-Id: <20211111162428.2286605-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111162428.2286605-1-hjl.tools@gmail.com> References: <20211111162428.2286605-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , Andreas Schwab , "Paul A . Clarke" , Arjan van de Ven Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Replace boolean CAS with value CAS to avoid the extra load. Reviewed-by: Szabolcs Nagy --- nptl/pthread_mutex_timedlock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 57f3f28869..f763cfc7fa 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -233,12 +233,12 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - if (atomic_compare_and_exchange_bool_acq (&mutex->__data.__lock, - oldval | FUTEX_WAITERS, - oldval) - != 0) + int val; + if ((val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, + oldval)) != oldval) { - oldval = mutex->__data.__lock; + oldval = val; continue; } oldval |= FUTEX_WAITERS;