public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: David Howells <dhowells@redhat.com>, Pavel Machek <pavel@ucw.cz>,
	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: Thu, 09 Mar 2006 13:02:01 +0000	[thread overview]
Message-ID: <26313.1141909321@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <1141907339.16745.2.camel@localhost.localdomain>

Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> > Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > So, you're saying that the LOCK and UNLOCK primitives don't actually modify
> > memory, but rather simply pin the cacheline into the CPU's cache and refuse to
> > let anyone else touch it?
> 
> Basically yes

What you said is incomplete: the cacheline is wangled into the Exclusive
state, and there it sits until modified (at which point it shifts to the
Modified state) or stolen (when it shifts to the Shared state). Whilst the x86
CPU might pin it there for the duration of the execution of the locked
instruction, it can't leave it there until it detects a spin_unlock() or
equivalent.

I guess LL/SC and LWARX/STWCX work by the reserved load wangling the cacheline
into the Exclusive state, and then the conditional store only doing the store
if the cacheline is still in that state. I don't know whether the conditional
store may modify a cacheline that's in the Modified state, but I'd guess you'd
need more state than that, because you have to pair it with a load reserved.


With inter-CPU memory barriers I think you have to consider the cache part of
the memory, not part of the CPU. The CPU _does_ make a memory modification;
it's just that it doesn't proceed any further than the cache, until the cache
coherency mechanisms transfer the change to another CPU, or until the cache
becomes full and the lock's line gets ejected.

> > No... it can't work like that. It *must* make a memory modification 
> 
> Then you'll have to argue with the chip designers because it doesn't.
> 
> Its all built around the cache coherency. To make a write to a cache
> line I must be the sole owner of the line. Look up "MESI cache" in a
> good book on the subject.

http://en.wikipedia.org/wiki/MESI_protocol

And a picture of the state machine may be found here:

https://www.cs.tcd.ie/Jeremy.Jones/vivio/caches/MESIHelp.htm

David

  reply	other threads:[~2006-03-09 13:02 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
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 [this message]
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=26313.1141909321@warthog.cambridge.redhat.com \
    --to=dhowells@redhat.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc64-dev@ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=pavel@ucw.cz \
    --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