From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: mutex: use generic atomic_dec-based implementation for ARMv6+
Date: Fri, 13 Jul 2012 14:43:52 +0100 [thread overview]
Message-ID: <20120713134352.GR18079@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1207130905390.14068@xanadu.home>
Hi Nico,
On Fri, Jul 13, 2012 at 02:21:41PM +0100, Nicolas Pitre wrote:
> On Fri, 13 Jul 2012, Will Deacon wrote:
>
> > The open-coded mutex implementation for ARMv6+ cores suffers from a
> > couple of problems:
> >
> > 1. (major) There aren't any barriers in sight, so in the
> > uncontended case we don't actually protect any accesses
> > performed in during the critical section.
> >
> > 2. (minor) If the strex indicates failure to complete the store,
> > we assume that the lock is contended and run away down the
> > failure (slow) path. This assumption isn't correct and the
> > core may fail the strex for reasons other than contention.
> >
> > This patch solves both of these problems by using the generic atomic_dec
> > based implementation for mutexes on ARMv6+. This also has the benefit of
> > removing a fair amount of inline assembly code.
>
> I don't agree with #2. Mutexes should be optimized for the uncontended
> case. And in such case, strex failures are unlikely.
Hmm, my only argument here is that the architecture doesn't actually define
all the causes of such a failure, so assuming that they are unlikely is
really down to the CPU implementation. However, whilst I haven't benchmarked
the strex failure rate, it wouldn't make sense to fail them gratuitously
although we may still end up on the slow path for the uncontended case.
> There was a time where the fast path was inlined in the code while any
> kind of contention processing was pushed out of line. Going to the slow
> path on strex failure just followed that model and provided correct
> mutex behavior while making the inlined sequence one instruction
> shorter. Therefore #2 is not a problem at all, not even a minor one.
Ok, I wasn't aware of the history, thanks. The trade-off between size of
inlined code and possibly taking the slow path unnecessarily seems like a
compromise, so point (2) doesn't stand there...
> These days the whole mutex code is always out of line so the saving of a
> single branch instruction in the whole kernel doesn't really matter
> anymore. So to say that I agree with the patch but not the second half
> of its justification.
... but like you say, the size of the out-of-line code doesn't matter as
much, so surely taking the slow patch for an uncontended mutex is a minor
issue here?
Anyway, that's an interesting discussion but I'll reword the commit message
so we can get this in while we ponder strex failures :)
How about:
ARM: mutex: use generic atomic_dec-based implementation for ARMv6+
The open-coded mutex implementation for ARMv6+ cores suffers from a
severe lack of barriers, so in the uncontended case we don't actually
protect any accesses performed during the critical section.
Furthermore, the code is largely a duplication of the ARMv6+ atomic_dec
code but optimised to remove a branch instruction, as the mutex fastpath
was previously inlined. Now that this is executed out-of-line, we can
reuse the atomic access code for the locking.
This patch solves uses the generic atomic_dec based implementation for
mutexes on ARMv6+, which introduces barriers to the lock/unlock
operations and also has the benefit of removing a fair amount of inline
assembly code.
Cheers,
Will
next prev parent reply other threads:[~2012-07-13 13:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-13 11:04 [PATCH] ARM: mutex: use generic atomic_dec-based implementation for ARMv6+ Will Deacon
2012-07-13 13:21 ` Nicolas Pitre
2012-07-13 13:43 ` Will Deacon [this message]
2012-07-13 17:00 ` Nicolas Pitre
2012-07-13 14:14 ` Arnd Bergmann
2012-07-13 14:30 ` Will Deacon
2012-07-13 15:13 ` Will Deacon
2012-07-13 17:07 ` Nicolas Pitre
-- strict thread matches above, loose matches on Subject: below --
2012-08-13 17:38 Will Deacon
2012-08-13 18:14 ` Nicolas Pitre
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=20120713134352.GR18079@mudshark.cambridge.arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.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;
as well as URLs for NNTP newsgroup(s).