From: jamie@shareable.org (Jamie Lokier)
To: linux-arm-kernel@lists.infradead.org
Subject: LDREX/STREX and pre-emption on SMP hardware
Date: Tue, 15 Sep 2009 00:16:18 +0100 [thread overview]
Message-ID: <20090914231618.GA28427@shareable.org> (raw)
In-Reply-To: <1252930881.16853.99.camel@pc1117.cambridge.arm.com>
Catalin Marinas wrote:
> #define atomic_read(v) ((v)->counter)
> +#define atomic_set(v,i) (((v)->counter) = (i))
>
> #if __LINUX_ARM_ARCH__ >= 6
>
> /*
> * ARMv6 UP and SMP safe atomic ops. We use load exclusive and
> * store exclusive to ensure that these are atomic. We may loop
> - * to ensure that the update happens. Writing to 'v->counter'
> - * without using the following operations WILL break the atomic
> - * nature of these ops.
> + * to ensure that the update happens.
> */
> -static inline void atomic_set(atomic_t *v, int i)
> -{
> - unsigned long tmp;
> -
> - __asm__ __volatile__("@ atomic_set\n"
> -"1: ldrex %0, [%1]\n"
> -" strex %0, %2, [%1]\n"
> -" teq %0, #0\n"
> -" bne 1b"
> - : "=&r" (tmp)
> - : "r" (&v->counter), "r" (i)
> - : "cc");
> -}
I was going to say this won't work, because I'd read this in
<asm/atomic.h>:
/* Atomic operations are already serializing on ARM */
#define smp_mb__before_atomic_dec() barrier()
[etc]
and imagined that atomic_set() needed to provide the same.
But then but then I spotted Documentation/atomic_ops.txt:
*** WARNING: atomic_read() and atomic_set() DO NOT IMPLY BARRIERS! ***
So that's alright then.
Besides, it turns out the comment in <asm/atomic.h> was wrong, and was
removed recently, with explicit barrier instructions being added where
expected.
Regarding the patch, a command saying _why_ it's ok for atomic_set()
to be a simple assignment would be good:
/*
* On ARM, ordinary assignment (str instruction) doesn't clear the
* _local_ strex/ldrex monitor on some implementations. The
* reason we can use it for atomic_set() is the clrex or dummy
* strex done on every exception return and context switch.
*/
-- Jamie
next prev parent reply other threads:[~2009-09-14 23:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-21 15:07 LDREX/STREX and pre-emption on SMP hardware Richard Crewe
2009-08-21 15:42 ` Catalin Marinas
2009-08-21 15:50 ` Jamie Lokier
2009-08-21 15:58 ` Catalin Marinas
2009-08-21 21:29 ` David Xiao
2009-08-24 15:44 ` Catalin Marinas
2009-08-24 17:14 ` David Xiao
2009-08-24 17:41 ` Catalin Marinas
2009-08-24 18:59 ` David Xiao
2009-09-14 1:43 ` Jamie Lokier
2009-09-14 8:53 ` Catalin Marinas
2009-09-14 10:00 ` Russell King - ARM Linux
2009-09-14 10:06 ` Catalin Marinas
2009-09-14 11:47 ` Catalin Marinas
2009-09-14 12:21 ` Catalin Marinas
2009-09-14 12:43 ` Bill Gatliff
2009-09-14 12:57 ` Catalin Marinas
2009-09-14 19:30 ` Bill Gatliff
2009-09-14 14:09 ` Russell King - ARM Linux
2009-09-14 14:21 ` Russell King - ARM Linux
2009-09-14 14:26 ` Catalin Marinas
2009-09-14 15:35 ` Catalin Marinas
2009-09-14 23:16 ` Jamie Lokier [this message]
2009-09-14 14:23 ` Russell King - ARM Linux
2009-09-14 14:29 ` Catalin Marinas
2009-09-18 20:20 ` Russell King - ARM Linux
2009-09-18 22:51 ` Catalin Marinas
2009-08-24 21:12 ` Jamie Lokier
2009-08-25 8:33 ` Catalin Marinas
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=20090914231618.GA28427@shareable.org \
--to=jamie@shareable.org \
--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).