From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by sourceware.org (Postfix) with ESMTPS id 3E700395253E for ; Thu, 6 Oct 2022 21:43:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E700395253E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=fastmail.fm Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fastmail.fm Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A56E25C015C; Thu, 6 Oct 2022 17:43:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 06 Oct 2022 17:43:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1665092632; x=1665179032; bh=zk Xhy7w8DzyufNSvHb0R1ldOXujQQim9IaSsNlLHRMc=; b=fAdgoIw5JL+M7M74Jw GjLmPD34UxMgNBhQXX4ud4g1qGFNuufKvroj1k31LyUhVfRQ1LVbfDXHsmrYNTAu ILaAllxf+7gbr83TNlbDtvkXEXJ4i+9QMjwV+YsiR4Z2m2rRcZRqWTByHz0DWofV 3WDtZKOIc7lIXd+dfkByD99/TD42JT2zA3vh4BUqqVnIEw+TzDcHRa3LpGia6m7x +9hAsi+Pf9s+z70szk4qDgXZQuZfH9m6xZSyH4hC0earu0UZeaugFTjt9hTcbbO7 Wlodvp7KZODIV2rweb1QSL5+4SeaSU8zmgtJLuMJt2hlUfTCi2b7sgLv3nhRtmJ7 bWQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1665092632; x=1665179032; bh=zkXhy7w8Dzyuf NSvHb0R1ldOXujQQim9IaSsNlLHRMc=; b=TVa2OSMR7Aal9NtL1ANIDHAj9JDiM rYMiKEMY8lOeUYjIOxXjJucHLS8Vq/KfZvbHPnfd+tlj2JUr2lNSL9pCSb0srAYX S6gpzFa4vllmvbc3zMUyNRXNmeYH43lkzziqfZ+ziMWFF+WIcJ3DOKE/CV8mM0gL GCGOMAJIG4DjjoGk0iOZa49kRsSDWdgPKzreSnbH3ScnYCtujvqx8YpqmDyOS4Kb SiwcnjvbnJckehFysMxfaiWIe8TMalfPnJ+tuja3YcomnNDUyYzOms2X7V5M+IjG jyNuLeySO7T3CK5cqnsTh3VB6xZu4iAKtXJcoLo2QBjd+aMFgNkYwoREQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeiiedgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmhgrlhht vghskhgrrhhuphhkvgesfhgrshhtmhgrihhlrdhfmhenucggtffrrghtthgvrhhnpeetge elgfeggeeuleeuffetveefgffgjedvgeehffdthfekteegtdeguefhffeftdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghlthgvshhkrg hruhhpkhgvsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ifa6c408f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 6 Oct 2022 17:43:52 -0400 (EDT) From: malteskarupke@fastmail.fm To: libc-alpha@sourceware.org Cc: Malte Skarupke Subject: [PATCH v3 5/6] nptl: Rename __wrefs to __crefs because its meaning has changed Date: Thu, 6 Oct 2022 17:43:28 -0400 Message-Id: <20221006214329.1084244-6-malteskarupke@fastmail.fm> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006214329.1084244-1-malteskarupke@fastmail.fm> References: <20221006214329.1084244-1-malteskarupke@fastmail.fm> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 List-Id: From: Malte Skarupke When I remove the increment/decrement of wrefs in pthread_cond_wait, it no longer really had the meaning of representing the number of waiters. It is still used as a reference count for threads that call pthread_cancel, so crefs it is. --- nptl/nptl-printers.py | 6 +++--- nptl/pthread_cond_broadcast.c | 2 +- nptl/pthread_cond_common.c | 4 ++-- nptl/pthread_cond_destroy.c | 10 +++++----- nptl/pthread_cond_init.c | 4 ++-- nptl/pthread_cond_signal.c | 2 +- nptl/pthread_cond_wait.c | 16 ++++++++-------- nptl/tst-cond22.c | 4 ++-- sysdeps/nptl/bits/thread-shared-types.h | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/nptl/nptl-printers.py b/nptl/nptl-printers.py index 3fb0335135..981eeedd76 100644 --- a/nptl/nptl-printers.py +++ b/nptl/nptl-printers.py @@ -312,7 +312,7 @@ class ConditionVariablePrinter(object): """ data = cond['__data'] - self.wrefs = data['__wrefs'] + self.crefs = data['__crefs'] self.grefs = data['__g_refs'] self.values = [] @@ -359,12 +359,12 @@ class ConditionVariablePrinter(object): def read_attributes(self): """Read the condvar's attributes.""" - if (self.wrefs & PTHREAD_COND_CLOCK_MONOTONIC_MASK) != 0: + if (self.crefs & PTHREAD_COND_CLOCK_MONOTONIC_MASK) != 0: self.values.append(('Clock ID', 'CLOCK_MONOTONIC')) else: self.values.append(('Clock ID', 'CLOCK_REALTIME')) - if (self.wrefs & PTHREAD_COND_SHARED_MASK) != 0: + if (self.crefs & PTHREAD_COND_SHARED_MASK) != 0: self.values.append(('Shared', 'Yes')) else: self.values.append(('Shared', 'No')) diff --git a/nptl/pthread_cond_broadcast.c b/nptl/pthread_cond_broadcast.c index e45f6271bf..18a3c3553c 100644 --- a/nptl/pthread_cond_broadcast.c +++ b/nptl/pthread_cond_broadcast.c @@ -44,7 +44,7 @@ ___pthread_cond_broadcast (pthread_cond_t *cond) unsigned int grefs1 = atomic_load_relaxed (cond->__data.__g_refs + 1); if ((grefs0 >> 1) == 0 && (grefs1 >> 1) == 0) return 0; - unsigned int flags = atomic_load_relaxed (&cond->__data.__wrefs); + unsigned int flags = atomic_load_relaxed (&cond->__data.__crefs); int private = __condvar_get_private (flags); __condvar_acquire_lock (cond, private); diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c index ce09d5d15a..220db22e9f 100644 --- a/nptl/pthread_cond_common.c +++ b/nptl/pthread_cond_common.c @@ -21,7 +21,7 @@ #include #include -/* We need 3 least-significant bits on __wrefs for something else. +/* We need 3 least-significant bits on __crefs for something else. This also matches __atomic_wide_counter requirements: The highest value we add is __PTHREAD_COND_MAX_GROUP_SIZE << 2 to __g1_start (the two extra bits are for the lock in the two LSBs of @@ -178,7 +178,7 @@ __condvar_set_orig_size (pthread_cond_t *cond, unsigned int size) atomic_store_relaxed (&cond->__data.__g1_orig_size, (size << 2) | 2); } -/* Returns FUTEX_SHARED or FUTEX_PRIVATE based on the provided __wrefs +/* Returns FUTEX_SHARED or FUTEX_PRIVATE based on the provided __crefs value. */ static int __attribute__ ((unused)) __condvar_get_private (int flags) diff --git a/nptl/pthread_cond_destroy.c b/nptl/pthread_cond_destroy.c index 053d0a2fbc..844647b3b7 100644 --- a/nptl/pthread_cond_destroy.c +++ b/nptl/pthread_cond_destroy.c @@ -42,7 +42,7 @@ __pthread_cond_destroy (pthread_cond_t *cond) { LIBC_PROBE (cond_destroy, 1, cond); - unsigned int flags = atomic_load_relaxed (&cond->__data.__wrefs); + unsigned int flags = atomic_load_relaxed (&cond->__data.__crefs); int private = __condvar_get_private (flags); for (unsigned g = 0; g < 2; ++g) { @@ -62,11 +62,11 @@ __pthread_cond_destroy (pthread_cond_t *cond) /* Same as above, except to synchronize with canceled threads. This wake flag never gets cleared, so it's enough to set it once. */ - unsigned int wrefs = atomic_fetch_or_acquire (&cond->__data.__wrefs, 4) | 4; - while (wrefs >> 3 != 0) + unsigned int crefs = atomic_fetch_or_acquire (&cond->__data.__crefs, 4) | 4; + while (crefs >> 3 != 0) { - futex_wait_simple (&cond->__data.__wrefs, wrefs, private); - wrefs = atomic_load_acquire (&cond->__data.__wrefs); + futex_wait_simple (&cond->__data.__crefs, crefs, private); + crefs = atomic_load_acquire (&cond->__data.__crefs); } /* The memory the condvar occupies can now be reused. */ return 0; diff --git a/nptl/pthread_cond_init.c b/nptl/pthread_cond_init.c index 739b3afb2d..d2e1988cf6 100644 --- a/nptl/pthread_cond_init.c +++ b/nptl/pthread_cond_init.c @@ -36,13 +36,13 @@ __pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *cond_attr) /* Iff not equal to ~0l, this is a PTHREAD_PROCESS_PRIVATE condvar. */ if (icond_attr != NULL && (icond_attr->value & 1) != 0) - cond->__data.__wrefs |= __PTHREAD_COND_SHARED_MASK; + cond->__data.__crefs |= __PTHREAD_COND_SHARED_MASK; int clockid = (icond_attr != NULL ? ((icond_attr->value >> 1) & ((1 << COND_CLOCK_BITS) - 1)) : CLOCK_REALTIME); /* If 0, CLOCK_REALTIME is used; CLOCK_MONOTONIC otherwise. */ if (clockid != CLOCK_REALTIME) - cond->__data.__wrefs |= __PTHREAD_COND_CLOCK_MONOTONIC_MASK; + cond->__data.__crefs |= __PTHREAD_COND_CLOCK_MONOTONIC_MASK; LIBC_PROBE (cond_init, 2, cond, cond_attr); diff --git a/nptl/pthread_cond_signal.c b/nptl/pthread_cond_signal.c index 2e8be2d3b5..d3735103fc 100644 --- a/nptl/pthread_cond_signal.c +++ b/nptl/pthread_cond_signal.c @@ -48,7 +48,7 @@ ___pthread_cond_signal (pthread_cond_t *cond) unsigned int grefs1 = atomic_load_relaxed (cond->__data.__g_refs + 1); if ((grefs0 >> 1) == 0 && (grefs1 >> 1) == 0) return 0; - unsigned int flags = atomic_load_relaxed (&cond->__data.__wrefs); + unsigned int flags = atomic_load_relaxed (&cond->__data.__crefs); int private = __condvar_get_private (flags); __condvar_acquire_lock (cond, private); diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c index b949805dae..515b4ba60e 100644 --- a/nptl/pthread_cond_wait.c +++ b/nptl/pthread_cond_wait.c @@ -156,10 +156,10 @@ __condvar_cleanup_waiting (void *arg) determine when all waiters have woken. Since we will do more work in this function, we are using an extra channel to communicate to pthread_cond_destroy that it is not allowed to finish yet: We - increment the refcount starting at the fourth bit on __wrefs. Relaxed + increment the refcount starting at the fourth bit on __crefs. Relaxed MO is enough. The synchronization happens because __condvar_dec_grefs uses release MO. */ - atomic_fetch_add_relaxed (&cond->__data.__wrefs, 8); + atomic_fetch_add_relaxed (&cond->__data.__crefs, 8); __condvar_dec_grefs (cond, g, cbuffer->private); __condvar_cancel_waiting (cond, cbuffer->wseq >> 1, g, cbuffer->private); @@ -175,8 +175,8 @@ __condvar_cleanup_waiting (void *arg) are the last waiter (prior value of __wrefs was 1 << 3), then wake any threads waiting in pthread_cond_destroy. Release MO to synchronize with these threads. Don't bother clearing the wake-up request flag. */ - if ((atomic_fetch_add_release (&cond->__data.__wrefs, -8) >> 2) == 3) - futex_wake (&cond->__data.__wrefs, INT_MAX, cbuffer->private); + if ((atomic_fetch_add_release (&cond->__data.__crefs, -8) >> 2) == 3) + futex_wake (&cond->__data.__crefs, INT_MAX, cbuffer->private); /* XXX If locking the mutex fails, should we just stop execution? This might be better than silently ignoring the error. */ @@ -280,13 +280,13 @@ __condvar_cleanup_waiting (void *arg) __g1_orig_size: Initial size of G1 * The two least-significant bits represent the condvar-internal lock. * Only accessed while having acquired the condvar-internal lock. - __wrefs: Flags and count of waiters who called pthread_cancel. + __crefs: Flags and count of waiters who called pthread_cancel. * Bit 2 is true if waiters should run futex_wake when they remove the last reference. pthread_cond_destroy uses this as futex word. * Bit 1 is the clock ID (0 == CLOCK_REALTIME, 1 == CLOCK_MONOTONIC). * Bit 0 is true iff this is a process-shared condvar. * Simple reference count used by __condvar_cleanup_waiting and pthread_cond_destroy. - (If the format of __wrefs is changed, update the pretty printers.) + (If the format of __crefs is changed, update the pretty printers.) For each of the two groups, we have: __g_refs: Futex waiter reference count. * LSB is true if waiters should run futex_wake when they remove the @@ -393,7 +393,7 @@ __pthread_cond_wait_common (pthread_cond_t *cond, pthread_mutex_t *mutex, make us see the closed flag on __g_signals that designates a concurrent attempt to reuse the group's slot. */ atomic_fetch_add_acquire (cond->__data.__g_refs + g, 2); - unsigned int flags = atomic_load_relaxed (&cond->__data.__wrefs); + unsigned int flags = atomic_load_relaxed (&cond->__data.__crefs); int private = __condvar_get_private (flags); /* Now that we are registered as a waiter, we can release the mutex. @@ -548,7 +548,7 @@ ___pthread_cond_timedwait64 (pthread_cond_t *cond, pthread_mutex_t *mutex, /* Relaxed MO is suffice because clock ID bit is only modified in condition creation. */ - unsigned int flags = atomic_load_relaxed (&cond->__data.__wrefs); + unsigned int flags = atomic_load_relaxed (&cond->__data.__crefs); clockid_t clockid = (flags & __PTHREAD_COND_CLOCK_MONOTONIC_MASK) ? CLOCK_MONOTONIC : CLOCK_REALTIME; return __pthread_cond_wait_common (cond, mutex, clockid, abstime); diff --git a/nptl/tst-cond22.c b/nptl/tst-cond22.c index 1336e9c79d..9f8cfea5c3 100644 --- a/nptl/tst-cond22.c +++ b/nptl/tst-cond22.c @@ -113,7 +113,7 @@ do_test (void) c.__data.__g1_start.__value32.__low, c.__data.__g_signals[0], c.__data.__g_refs[0], c.__data.__g_size[0], c.__data.__g_signals[1], c.__data.__g_refs[1], c.__data.__g_size[1], - c.__data.__g1_orig_size, c.__data.__wrefs); + c.__data.__g1_orig_size, c.__data.__crefs); if (pthread_create (&th, NULL, tf, (void *) 1l) != 0) { @@ -159,7 +159,7 @@ do_test (void) c.__data.__g1_start.__value32.__low, c.__data.__g_signals[0], c.__data.__g_refs[0], c.__data.__g_size[0], c.__data.__g_signals[1], c.__data.__g_refs[1], c.__data.__g_size[1], - c.__data.__g1_orig_size, c.__data.__wrefs); + c.__data.__g1_orig_size, c.__data.__crefs); return status; } diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h index 5653507e55..52decc49d6 100644 --- a/sysdeps/nptl/bits/thread-shared-types.h +++ b/sysdeps/nptl/bits/thread-shared-types.h @@ -98,7 +98,7 @@ struct __pthread_cond_s unsigned int __g_refs[2] __LOCK_ALIGNMENT; unsigned int __g_size[2]; unsigned int __g1_orig_size; - unsigned int __wrefs; + unsigned int __crefs; unsigned int __g_signals[2]; }; -- 2.25.1