From: Will Deacon <will.deacon@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "waiman.long@hp.com" <waiman.long@hp.com>,
"ksummit-discuss@lists.linuxfoundation.org"
<ksummit-discuss@lists.linuxfoundation.org>
Subject: Re: [Ksummit-discuss] [TECH TOPIC] asm-generic implementations of low-level synchronisation constructs
Date: Wed, 7 May 2014 22:20:01 +0100 [thread overview]
Message-ID: <20140507212001.GA5311@arm.com> (raw)
In-Reply-To: <20140507191208.GZ30445@twins.programming.kicks-ass.net>
Hi Peter,
On Wed, May 07, 2014 at 08:12:08PM +0100, Peter Zijlstra wrote:
> On Wed, May 07, 2014 at 07:29:16PM +0100, Will Deacon wrote:
> > better_spin_lock(atomic_t *lock)
> > {
> > /*
> > * Atomic add to lock with acquire semantics, returning original
> > * value.
> > */
> > int old = atomic_xchg_add(ACQUIRE, lock, 1 << TICKET_SHIFT);
> > if ((old << TICKET_SHIFT) == (old & (TICKET_MASK << TICKET_SHIFT)))
> > return; /* Got the lock */
> >
> > while (smp_load_acquire((u16 *)lock) != (old >> TICKET_SHIFT))
> > cpu_relax();
> > }
>
> So xchg_add and atomic_add_return() are pretty much an identity map
> because the add operation is reversible. The other popular name for this
> operation is fetch_add() fwiw.
Yup, and we could implement atomic_xchg_add (or atomic_fetch_add :) in
asm-generic using atomic_add_return followed by a subtraction. However,
architectures might be able to avoid the sub (especially on LL/SC
implementations like ARM).
> In any case, something that's been brewing in the back of my mind is an
> ATOMIC_OP() and ATOMIC_RET_OP() macro construct that takes a lambda
> function (expr-stmt is I think the closes we get in C) and either
> generates the appropriate ll/sc loop or a cmpxchg loop, depending on
> arch.
I've been thinking along the same lines but decided it was a bit too
abstract to propose here. I'd certainly be interested in talking about it
though. Another cool thing would be to allow for arbitrary compositions of
different atomic operations, then apply barrier semantics to the whole lot.
Not sure how much mileage there is in that though, especially given the
typical architectural restrictions on what you can in a LL/SC loop (and
if they get too big, you shoot yourself in the foot).
> Its fairly sad that many of the generic atomic operations we do with
> cmpxchg loops where ll/sc archs can do better using their ll/sc
> primitive and I just feel there must be a semi-sane way to express all
> that, despite C :-)
Hehe, yeah. It's like trying to implement a functional programming language
in the preprocessor...
> That also reminds me, I should send round 2 of the arch atomic cleanups
> (I've got the patches), and write changelogs for round 3, and start on
> the patches for round 4 :-)
Excellent! Please stick me on CC when you send them out.
Will
next prev parent reply other threads:[~2014-05-07 21:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 18:29 Will Deacon
2014-05-07 19:12 ` Peter Zijlstra
2014-05-07 21:20 ` Will Deacon [this message]
2014-05-08 9:13 ` Peter Zijlstra
2014-05-08 14:27 ` Peter Zijlstra
2014-05-08 14:43 ` David Woodhouse
2014-05-08 15:13 ` Will Deacon
2014-05-08 16:39 ` Paul E. McKenney
2014-05-07 21:17 ` Waiman Long
2014-05-07 21:26 ` Peter Zijlstra
2014-05-07 22:29 ` Waiman Long
2014-05-08 14:16 ` Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140507212001.GA5311@arm.com \
--to=will.deacon@arm.com \
--cc=ksummit-discuss@lists.linuxfoundation.org \
--cc=peterz@infradead.org \
--cc=waiman.long@hp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox