public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, akpm@osdl.org, mingo@redhat.com,
	linux-arch@vger.kernel.org, linuxppc64-dev@ozlabs.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Document Linux's memory barriers
Date: Tue, 07 Mar 2006 18:40:25 +0000	[thread overview]
Message-ID: <1141756825.31814.75.camel@localhost.localdomain> (raw)
In-Reply-To: <31492.1141753245@warthog.cambridge.redhat.com>

On Maw, 2006-03-07 at 17:40 +0000, David Howells wrote:
> +Older and less complex CPUs will perform memory accesses in exactly the order
> +specified, so if one is given the following piece of code:

Not really true. Some of the fairly old dumb processors don't do this to
the bus, and just about anything with a cache wont (as it'll burst cache
lines to main memory)

> +     want to access to the address register, and then read or write the
> +     appropriate data register to access the chip's internal register:
> +
> +	*ADR = ctl_reg_3;
> +	reg = *DATA;

Not allowed anyway

> +     In this case, the barrier makes a guarantee that all memory accesses
> +     before the barrier will happen before all the memory accesses after the
> +     barrier. It does _not_ guarantee that all memory accesses before the
> +     barrier will be complete by the time the barrier is complete.

Better meaningful example would be barriers versus an IRQ handler. Which
leads nicely onto section 2

> +General memory barriers make a guarantee that all memory accesses specified
> +before the barrier will happen before all memory accesses specified after the
> +barrier.

No. They guarantee that to an observer also running on that set of
processors the accesses to main memory will appear to be ordered in that
manner. They don't guarantee I/O related ordering for non main memory
due to things like PCI posting rules and NUMA goings on.

As an example of the difference here a Geode will reorder stores as it
feels but snoop the bus such that it can ensure an external bus master
cannot observe this by holding it off the bus to fix up ordering
violations first.

> +Read memory barriers make a guarantee that all memory reads specified before
> +the barrier will happen before all memory reads specified after the barrier.
> +
> +Write memory barriers make a guarantee that all memory writes specified before
> +the barrier will happen before all memory writes specified after the barrier.

Both with the caveat above

> +There is no guarantee that any of the memory accesses specified before a memory
> +barrier will be complete by the completion of a memory barrier; the barrier can
> +be considered to draw a line in the access queue that accesses of the
> +appropriate type may not cross.

CPU generated accesses to main memory

> + (*) interrupt disablement and/or interrupts
> + (*) spin locks
> + (*) R/W spin locks
> + (*) mutexes
> + (*) semaphores
> + (*) R/W semaphores

Should probably cover schedule() here.

> +Locks and semaphores may not provide any guarantee of ordering on UP compiled
> +systems, and so can't be counted on in such a situation to actually do
> +anything at all, especially with respect to I/O memory barriering.

_irqsave/_irqrestore ...


> +==============================
> +I386 AND X86_64 SPECIFIC NOTES
> +==============================
> +
> +Earlier i386 CPUs (pre-Pentium-III) are fully ordered - the operations on the
> +bus appear in program order - and so there's no requirement for any sort of
> +explicit memory barriers.

Actually they are not. Processors prior to Pentium Pro ensure that the
perceived ordering between processors of writes to main memory is
preserved. The Pentium Pro is supposed to but does not in SMP cases. Our
spin_unlock code knows about this. It also has some problems with this
situation when handling write combining memory. The IDT Winchip series
processors are run in out of order store mode and our lock functions and
dmamappers should know enough about this. 

On x86 memory barriers for read serialize order using lock instructions,
on write the winchip at least generates serializing instructions.

barrier() is pure CPU level of course

> + (*) Normal writes to memory imply wmb() [and so SFENCE is normally not
> +     required].

Only at an on processor level and not for all clones, also there are
errata here for PPro.

> + (*) Accesses to uncached memory imply mb() [eg: memory mapped I/O].

Not always. MMIO ordering is outside of the CPU ordering rules and into
PCI and other bus ordering rules. Consider

	writel(STOP_DMA, &foodev->ctrl);
	free_dma_buffers(foodev);

This leads to horrible disasters.


> +
> +======================
> +POWERPC SPECIFIC NOTES

