public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix x86 atomic_fetch_xor_release.
@ 2016-10-18  3:19 Carlos O'Donell
  2016-10-18 11:02 ` Torvald Riegel
  0 siblings, 1 reply; 3+ messages in thread
From: Carlos O'Donell @ 2016-10-18  3:19 UTC (permalink / raw)
  To: GNU C Library, Torvald Riegel

Torvald,

No code uses atomic_fetch_xor_release except for the upcoming conditional
variable rewrite. Therefore there is no user visible bug here.

The use of atomic_compare_and_exchange_bool_rel is removed (since it doesn't
exist anymore), and is replaced by atomic_compare_exchange_weak_release.

We use weak_release because it provides better performance in the loop
(the weak semantic) and because the xor is release MO (the release semantic).

We don't reload expected in the loop because atomic_compare_and_exchange_weak_release
does this for us as part of the CAS failure.

It is otherwise a fairly plain conversion that fixes building the new condvar
for 32-bit x86.

I have pushed the new condvar into Fedora Rawhide for testing.

OK to checkin?

Cheers,
Carlos.

2016-10-17  Carlos O'Donell  <carlos@redhat.com>

	* include/atomic.h
	[USE_COMPILER_ATOMIC_BUILTINS && !atomic_fetch_xor_release]
	(atomic_fetch_xor_release): Use atomic_compare_exchange_weak_release.

Index: glibc-2.24-256-g5140d03/include/atomic.h
===================================================================
--- glibc-2.24-256-g5140d03.orig/include/atomic.h
+++ glibc-2.24-256-g5140d03/include/atomic.h
@@ -777,18 +777,22 @@ void __atomic_link_error (void);
 # endif

 # ifndef atomic_fetch_xor_release
+/* Failing the atomic_compare_exchange_weak_release reloads the value in
+   __atg104_expected, so we need only do the XOR again and retry.  */
 # define atomic_fetch_xor_release(mem, operand) \
-  ({ __typeof (*(mem)) __atg104_old;                                         \
-     __typeof (mem) __atg104_memp = (mem);                                   \
+  ({ __typeof (mem) __atg104_memp = (mem);                                   \
+     __typeof (*(mem)) __atg104_expected = (*__atg104_memp);                 \
+     __typeof (*(mem)) __atg104_desired;                                     \
      __typeof (*(mem)) __atg104_op = (operand);                                      \
                                                                              \
      do                                                                              \
-       __atg104_old = (*__atg104_memp);                                              \
-     while (__builtin_expect                                                 \
-           (atomic_compare_and_exchange_bool_rel (                           \
-               __atg104_memp, __atg104_old ^ __atg104_op, __atg104_old), 0));\
+       __atg104_desired = __atg104_expected ^ __atg104_op;                   \
+     while (__glibc_unlikely                                                 \
+           (atomic_compare_exchange_weak_release (                           \
+               __atg104_memp, &__atg104_expected, __atg104_desired)          \
+            == 0));                                                          \
                                                                              \
-     __atg104_old; })
+     __atg104_expected; })
 #endif

 #endif /* !USE_ATOMIC_COMPILER_BUILTINS  */
---

-- 
Cheers,
Carlos.

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

* Re: [PATCH] Fix x86 atomic_fetch_xor_release.
  2016-10-18  3:19 [PATCH] Fix x86 atomic_fetch_xor_release Carlos O'Donell
@ 2016-10-18 11:02 ` Torvald Riegel
  2016-10-26  4:04   ` Carlos O'Donell
  0 siblings, 1 reply; 3+ messages in thread
From: Torvald Riegel @ 2016-10-18 11:02 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: GNU C Library

On Mon, 2016-10-17 at 23:18 -0400, Carlos O'Donell wrote:
> Torvald,
> 
> No code uses atomic_fetch_xor_release except for the upcoming conditional
> variable rewrite. Therefore there is no user visible bug here.
> 
> The use of atomic_compare_and_exchange_bool_rel is removed (since it doesn't
> exist anymore), and is replaced by atomic_compare_exchange_weak_release.
> 
> We use weak_release because it provides better performance in the loop
> (the weak semantic) and because the xor is release MO (the release semantic).
> 
> We don't reload expected in the loop because atomic_compare_and_exchange_weak_release
> does this for us as part of the CAS failure.
> 
> It is otherwise a fairly plain conversion that fixes building the new condvar
> for 32-bit x86.
> 
> I have pushed the new condvar into Fedora Rawhide for testing.
> 
> OK to checkin?

OK.

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

* Re: [PATCH] Fix x86 atomic_fetch_xor_release.
  2016-10-18 11:02 ` Torvald Riegel
@ 2016-10-26  4:04   ` Carlos O'Donell
  0 siblings, 0 replies; 3+ messages in thread
From: Carlos O'Donell @ 2016-10-26  4:04 UTC (permalink / raw)
  To: Torvald Riegel; +Cc: GNU C Library

On 10/18/2016 07:02 AM, Torvald Riegel wrote:
> On Mon, 2016-10-17 at 23:18 -0400, Carlos O'Donell wrote:
>> Torvald,
>>
>> No code uses atomic_fetch_xor_release except for the upcoming conditional
>> variable rewrite. Therefore there is no user visible bug here.
>>
>> The use of atomic_compare_and_exchange_bool_rel is removed (since it doesn't
>> exist anymore), and is replaced by atomic_compare_exchange_weak_release.
>>
>> We use weak_release because it provides better performance in the loop
>> (the weak semantic) and because the xor is release MO (the release semantic).
>>
>> We don't reload expected in the loop because atomic_compare_and_exchange_weak_release
>> does this for us as part of the CAS failure.
>>
>> It is otherwise a fairly plain conversion that fixes building the new condvar
>> for 32-bit x86.
>>
>> I have pushed the new condvar into Fedora Rawhide for testing.
>>
>> OK to checkin?
> 
> OK.
> 

Checked in. Verified it fixes everything with the other dependent
patches applied.

-- 
Cheers,
Carlos.

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

end of thread, other threads:[~2016-10-26  4:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-18  3:19 [PATCH] Fix x86 atomic_fetch_xor_release Carlos O'Donell
2016-10-18 11:02 ` Torvald Riegel
2016-10-26  4:04   ` Carlos O'Donell

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).