From: Manfred Spraul <manfred@colorfullife.com>
To: Boqun Feng <boqun.feng@gmail.com>, Davidlohr Bueso <dave@stgolabs.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Michael Ellerman <mpe@ellerman.id.au>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Susanne Spraul <1vier1@web.de>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: spin_lock implicit/explicit memory barrier
Date: Fri, 12 Aug 2016 20:43:55 +0200 [thread overview]
Message-ID: <bafec8b4-cc7e-7453-1b49-e7121bf76c41@colorfullife.com> (raw)
In-Reply-To: <20160812024712.GA31159@tardis.cn.ibm.com>
Hi Boqun,
On 08/12/2016 04:47 AM, Boqun Feng wrote:
>> We should not be doing an smp_mb() right after a spin_lock(), makes no sense. The
>> spinlock machinery should guarantee us the barriers in the unorthodox locking cases,
>> such as this.
>>
Do we really want to go there?
Trying to handle all unorthodox cases will end up as an endless list of
patches, and guaranteed to be stale architectures.
> Right.
>
> If you have:
>
> 6262db7c088b ("powerpc/spinlock: Fix spin_unlock_wait()")
>
> you don't need smp_mb() after spin_lock() on PPC.
>
> And, IIUC, if you have:
>
> 3a5facd09da8 ("arm64: spinlock: fix spin_unlock_wait for LSE atomics")
> d86b8da04dfa ("arm64: spinlock: serialise spin_unlock_wait against
> concurrent lockers")
>
> you don't need smp_mb() after spin_lock() on ARM64.
>
> And, IIUC, if you have:
>
> 2c6100227116 ("locking/qspinlock: Fix spin_unlock_wait() some more")
>
> you don't need smp_mb() after spin_lock() on x86 with qspinlock.
I would really prefer the other approach:
- spin_lock() is an acquire, that's it. No further guarantees, e.g.
ordering of writing the lock.
- spin_unlock() is a release, that's it.
- generic smp_mb__after_before_whatever(). And architectures can
override the helpers.
E.g. if qspinlocks on x86 can implement the smp_mb__after_spin_lock()
for free, then the helper can be a nop.
Right now, we start to hardcode something into the architectures - for
some callers.
Other callers use solutions such as smp_mb__after_unlock_lock(), i.e.
arch dependent workarounds in arch independent code.
And: We unnecessarily add overhead.
Both ipc/sem and netfilter do loops over many spinlocks:
> for (i = 0; i < CONNTRACK_LOCKS; i++) {
> spin_unlock_wait(&nf_conntrack_locks[i]);
> }
One memory barrier would be sufficient, but due to embedding we end up
with CONNTRACK_LOCKS barriers.
Should I create a patch?
(i.e. documentation and generic helpers)
--
Manfred
next prev parent reply other threads:[~2016-08-12 18:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 18:52 Manfred Spraul
2016-08-10 0:05 ` Benjamin Herrenschmidt
2016-08-10 18:21 ` Manfred Spraul
2016-08-10 19:17 ` Davidlohr Bueso
2016-08-10 21:00 ` Paul E. McKenney
2016-08-15 20:06 ` Manfred Spraul
2016-08-15 20:28 ` Paul E. McKenney
2016-08-12 2:47 ` Boqun Feng
2016-08-12 18:43 ` Manfred Spraul [this message]
2016-08-22 9:15 ` Boqun Feng
2016-08-10 20:52 ` Paul E. McKenney
2016-08-10 22:23 ` Davidlohr Bueso
2016-08-10 22:58 ` Paul E. McKenney
2016-08-10 23:29 ` Davidlohr Bueso
2016-08-11 8:11 ` Peter Zijlstra
2016-08-11 18:31 ` Davidlohr Bueso
2016-08-12 2:59 ` Boqun Feng
2016-08-19 14:01 ` Peter Zijlstra
2016-08-10 23:59 ` Benjamin Herrenschmidt
2016-08-10 18:33 ` Paul E. McKenney
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=bafec8b4-cc7e-7453-1b49-e7121bf76c41@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=1vier1@web.de \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=boqun.feng@gmail.com \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mpe@ellerman.id.au \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
/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
all inboxes | Powered by JetHome®