Can't comment on PPC 


  parent reply	other threads:[~2006-03-07 18:35 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-07 17:40 [PATCH] Document Linux's memory barriers David Howells
2006-03-07 10:34 ` Andi Kleen
2006-03-07 18:30   ` David Howells
2006-03-07 11:13     ` Andi Kleen
2006-03-07 19:24       ` David Howells
2006-03-07 18:46     ` Jesse Barnes
2006-03-07 19:23     ` Bryan O'Sullivan
2006-03-07 11:57       ` Andi Kleen
2006-03-07 20:01         ` Jesse Barnes
2006-03-07 21:14         ` Bryan O'Sullivan
2006-03-07 21:24           ` Andi Kleen
2006-03-08  0:36             ` Alan Cox
2006-03-08  0:35         ` Alan Cox
2006-03-07 18:40 ` Alan Cox [this message]
2006-03-07 18:54   ` linux-os (Dick Johnson)
2006-03-07 19:06     ` Matthew Wilcox
2006-03-07 19:15       ` linux-os (Dick Johnson)
2006-03-07 19:33     ` Alan Cox
2006-03-07 20:09   ` David Howells
2006-03-08  0:32     ` Alan Cox
2006-03-08  8:25     ` Duncan Sands
2006-03-08 22:06       ` Paul Mackerras
2006-03-08 22:24         ` David S. Miller
2006-03-08 22:31           ` Linus Torvalds
2006-03-08 22:42         ` Alan Cox
2006-03-08  2:07 ` Nick Piggin
2006-03-08  3:10 ` Paul Mackerras
2006-03-08  3:30   ` Linus Torvalds
2006-03-08 12:34     ` David Howells
2006-03-08 16:40       ` Bryan O'Sullivan
2006-03-08  7:41   ` Nick Piggin
2006-03-08 13:19   ` David Howells
2006-03-08 21:49     ` Paul Mackerras
2006-03-08 22:05       ` Alan Cox
2006-03-08 14:37 ` [PATCH] Document Linux's memory barriers [try #2] David Howells
2006-03-08 14:55   ` Alan Cox
2006-03-08 15:41     ` Matthew Wilcox
2006-03-08 17:19       ` David Howells
2006-03-08 22:10         ` Paul Mackerras
2006-03-08 23:08           ` Ivan Kokshaysky
2006-03-09  1:01             ` Paul Mackerras
2006-03-09 16:02               ` Ivan Kokshaysky
2006-03-08 17:04     ` David Howells
2006-03-08 17:36       ` Alan Cox
2006-03-08 18:35         ` David Howells
2006-03-08 18:45           ` Alan Cox
2006-03-08 18:59             ` David Howells
2006-03-08 11:38               ` Andi Kleen
2006-03-08 19:08             ` David Howells
2006-03-08 19:26               ` Linus Torvalds
2006-03-08 19:31                 ` David Howells
2006-03-09  0:35                   ` Paul Mackerras
2006-03-09  0:54                     ` Linus Torvalds
2006-03-09  1:08                       ` Paul Mackerras
2006-03-09  1:27                         ` Linus Torvalds
2006-03-09  2:38                           ` Nick Piggin
2006-03-09  3:45                           ` Paul Mackerras
2006-03-09  4:36                             ` Jesse Barnes
2006-03-09  7:41                               ` Paul Mackerras
2006-03-09  5:38                             ` Linus Torvalds
2006-03-09 12:27                               ` David Howells
2006-03-09 11:44                             ` Michael Buesch
2006-03-09  4:34                           ` Jesse Barnes
2006-03-09  4:43                             ` Paul Mackerras
2006-03-09 10:05                               ` Jes Sorensen
2006-03-09  0:55                     ` Jesse Barnes
2006-03-09  1:57                       ` Paul Mackerras
2006-03-09  4:26                         ` Jesse Barnes
2006-03-08 19:40                 ` Matthew Wilcox
2006-03-09  0:37                   ` Paul Mackerras
2006-03-09  0:59                     ` Jesse Barnes
2006-03-09  1:36                       ` Paul Mackerras
2006-03-09  4:18                         ` Jesse Barnes
2006-03-08 19:54                 ` Jesse Barnes
2006-03-08 20:02                 ` Alan Cox
2006-03-08 22:01     ` Paul Mackerras
2006-03-08 22:23       ` David S. Miller
2006-03-08 19:37   ` [PATCH] Document Linux's memory barriers [try #3] David Howells
2006-03-09 14:01     ` David Howells
2006-03-08 16:18 ` [PATCH] Document Linux's memory barriers Pavel Machek
2006-03-08 20:16   ` David Howells
2006-03-08 22:01     ` Alan Cox
2006-03-09 11:41       ` David Howells
2006-03-09 12:28         ` Alan Cox
2006-03-09 13:02           ` David Howells
2006-03-09 16:32         ` Linus Torvalds
2006-03-09 17:39           ` David Howells
2006-03-09 17:54             ` Linus Torvalds
2006-03-09 17:56               ` Linus Torvalds

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=1141756825.31814.75.camel@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=akpm@osdl.org \
    --cc=dhowells@redhat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc64-dev@ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=torvalds@osdl.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