mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Suzanne Wood <suzannew@cs.pdx.edu>
Cc: dhowells@redhat.com, linux-kernel@vger.kernel.org, paulmck@us.ibm.com
Subject: Re: [PATCH] Document Linux's memory barriers [try #5]
Date: Thu, 30 Mar 2006 21:18:24 +0100	[thread overview]
Message-ID: <27311.1143749904@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <200603292051.k2TKpCde027872@baham.cs.pdx.edu>

Suzanne Wood <suzannew@cs.pdx.edu> wrote:

> Do you mean to formalize preconditions on the value of Y and contents of A 
> and consider postconditions after the execution of the three statements of 
> the example where the value of X is the prior content of A and A contains and 
> Z equals the value of Y.

Something like that, yes.

How about the attached instead?  My explanation didn't give a write/write
example, so I've added that in too.

> Sorry to be unclear.  I was just asking about the explanation of the 
> self-consistent CPU example.  The other ideas in the document are more
> difficult, so thought this part might be simplified.

The whole subject is fraught with unclarity:-)

David


However, it is guaranteed that a CPU will be self-consistent: it will see its
_own_ accesses appear to be correctly ordered, without the need for a memory
barrier.  For instance with the following code:

	U = *A;
	*A = V;
	*A = W;
	X = *A;
	*A = Y;
	Z = *A;

and assuming no intervention by an external influence, it can be taken that the
final result will appear to be:

	U == the original value of *A
	X == W
	Z == Y
	*A == Y

The code above may cause the CPU to generate the full sequence of memory
accesses:

	U=LOAD *A, STORE *A=V, STORE *A=W, X=LOAD *A, STORE *A=Y, Z=LOAD *A

But, without intervention, the sequence may have almost any combination of
elements barring the load of *A into U and the store of Y into *A discarded as
the CPU may combine or discard memory accesses as it sees fit, provided _its_
view of the world is consistent.  This leads to the following possible other
sequences:

	U=LOAD *A, STORE *A=V, STORE *A=W, X=LOAD *A, STORE *A=Y
	U=LOAD *A, STORE *A=V, STORE *A=W, STORE *A=Y, Z=LOAD *A
	U=LOAD *A, STORE *A=V, STORE *A=W, STORE *A=Y
	U=LOAD *A, STORE *A=V, STORE *A=Y, Z=LOAD *A
	U=LOAD *A, STORE *A=V, STORE *A=Y
	U=LOAD *A, STORE *A=W, X=LOAD *A, STORE *A=Y
	U=LOAD *A, STORE *A=W, STORE *A=Y, Z=LOAD *A
	U=LOAD *A, STORE *A=W, STORE *A=Y
	U=LOAD *A, STORE *A=Y, Z=LOAD *A
	U=LOAD *A, STORE *A=Y

Note:

 (*) STORE *A=W can only be dispensed with if X=LOAD *A is also dispensed with,
     otherwise X would be given the original value of *A or the value assigned
     there from V, and not the value assigned there from W.

 (*) STORE *A=V would probably be discarded entirely by the CPU - if not the
     compiler - as it's effect is overridden by STORE *A=W without anything
     seeing it.

 (*) STORE *A=Y may be deferred indefinitely until the CPU has some reason to
     perform it or discard it.

 (*) Even the two 'fixed' operations can be dispensed with if they can be
     combined or discarded with respect to the surrounding code.

 (*) The compiler may also combine, discard or defer elements of the sequence

  reply	other threads:[~2006-03-30 20:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-29 20:51 Suzanne Wood
2006-03-30 20:18 ` David Howells [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-03-31 16:16 Suzanne Wood
2006-03-31  0:55 Suzanne Wood
2006-03-31 14:51 ` David Howells
2006-03-28 22:25 Suzanne Wood
2006-03-29 17:54 ` David Howells
     [not found] <20060315200956.4a9e2cb3.akpm@osdl.org>
2006-03-09 20:29 ` [PATCH] Document Linux's memory barriers [try #4] David Howells
2006-03-15 14:23   ` [PATCH] Document Linux's memory barriers [try #5] David Howells
2006-03-16 11:50     ` David Howells
2006-03-16 17:18       ` Linus Torvalds
2006-03-17  1:20         ` Nick Piggin
2006-03-16 23:17     ` Paul E. McKenney
2006-03-16 23:55       ` Linus Torvalds
2006-03-17  1:29         ` Paul E. McKenney
2006-03-17  5:32           ` Linus Torvalds
2006-03-17  6:23             ` Paul E. McKenney
2006-03-23 18:34     ` David Howells
2006-03-23 19:28       ` Linus Torvalds
2006-03-23 22:26       ` Paul E. McKenney

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=27311.1143749904@warthog.cambridge.redhat.com \
    --to=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@us.ibm.com \
    --cc=suzannew@cs.pdx.edu \
    /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

Powered by JetHome