public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: linux-ia64@vger.kernel.org, Jesse Barnes <jesse.barnes@intel.com>,
	linuxppc-dev@ozlabs.org
Subject: Re: wmb vs mmiowb
Date: Wed, 22 Aug 2007 18:07:32 +0000	[thread overview]
Message-ID: <alpine.LFD.0.999.0708221049560.30176@woody.linux-foundation.org> (raw)
In-Reply-To: <20070822045714.GD26374@wotan.suse.de>



On Wed, 22 Aug 2007, Nick Piggin wrote:
> 
> It took me more than a glance to see what the difference is supposed to be
> between wmb() and mmiowb(). I think especially because mmiowb isn't really
> like a write barrier.

Well, it is, but it isn't. Not on its own - but together with a "normal" 
barrier it is.

> wmb is supposed to order all writes coming out of a single CPU, so that's
> pretty simple.

No. wmb orders all *normal* writes coming out of a single CPU.

It may not do anything at all for "uncached" IO writes that aren't part of 
the cache coherency, and that are handled using totally different queues 
(both inside and outside of the CPU)!

Now, on x86, the CPU actually tends to order IO writes *more* than it 
orders any other writes (they are mostly entirely synchronous, unless the 
area has been marked as write merging), but at least on PPC, it's the 
other way around: without the cache as a serialization entry, you end up 
having a totally separate queueu to serialize, and a regular-memory write 
barrier does nothing at all to the IO queue.

So think of the IO write queue as something totally asynchronous that has 
zero connection to the normal write ordering - and then think of mmiowb() 
as a way to *insert* a synchronization point.

In particular, the normal synchronization primitives (spinlocks, mutexes 
etc) are guaranteed to synchronize only normal memory accesses. So if you 
do MMIO inside a spinlock, since the MMIO writes are totally asyncronous 
wrt the normal memory accesses, the MMIO write can escape outside the 
spinlock unless you have somethign that serializes the MMIO accesses with 
the normal memory accesses.

So normally you'd see "mmiowb()" always *paired* with a normal memory 
barrier! The "mmiowb()" ends up synchronizing the MMIO writes with the 
normal memory accesses, and then the normal memory barrier acts as a 
barrier for subsequent writes.

Of course, the normal memory barrier would usually be a "spin_unlock()" or 
something like that, not a "wmb()". In fact, I don't think the powerpc 
implementation (as an example of this) will actually synchronize with 
anything *but* a spin_unlock().

> It really seems like it is some completely different concept from a
> barrier. And it shows, on the platform where it really matters (sn2), where
> the thing actually spins.

I agree that it probably isn't a "write barrier" per se. Think of it as a 
"tie two subsystems together" thing.

(And it doesn't just matter on sn2. It also matters on powerpc64, although 
I think they just set a flag and do the *real* sync in the spin_unlock() 
path).

Side note: the thing that makes "mmiowb()" even more exciting is that it's 
not just the CPU, it's the fabric outside the CPU that matters too. That's 
why the sn2 needs this - but the powerpc example shows a case where the 
ordering requirement actually comes from the CPU itself.

			Linus

  reply	other threads:[~2007-08-22 18:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-22  4:57 wmb vs mmiowb Nick Piggin
2007-08-22 18:07 ` Linus Torvalds [this message]
2007-08-22 19:02   ` Jesse Barnes
2007-08-23  2:20     ` Nick Piggin
2007-08-23  2:57       ` Linus Torvalds
2007-08-23  3:54         ` Nick Piggin
2007-08-23 16:14           ` Linus Torvalds
2007-08-23  4:20         ` Nick Piggin
2007-08-23 16:16           ` Linus Torvalds
2007-08-23 16:27             ` Benjamin Herrenschmidt
2007-08-24  3:09               ` Nick Piggin
2007-08-28 20:56                 ` Brent Casavant
2007-08-29  0:59                   ` Nick Piggin
2007-08-29 18:53                     ` Brent Casavant
2007-08-30  3:36                       ` Nick Piggin
2007-08-30 19:42                         ` Brent Casavant
2007-09-03 20:48                           ` Nick Piggin
2007-08-24  2:59             ` Nick Piggin
2007-08-23 17:02       ` Jesse Barnes
2007-08-23  1:59   ` Nick Piggin
2007-08-23  7:27   ` Benjamin Herrenschmidt
2007-08-23 16:56     ` Jesse Barnes
2007-08-24  3:12       ` Nick Piggin
2007-08-28 21:21       ` Brent Casavant
2007-08-28 23:01         ` Peter Chubb
2007-08-23  7:25 ` Benjamin Herrenschmidt

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=alpine.LFD.0.999.0708221049560.30176@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=jesse.barnes@intel.com \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=npiggin@suse.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