lkml.org 
[lkml]   [2020]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] tools/memory-model: document the "one-time init" pattern
On Fri, Jul 17, 2020 at 01:51:38PM -0400, Alan Stern wrote:
> On Fri, Jul 17, 2020 at 06:47:50PM +0100, Matthew Wilcox wrote:
> > On Thu, Jul 16, 2020 at 09:44:27PM -0700, Eric Biggers wrote:
> ...
> > > + /* on success, pairs with smp_load_acquire() above and below */
> > > + if (cmpxchg_release(&foo, NULL, p) != NULL) {
> >
> > Why do we have cmpxchg_release() anyway? Under what circumstances is
> > cmpxchg() useful _without_ having release semantics?
>
> To answer just the last question: cmpxchg() is useful for lock
> acquisition, in which case it needs to have acquire semantics rather
> than release semantics.
>

To clarify, there are 4 versions of cmpxchg:

cmpxchg(): does ACQUIRE and RELEASE (on success)
cmpxchg_acquire(): does ACQUIRE only (on success)
cmpxchg_release(): does RELEASE only (on success)
cmpxchg_relaxed(): no barriers

The problem here is that here we need RELEASE on success and ACQUIRE on failure.
But no version guarantees any barrier on failure.

So as far as I can tell, the best we can do is use cmpxchg_release() (or
cmpxchg() which would be stronger but unnecessary), followed by a separate
ACQUIRE on failure.

- Eric

\
 
 \ /
  Last update: 2020-07-18 03:03    [W:0.149 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site