public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Move assignment out of the CAS condition
@ 2021-11-12 20:22 H.J. Lu
  2021-11-15 13:42 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2021-11-12 20:22 UTC (permalink / raw)
  To: libc-alpha; +Cc: Szabolcs Nagy, Andreas Schwab

Update

commit 49302b8fdf9103b6fc0a398678668a22fa19574c
Author: H.J. Lu <hjl.tools@gmail.com>
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 <hjl.tools@gmail.com>
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;
-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Move assignment out of the CAS condition
  2021-11-12 20:22 [PATCH] Move assignment out of the CAS condition H.J. Lu
@ 2021-11-15 13:42 ` Andreas Schwab
  2022-09-11 20:21   ` Sunil Pandey
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2021-11-15 13:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: libc-alpha, Szabolcs Nagy

Ok.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Move assignment out of the CAS condition
  2021-11-15 13:42 ` Andreas Schwab
@ 2022-09-11 20:21   ` Sunil Pandey
  2022-09-29  0:09     ` Noah Goldstein
  0 siblings, 1 reply; 4+ messages in thread
From: Sunil Pandey @ 2022-09-11 20:21 UTC (permalink / raw)
  To: Andreas Schwab, Libc-stable Mailing List, Florian Weimer
  Cc: H.J. Lu, Szabolcs Nagy, GNU C Library

On Mon, Nov 15, 2021 at 5:42 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> Ok.
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."

I would like to backport this patch to release branch 2.33 and 2.34.

Any comments/suggestions or objections on this.

commit 120ac6d238825452e8024e2f627da33b2508dfd3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Nov 12 11:47:42 2021 -0800

    Move assignment out of the CAS condition

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Move assignment out of the CAS condition
  2022-09-11 20:21   ` Sunil Pandey
@ 2022-09-29  0:09     ` Noah Goldstein
  0 siblings, 0 replies; 4+ messages in thread
From: Noah Goldstein @ 2022-09-29  0:09 UTC (permalink / raw)
  To: Sunil Pandey
  Cc: Andreas Schwab, Libc-stable Mailing List, Florian Weimer,
	Szabolcs Nagy, GNU C Library

On Sun, Sep 11, 2022 at 4:22 PM Sunil Pandey via Libc-stable
<libc-stable@sourceware.org> wrote:
>
> On Mon, Nov 15, 2021 at 5:42 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >
> > Ok.
> >
> > Andreas.
> >
> > --
> > Andreas Schwab, schwab@linux-m68k.org
> > GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> > "And now for something completely different."
>
> I would like to backport this patch to release branch 2.33 and 2.34.
>
> Any comments/suggestions or objections on this.
>
> commit 120ac6d238825452e8024e2f627da33b2508dfd3
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Fri Nov 12 11:47:42 2021 -0800
>
>     Move assignment out of the CAS condition

Fine by me.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-29  0:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 20:22 [PATCH] Move assignment out of the CAS condition H.J. Lu
2021-11-15 13:42 ` Andreas Schwab
2022-09-11 20:21   ` Sunil Pandey
2022-09-29  0:09     ` Noah Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).