Skip to contentSkip to conversation

Document Linux's memory barriers [try #5]

PATCH Suzanne Wood 2 participants 2 messages Mar 28, 2006 – Mar 29, 2006

lore
Share & tools
lore
#0 lore raw

Hello,
This is just a question about intended meaning in a paragraph at the end of the "What are memory barriers?" section.

Quoted 23 lines

From: Paul E. McKenney Thu Mar 16 2006 - 18:14:11 EST

Quoted 5 lines · David Howells

The attached patch documents the Linux kernel's memory barriers.

I've updated it from the comments I've been given.

. . .

Good stuff!!! Please see comments interspersed, search for empty lines.

One particularly serious issue involve your smp_read_barrier_depends() example.

Quoted 4 lines

---
warthog>diffstat -p1 /tmp/mb.diff
Documentation/memory-barriers.txt | 1039

++++++++++++++++++++++++++++++++++++++

Review

Quoted 3 lines
1 files changed, 1039 insertions(+)
(quoted diff) +0 -0

b/Documentation/memory-barriers.txt

Quoted 8 lines

Documentation/memory-barriers.txt line 3

Quoted 8 lines

new file mode 100644
index 0000000..fd7a6f1

Documentation/memory-barriers.txt new file +3 -0
@@ -0,0 +1,1039 @@
+ ============================
+ LINUX KERNEL MEMORY BARRIERS
+ ============================

. . .

Quoted 7 lines

Documentation/memory-barriers.txt line 7

Quoted 4 lines
Documentation/memory-barriers.txt new file +4 -0
+=========================
+WHAT ARE MEMORY BARRIERS?
+=========================
+

. . .

Quoted 12 lines

Documentation/memory-barriers.txt line 19

Quoted 12 lines
Documentation/memory-barriers.txt new file +12 -0
+It is also 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:
+
+ X = *A;
+ *A = Y;
+ Z = *A;
+
+assuming no intervention by an external influence, it can be taken that:
+
+ (*) X will hold the old value of *A, and will never happen after the write and
+ thus end up being given the value that was assigned to *A from Y instead;

Seems like the subject of "will never happen" is the read from memory for the asmt to X, but does that sentence say that?

Quoted 5 lines

Documentation/memory-barriers.txt line 24

Quoted 5 lines
Documentation/memory-barriers.txt new file +5 -0
+ and
+
+ (*) Z will always be given the value in *A that was assigned there from Y, and
+ will never happen before the write, and thus end up with the same value
+ that was in *A initially.

Similarly, the read from memory for the asmt to Z won't precede the write of Y to *A.

Quoted 8 lines

Documentation/memory-barriers.txt line 32

Quoted 8 lines
Documentation/memory-barriers.txt new file +8 -0
+
+(This is ignoring the fact that the value initially in *A may appear to be the
+same as the value assigned to *A from Y).
+
+
+=================================
+WHERE ARE MEMORY BARRIERS NEEDED?
+=================================

It seems to require more effort than necessary to understand in regard to all that is presented in this document.

Thanks.
Suzanne

#1 lore raw
Quoted 2 lines · Suzanne Wood

Seems like the subject of "will never happen" is the read from memory for the asmt to X, but does that sentence say that?

"asmt"?

I agree that it doesn't make much sense, so how's this instead?

+ 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:
+
+ X = *A;
+ *A = Y;
+ Z = *A;
+
+ and assuming no intervention by an external influence, it can be taken that:
+
+ (*) X will end up holding the original value of *A, as
+
+ (*) the load of X from *A will never happen after the store of Y into *A, and
+ thus
+
+ (*) X will never be given instead the value that was assigned from Y to *A;
+ and
+
+ (*) Z will always be given the value in *A that was assigned there from Y, as +
+ (*) the load of Z from *A will never happen before the store, and thus +
+ (*) Z will never be given instead the value that was in *A initially. +
+ (This ignores the fact that the value initially in *A may appear to be the same
+ as the value assigned to *A from Y).

I'm not sure I want to split the points up that way, but it does make them clearer. I'm not sure that method of linking them works, since it looks like a bunch of incomplete statements.

Really, this should be described mathematically, if at all.

Quoted 2 lines

It seems to require more effort than necessary to understand in regard to all that is presented in this document.

Are you referring to my attempt to define a self-consistent CPU? Or to the subject in general?

If the former, you may be right. I'll look at compressing the whole thing down to a single paragraph.

David