Skip to contentSkip to conversation

Document Linux's memory barriers

PATCH Robert Hancock 3 participants 4 messages Mar 8, 2006 8 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 7 lines · Jesse Barnes
Quoted 4 lines · David Howells

True, I suppose. I should make it clear that these accessor functions imply memory barriers, if indeed they do, and that you should use them rather than accessing I/O registers directly (at least, outside the arch you should).

But they don't, that's why we have mmiowb().

I don't think that is why that function exists.. It's a no-op on most architectures, even where you would need to be able to do write barriers on IO accesses (i.e. x86_64 using CONFIG_UNORDERED_IO). I believe that function is intended for a more limited special case.

I think any complete memory barrier description should document that function as well as EXPLICITLY specifying whether or not the readX/writeX, etc. functions imply barriers or not.

Quoted 1 line

Btw, thanks for putting together this documentation, it's desperately needed.

Seconded.. The fact that there's debate over what the rules even are shows why this is needed so badly.

Signature · 3 lines
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 7 lines · Alan Cox
Quoted 3 lines · Andi Kleen
Quoted 2 lines

But on most arches those accesses do indeed seem to happen in-order. On i386 and x86_64, it's a natural consequence of program store ordering.

Not true for reads on x86.

You must have a strange kernel Andi. Mine marks them as volatile unsigned char * references.

Well, that and the fact that IO memory should be mapped as uncacheable in the MTRRs should ensure that readl and writel won't be reordered on i386 and x86_64.. except in the case where CONFIG_UNORDERED_IO is enabled on x86_64 which can reorder writes since it uses nontemporal stores..

Signature · 3 lines
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from [email protected]
Home Page: http://www.roberthancock.com/
#10 lore raw
Quoted 9 lines · Robert Hancock
Quoted 2 lines · Alan Cox

You must have a strange kernel Andi. Mine marks them as volatile unsigned char * references.

Well, that and the fact that IO memory should be mapped as uncacheable in the MTRRs should ensure that readl and writel won't be reordered on i386 and x86_64.. except in the case where CONFIG_UNORDERED_IO is enabled on x86_64 which can reorder writes since it uses nontemporal stores..

You need both

real/writel need the volatile to stop gcc removing/reordering the accesses at compiler level, and the mtrr/pci bridge stuff then deals with bus level ordering for that CPU.

#11 lore raw
In reply to Robert Hancock
Quoted 5 lines · Robert Hancock
Quoted 4 lines · Alan Cox
Quoted 3 lines · Andi Kleen
Quoted 2 lines

But on most arches those accesses do indeed seem to happen in-order. On i386 and x86_64, it's a natural consequence of program store ordering.

Not true for reads on x86.

Quoted 8 lines
Quoted 2 lines

You must have a strange kernel Andi. Mine marks them as volatile unsigned char * references.

Well, that and the fact that IO memory should be mapped as uncacheable in the MTRRs should ensure that readl and writel won't be reordered on i386 and x86_64.. except in the case where CONFIG_UNORDERED_IO is enabled on x86_64 which can reorder writes since it uses nontemporal stores..

CONFIG_UNORDERED_IO is a failed experiment. I just removed it.

-Andi