All of lore.kernel.org
 help / color / mirror / Atom feed
From: arnd@arndb.de (Arnd Bergmann)
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:14:36 +0000	[thread overview]
Message-ID: <201207131414.37078.arnd@arndb.de> (raw)
In-Reply-To: <1342177463-21238-1-git-send-email-will.deacon@arm.com>

On Friday 13 July 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.
> 
> Cc: Nicolas Pitre <nico@fluxnic.net>
> Reported-by: Shan Kang <kangshan0910@gmail.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

Nice!

Acked-by: Arnd Bergmann <arnd@arndb.de>

One question though: can you explain why the xchg implementation is better
on pre-v6, while the dec implementation is better on v6+? It would probably
be helpful to put that in the comment at

 /* On pre-ARMv6 hardware the swp based implementation is the most efficient. */
 # include <asm-generic/mutex-xchg.h>
 #else
 /* ARMv6+ can implement efficient atomic decrement using exclusive accessors. */
 # include <asm-generic/mutex-dec.h>

Intuitively, I'd guess that both implementations are equally efficient
on ARMv6 because they use the same ldrex/strex loop.

	Arnd

  parent reply	other threads:[~2012-07-13 14:14 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
2012-07-13 17:00     ` Nicolas Pitre
2012-07-13 14:14 ` Arnd Bergmann [this message]
2012-07-13 14:30   ` Will Deacon
2012-07-13 15:13     ` Will Deacon
2012-07-13 17:07     ` Nicolas Pitre
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=201207131414.37078.arnd@arndb.de \
    --to=arnd@arndb.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.