A Locked Read is a special kind of Memory Read that is part of an atomic Read-Modify-Write operation — meaning it ensures that no one else can touch that memory location until the operation is complete.
Example use case:
- Semaphore Test-and-Set – Software wants to check if a semaphore (a memory flag) is
0and then set it to1without anyone else writing to it in between. - If this is not guaranteed, you could have a race condition where two CPUs or devices both think they successfully locked the semaphore, breaking synchronization.
How PCIe Handles This
Unlike ordinary memory reads, a locked read:
- Is initiated by the CPU only (Root Port generates MRdLk).
- Requires exclusive access to the path from the Root Port to the target memory.
- Prevents other devices from issuing transactions to that target memory while the lock is in effect.
Step-by-Step Flow
-
Root Port Sends a Locked Read Request (MRdLk)
- The packet includes the memory address and a “lock” indicator.
- It is routed through switches toward the target memory (or legacy endpoint).
-
Egress Port Locking
- At each switch or routing device (called a service point), the egress port used by this request is “locked.”
- This means no other packets are allowed to traverse that path toward the destination until the locked transaction is completed.
-
Target Completer Responds
- The target gathers the data and returns Locked Completion TLPs back to the Requester.
- These Completions are marked as “locked,” keeping the path locked until they all return.
-
If an Error Occurs
- The Completer sends a locked completion without data and sets an error status.
- The Requester (CPU) understands this means the lock failed.
- Software decides what to do — retry, abort, or handle the error in some other way.
-
Unlocking
- Once the locked Completion(s) are delivered, the path is unlocked so that normal traffic can resume.
Legacy Support
- Locked transactions were originally designed because PCI was meant to be a replacement for CPU front-side buses — so CPU-like atomic operations were supported.
- In modern PCIe:
- New devices are not allowed to accept locked transactions unless they declare themselves as Legacy Endpoints.
- This is partly to discourage reliance on this old mechanism and encourage newer atomic operations (PCIe added native atomic ops in later versions).
Key Takeaways
- MRdLk = Memory Read Locked.
- CPU-only feature (Root Port initiates it).
- Locks the data path (no other traffic can pass through that egress port) → ensures atomicity.
- Rarely used in modern systems, kept mainly for backward compatibility.
- PCIe introduced native atomic operations (like AtomicOp FetchAdd, Swap, CAS) which are better alternatives and don’t require locking whole paths.
