From: "Leonidas ." <leonidas137@gmail.com>
To: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: Noah Watkins <noah@noahdesu.com>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Difference between atomic operations and memory barriers
Date: Tue, 27 Oct 2009 00:35:18 +0530 [thread overview]
Message-ID: <f22d86810910261205r232db5d4re97a54827c7adab3@mail.gmail.com> (raw)
In-Reply-To: <4AE5F1D2.9030908@s5r6.in-berlin.de>
On Tue, Oct 27, 2009 at 12:30 AM, Stefan Richter
<stefanr@s5r6.in-berlin.de> wrote:
> Leonidas . wrote:
>> On Mon, Oct 26, 2009 at 11:49 PM, Noah Watkins <noah@noahdesu.com> wrote:
>>>> Trying to understand difference between atomic ops and memory barriers.
>
> Atomic accesses and barriers are different concepts.
>
> The former means that there won't be intermediary values visible (to
> another CPU or to a DMA capable device) at any time; there will only be
> either the old value or the new value, but nothing half-done.
>
> The latter means that an order between two (or more) separate accesses
> is enforced.
>
> You cannot use barriers to make intrinsically non-atomic accesses look
> atomically; you need a lock for such a purpose. (Or RCU.)
>
>>>> I was thinking all atomic operations must be using barrier internally, but I read
>>>> somewhere that only some of them use barriers. Sorry for being vague here.
>>>>
>>>> Operations before call to smp_mb() will not be re-ordered and all cpus will see
>>>> consistent value after the variable is updated.
>>>>
>>>> E.g.
>>>> void * ptr = (void *) str;
>>>> smb_mb();
>>>>
>>>> Will this not atomically update ptr? Ptr will be seen by all cpu's in same state
>>>> after it has been assigned str, right?
>>>
>>> There is a bit of info in:
>>> Documentation/atomic_ops.txt
>>>
>>> -noah
>>>
>>>
>>
>>
>> Thanks for the pointer, there are no atomic operations for pointers, right?
>> I guess barrier is what we need in that case.
>
> There are more atomic accesses than those which deal with atomic_t. For
> example,
> any_t *ptr = something;
> is definitely atomic, and we rely on this atomicity in the kernel at
> many places.
>
> I guess these things can be found somewhere in the C language specification.
> --
> Stefan Richter
> -=====-==--= =-=- ==-=-
> http://arcgraph.de/sr/
>
If your answer matches my inference that,
any_t *ptr = something;
is always atomic even on SMPs without using locks, barriers then my
doubt is cleared. Thanks.
-Leo.
next prev parent reply other threads:[~2009-10-26 19:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 17:19 Leonidas .
[not found] ` <7ADB5FD7-9C97-4987-BC20-997258B25FD2@noahdesu.com>
2009-10-26 18:22 ` Leonidas .
2009-10-26 18:54 ` Chris Friesen
2009-10-26 19:00 ` Leonidas .
2009-10-26 19:07 ` Noah Watkins
2009-10-26 19:34 ` Stefan Richter
2009-10-26 19:42 ` Noah Watkins
2009-10-27 11:51 ` Valdis.Kletnieks
2009-10-28 10:00 ` Boaz Harrosh
2009-10-28 13:26 ` Valdis.Kletnieks
2009-10-26 19:00 ` Stefan Richter
2009-10-26 19:05 ` Leonidas . [this message]
2009-10-27 10:21 ` Michael Schnell
2009-10-27 10:23 ` Leonidas .
2009-10-27 11:01 ` Michael Schnell
2009-10-27 14:57 ` Stefan Richter
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=f22d86810910261205r232db5d4re97a54827c7adab3@mail.gmail.com \
--to=leonidas137@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=noah@noahdesu.com \
--cc=stefanr@s5r6.in-berlin.de \
/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®