public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Chris Friesen" <cfriesen@nortel.com>
To: "Leonidas ." <leonidas137@gmail.com>
Cc: Noah Watkins <noah@noahdesu.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Difference between atomic operations and memory barriers
Date: Mon, 26 Oct 2009 12:54:06 -0600	[thread overview]
Message-ID: <4AE5F04E.3050908@nortel.com> (raw)
In-Reply-To: <f22d86810910261122j6c9e57e8pd4a257090f65c727@mail.gmail.com>

On 10/26/2009 12:22 PM, 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.
>>>
>> There is a bit of info in:
>>    Documentation/atomic_ops.txt

> Thanks for the pointer, there are no atomic operations for pointers, right?
> I guess barrier is what we need in that case.

You need barriers for the atomics too, at least in some cases.  From
that document:

*** WARNING: atomic_read() and atomic_set() DO NOT IMPLY BARRIERS! ***


For simple assignments, I'm fairly sure linux assumes that writes to
individual variables are atomic.  ie, if you're assigning to an int you
won't get half of the assignment completed while the other half isn't.

What the atomic ops buy you is the ability to do increment-and-test,
compare-and-exchange, etc. in an atomic fashion.

Barriers are needed to make sure that operations are visible on other
cpus in the correct order, and to ensure that the compiler doesn't
reorder the operations.

If you use the normal locking mechanisms (mutexes, spinlocks, etc.) the
barriers are implicit in the lock.

Chris

  reply	other threads:[~2009-10-26 18:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-26 17:19 Difference between atomic operations and memory barriers Leonidas .
     [not found] ` <7ADB5FD7-9C97-4987-BC20-997258B25FD2@noahdesu.com>
2009-10-26 18:22   ` Leonidas .
2009-10-26 18:54     ` Chris Friesen [this message]
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

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=4AE5F04E.3050908@nortel.com \
    --to=cfriesen@nortel.com \
    --cc=leonidas137@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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