From patchwork Sat Oct 15 19:53:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: develop--- via Libc-alpha X-Patchwork-Id: 58906 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 70D7D3858429 for ; Sat, 15 Oct 2022 19:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70D7D3858429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665863639; bh=X8EKNAi5CiNKdj8wr5nG+LHi9zkHN1iYjDhecs+lKFk=; 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=CpZvHSnlcovHzRZfS1M2rkxaVU2uUl1dG98WSHG8OTQArJDJEp8GvN9inx5+UgSPN KKmoTjbvu7g+3GtvEWXGYdmiSI5RCU0TJdCUhau+ZAp/EgOs2YPC19DoAiLfMtf/II tFT5jAt7YuxtAq15l5NaGtmSrzLjniEXF5N2HRKg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by sourceware.org (Postfix) with ESMTPS id 6812D3858D38 for ; Sat, 15 Oct 2022 19:53:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6812D3858D38 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DDA545C00AF; Sat, 15 Oct 2022 15:53:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 15 Oct 2022 15:53:34 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeekgedgudeggecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpehmrghl thgvshhkrghruhhpkhgvsehfrghsthhmrghilhdrfhhmnecuggftrfgrthhtvghrnhepte eglefggeegueelueffteevfefggfejvdeghefftdfhkeetgedtgeeuhffffedtnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrlhhtvghskh grrhhuphhkvgesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: ifa6c408f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 15 Oct 2022 15:53:34 -0400 (EDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/2] nptl: Simplifying condvar-internal mutex Date: Sat, 15 Oct 2022 15:53:05 -0400 Message-Id: <20221015195305.1322087-2-malteskarupke@fastmail.fm> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221015195305.1322087-1-malteskarupke@fastmail.fm> References: <20221015195305.1322087-1-malteskarupke@fastmail.fm> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: malteskarupke--- via Libc-alpha From: develop--- via Libc-alpha Reply-To: malteskarupke@fastmail.fm Cc: Malte Skarupke Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" From: Malte Skarupke The condvar-internal mutex no longer shares its 32 bit futex with other information. There is no reason to keep the complexity, so simplify. --- nptl/pthread_cond_common.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index b9043a218b..efc7999cfe 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -32,11 +32,11 @@ static void __attribute__ ((unused)) __condvar_acquire_lock (pthread_cond_t *cond, int private) { - unsigned int s = atomic_load_relaxed (&cond->__data.__lock); - while ((s & 3) == 0) + unsigned int *lock = &cond->__data.__lock; + unsigned int s = atomic_load_relaxed (lock); + while (s == 0) { - if (atomic_compare_exchange_weak_acquire (&cond->__data.__lock, - &s, s | 1)) + if (atomic_compare_exchange_weak_acquire (lock, &s, 1)) return; /* TODO Spinning and back-off. */ } @@ -45,21 +45,19 @@ __condvar_acquire_lock (pthread_cond_t *cond, int private) from not acquired. */ while (1) { - while ((s & 3) != 2) + while (s != 2) { - if (atomic_compare_exchange_weak_acquire - (&cond->__data.__lock, &s, (s & ~(unsigned int) 3) | 2)) + if (atomic_compare_exchange_weak_acquire (lock, &s, 2)) { - if ((s & 3) == 0) + if (s == 0) return; break; } /* TODO Back off. */ } - futex_wait_simple (&cond->__data.__lock, - (s & ~(unsigned int) 3) | 2, private); + futex_wait_simple (lock, 2, private); /* Reload so we see a recent value. */ - s = atomic_load_relaxed (&cond->__data.__lock); + s = atomic_load_relaxed (lock); } } @@ -67,9 +65,7 @@ __condvar_acquire_lock (pthread_cond_t *cond, int private) static void __attribute__ ((unused)) __condvar_release_lock (pthread_cond_t *cond, int private) { - if ((atomic_fetch_and_release (&cond->__data.__lock, - ~(unsigned int) 3) & 3) - == 2) + if (atomic_exchange_release (&cond->__data.__lock, 0) == 2) futex_wake (&cond->__data.__lock, 1, private); }