From patchwork Fri Nov 12 20:22:56 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: 47575 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 2FC093857C52 for ; Fri, 12 Nov 2021 20:24:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FC093857C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636748697; bh=9DWrrZ/BrgeF7eO3jTChhL/S5ieA/l2+OV9MsYaOkSw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IRZt6pTNfySVyETneIo7hSH02HZ1uDerdik+LSqtGxdSsBY5muaEe8xzwmHyb7fY9 ryO+SSEQkxndOeymxEURJlFkUrhmy57HHJxxqP4Uns4oHuRtr47aUSDI7PtOD4nn9f dXYwEGRZQsacb9dbFoII0TOMDkoIq8tdN3xBh8Pk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id B989D3858420 for ; Fri, 12 Nov 2021 20:23:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B989D3858420 Received: by mail-pl1-x62b.google.com with SMTP id t21so9314419plr.6 for ; Fri, 12 Nov 2021 12:23:08 -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:mime-version :content-transfer-encoding; bh=9DWrrZ/BrgeF7eO3jTChhL/S5ieA/l2+OV9MsYaOkSw=; b=kaDTxAh8u19mpLmNgMZm2w5yO+KNvXRWt908DNTVXXhNHqMrgi6RjOUhGbSpyDP1mC sDnb9dl5ELz8FqMh7P1i0m7jj+fmxiGrkXEQuoW38KgQPuKMZgbPIJ01PDAxQCMkJTJT 8huR8Xp6Wi2A/MJi+pa4J9Lq/1/X21kedbORYt4CW6LAEk0vfU81XXhTj3itbXvIz6xb LpLV1LmcDNe8K9NSkg4qoewy+aZIIxgtHiHV2rvFdYsNopeP4wwc3+sY/gP+QVg5Ta9H fgqfkAqEf+FItBAPy3hZmH740PV+FJRlf2zI2lNGq6N7uSeuf+Rvnw7YQOn45+lGamSZ fgkA== X-Gm-Message-State: AOAM530NoFo9JsucMcMeDKlmWNvFVUVW0RiPmevI6oPCg1g5k80u92Z8 Sttl2kloiWPoe4ETIFZTbpuSNg2GZNA= X-Google-Smtp-Source: ABdhPJx1ghdy6ayBqPp8ncrHx9IUcajklg978i/eWfs1dbP4y/ZWyLbSiLUqzKBc7PYl2UPOkUI0Dg== X-Received: by 2002:a17:90a:ad47:: with SMTP id w7mr39660994pjv.16.1636748587879; Fri, 12 Nov 2021 12:23:07 -0800 (PST) Received: from gnu-cfl-2.localdomain ([2607:fb90:a63f:468b:b937:402b:0:c66]) by smtp.gmail.com with ESMTPSA id e14sm5432889pga.76.2021.11.12.12.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 12:23:07 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.34]) by gnu-cfl-2.localdomain (Postfix) with ESMTPS id 53D751A0A19; Fri, 12 Nov 2021 12:23:06 -0800 (PST) Received: from gnu-tgl-2.lan (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 3B916300324; Fri, 12 Nov 2021 12:22:56 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] Move assignment out of the CAS condition Date: Fri, 12 Nov 2021 12:22:56 -0800 Message-Id: <20211112202256.1591340-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3031.5 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Szabolcs Nagy , Andreas Schwab Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Update commit 49302b8fdf9103b6fc0a398678668a22fa19574c Author: H.J. Lu Date: Thu Nov 11 06:54:01 2021 -0800 Avoid extra load with CAS in __pthread_mutex_clocklock_common [BZ #28537] Replace boolean CAS with value CAS to avoid the extra load. and commit 0b82747dc48d5bf0871bdc6da8cb6eec1256355f Author: H.J. Lu Date: Thu Nov 11 06:31:51 2021 -0800 Avoid extra load with CAS in __pthread_mutex_lock_full [BZ #28537] Replace boolean CAS with value CAS to avoid the extra load. by moving assignment out of the CAS condition. --- nptl/pthread_mutex_lock.c | 7 +++---- nptl/pthread_mutex_timedlock.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 762059b230..47b88a6b5b 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -304,10 +304,9 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex) meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - int val; - if ((val = atomic_compare_and_exchange_val_acq - (&mutex->__data.__lock, oldval | FUTEX_WAITERS, - oldval)) != oldval) + int val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval); + if (val != oldval) { oldval = val; continue; diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index f763cfc7fa..791a2b54b1 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -233,10 +233,9 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, meantime. */ if ((oldval & FUTEX_WAITERS) == 0) { - int val; - if ((val = atomic_compare_and_exchange_val_acq - (&mutex->__data.__lock, oldval | FUTEX_WAITERS, - oldval)) != oldval) + int val = atomic_compare_and_exchange_val_acq + (&mutex->__data.__lock, oldval | FUTEX_WAITERS, oldval); + if (val != oldval) { oldval = val; continue;