mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: "Leonidas ." <leonidas137@gmail.com>
Cc: Michael Schnell <mschnell@lumino.de>,
	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 15:57:49 +0100	[thread overview]
Message-ID: <4AE70A6D.8060700@s5r6.in-berlin.de> (raw)
In-Reply-To: <f22d86810910270323m6e004576ya4da96afc02e3d07@mail.gmail.com>

Leonidas . wrote:
> On Tue, Oct 27, 2009 at 3:21 AM, Michael Schnell <mschnell@lumino.de> wrote:
>> Leonidas . wrote:
>>>
>>> any_t *ptr = something;
>>>
>>> is always atomic even on SMPs without using locks, barriers then my
>>> doubt is cleared. Thanks.
>>
>> I assume that this only holds if the pointer (not the thing it points
>> to) is denoted as volatile.

  - Atomic access (either old or new value is visible to CPUs or
    devices, but never any intermediary, half-baked value),
  - memory barrier (enforced order of accesses),
  - volatile qualifier (disabled compiler optimization of accesses)

are three different concepts.

We rely on atomic pointer load and store all over the kernel, yet never
qualify them as "volatile".  (A look into the C language spec might
bring clarity here.  I don't have the spec at hand alas.)

> I dont think so,  volatile would only ensure no caching, so some cpus
> might see the cached pointer (this is where you would want to use
> barriers), but pointer assignment would still be atomic.

What "volatile" ensures or not ensures is not that well defined in the C
language specification as far as I recall prior discussion.  Its precise
effects are compiler dependent.  You are right in so far as volatile
(given or missing) does not change whether an access is guaranteed
atomic or not.  Since it affects compiler optimizations, I think it
could possibly affect atomicity of accesses which were never guaranteed
to be atomic.  But this should not be interesting to 99.99% of all
kernel coders because they better use guaranteed atomic accesses when
they really need them.  (E.g. <linux/atomic.h> or pointer load/ store.)
-- 
Stefan Richter
-=====-==--= =-=- ==-==
http://arcgraph.de/sr/

      parent reply	other threads:[~2009-10-27 14:57 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 .
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 [this message]

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=4AE70A6D.8060700@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=leonidas137@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mschnell@lumino.de \
    --cc=noah@noahdesu.com \
    /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®