Monday, 17 September 2007
For a long time, the ordering of memory accesses between processors in a multi-core or multi-processor system based on the Intel x86 architecture has been under specified. Many newsgroup posts have discussed the interpretation of the Intel and AMD software developer manuals, and how that translates to actual guarantees, but there has been nothing authoritative, despite comments from Intel engineers. This has now changed! Both Intel and AMD have now released documentation of their memory ordering guarantees — Intel has published a new white paper (Intel 64 Architecture Memory Ordering White Paper) devoted to the issue, whereas AMD have updated their programmer's manual (Section 7.2 of AMD64 Architecture Programmer's Manual Volume 2: System Programming Rev 3.13).
In particular, there are a couple of things that a now made explicitly clear by this documentation:
- Stores from a single processor cannot be reordered, and
- Memory accesses obey causal consistency, so
- An aligned load is an acquire operation, and
- An aligned store is a release operation, and
- A locked instruction (such as
lock cmpxchg) is both an acquire and a release operation.
This has implications for the implementation of threading primitives such as mutexes for IA-32 and Intel 64 architectures — in some cases the code can be simplified, where it has been written to take a pessimistic interpretation of the specifications.