public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@redhat.com>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, akpm@osdl.org, mingo@redhat.com,
	alan@redhat.com, linux-arch@vger.kernel.org,
	linuxppc64-dev@ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Document Linux's memory barriers [try #2]
Date: Wed, 8 Mar 2006 09:55:06 -0500	[thread overview]
Message-ID: <20060308145506.GA5095@devserv.devel.redhat.com> (raw)
In-Reply-To: <29826.1141828678@warthog.cambridge.redhat.com>

On Wed, Mar 08, 2006 at 02:37:58PM +0000, David Howells wrote:
> + (*) reads can be done speculatively, and then the result discarded should it
> +     prove not to be required;

That might be worth an example with an if() because PPC will do this and if 
its a read with a side effect (eg I/O space) you get singed..

> +same set of data, but attempting not to use locks as locks are quite expensive.

s/are quite/is quite

and is quite confusing to read

> +SMP memory barriers are normally mere compiler barriers on a UP system because

s/mere//

Makes it easier to read if you are not 1st language English.

> +In addition, accesses to "volatile" memory locations and volatile asm
> +statements act as implicit compiler barriers.

Add

The use of volatile generates poorer code and hides the serialization in 
type declarations that may be far from the code. The Linux coding style therefore
strongly favours the use of explicit barriers except in small and specific cases.

> +SMP memory barriers are only compiler barriers on uniprocessor compiled systems
> +because it is assumed that a CPU will be apparently self-consistent, and will
> +order overlapping accesses correctly with respect to itself.

Is this true of IA-64 ??

> +There is no guarantee that some intervening piece of off-the-CPU hardware will
> +not reorder the memory accesses.  CPU cache coherency mechanisms should
> +propegate the indirect effects of a memory barrier between CPUs.

[For information on bus mastering DMA and coherency please read ....]

sincee have a doc on this

> +There are some more advanced barriering functions:

"barriering" ... ick,  barrier.

> +LOCKING FUNCTIONS
> +-----------------
> +
> +For instance all the following locking functions imply barriers:

s/For instance//

> + (*) spin locks
> + (*) R/W spin locks
> + (*) mutexes
> + (*) semaphores
> + (*) R/W semaphores
> +
> +In all cases there are variants on a LOCK operation and an UNLOCK operation.
> +
> + (*) LOCK operation implication:
> +
> +     Memory accesses issued after the LOCK will be completed after the LOCK
> +     accesses have completed.
> +
> +     Memory accesses issued before the LOCK may be completed after the LOCK
> +     accesses have completed.
> +
> + (*) UNLOCK operation implication:
> +
> +     Memory accesses issued before the UNLOCK will be completed before the
> +     UNLOCK accesses have completed.
> +
> +     Memory accesses issued after the UNLOCK may be completed before the UNLOCK
> +     accesses have completed.
> +
> + (*) LOCK vs UNLOCK implication:
> +
> +     The LOCK accesses will be completed before the UNLOCK accesses.
> +
> +And therefore an UNLOCK followed by a LOCK is equivalent to a full barrier, but
> +a LOCK followed by an UNLOCK isn't.
> +
> +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 barriering, unless combined with
> +interrupt disablement operations.

s/disablement/disabling/

Should clarify local ordering v SMP ordering for locks implied here.


> +INTERRUPT DISABLEMENT FUNCTIONS
> +-------------------------------

s/Disablement/Disabling/

> +Interrupt disablement (LOCK equivalent) and enablement (UNLOCK equivalent) will

disable

> +===========================
> +LINUX KERNEL I/O BARRIERING

/barriering/barriers

> + (*) inX(), outX():
> +
> +     These are intended to talk to legacy i386 hardware using an alternate bus
> +     addressing mode.  They are synchronous as far as the x86 CPUs are

Not really true. Lots of PCI devices use them. Need to talk about "I/O space"
> +     concerned, but other CPUs and intermediary bridges may not honour that.
> +
> +     They are guaranteed to be fully ordered with respect to each other.

And make clear I/O space is a CPU property and that inX()/outX() may well map
to read/write variant functions on many processors

> + (*) readX(), writeX():
> +
> +     These are guaranteed to be fully ordered and uncombined with respect to
> +     each other on the issuing CPU, provided they're not accessing a

MTRRs

> +     prefetchable device.  However, intermediary hardware (such as a PCI
> +     bridge) may indulge in deferral if it so wishes; to flush a write, a read
> +     from the same location must be performed.

False. Its not so tightly restricted and many devices the location you write
is not safe to read so you must use another. I'd have to dig the PCI spec 
out but I believe it says the same devfn. It also says stuff about rules for
visibility of bus mastering relative to these accesses and PCI config space
accesses relative to the lot (the latter serveral chipsets get wrong). We
should probably point people at the PCI 2.2 spec .

Looks much much better than the first version and just goes to prove how complex
this all is


  reply	other threads:[~2006-03-08 14:55 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
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 [this message]
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=20060308145506.GA5095@devserv.devel.redhat.com \
    --to=alan@redhat.com \
    --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