public inbox for linux-kernel@vger.kernel.org
 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: Fri, 31 Mar 2006 15:51:44 +0100	[thread overview]
Message-ID: <19707.1143816704@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <200603310055.k2V0trkY013523@murzim.cs.pdx.edu>

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

> OK, you can dispense with a store if the value is not used before another
> store to the same memory location.  So if, for some other reason, X = *A
> goes away, you discard *A = W.

What I was actually thinking of is:

	*A = Y;
	Z = *A;

Can be changed by the compiler or the CPU into:

	*A = Y;
	Z = Y;

Which would eliminate the externally visible "Z = LOAD *A" entirely by
combination with the store.

However, that's reintroducing the concept of caching back into the abstract
CPU again - which complicates things once again.

I've decided to rewrite what I was trying to say to the attached.

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 assumed 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

in that order, but, without intervention, the sequence may have almost any
combination of elements combined or discarded, provided the program's view of
the world remains consistent.

The compiler may also combine, discard or defer elements of the sequence before
the CPU even sees them.

For instance:

	*A = V;
	*A = W;

may be reduced to:

	*A = W;

since, without a write barrier, it can be assumed that the effect of the
storage of V to *A is lost.  Similarly:

	*A = Y;
	Z = *A;

may, without a memory barrier, be reduced to:

	*A = Y;
	Z = Y;

and the LOAD operation never appear outside of the CPU.

  reply	other threads:[~2006-03-31 14:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31  0:55 [PATCH] Document Linux's memory barriers [try #5] Suzanne Wood
2006-03-31 14:51 ` David Howells [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-03-31 16:16 Suzanne Wood
2006-03-29 20:51 Suzanne Wood
2006-03-30 20:18 ` David Howells
2006-03-28 22:25 Suzanne Wood
2006-03-29 17:54 ` David Howells
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
     [not found]   ` <20060315200956.4a9e2cb3.akpm@osdl.org>
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=19707.1143816704@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