Conceptual
Login

Allocating Memory a Device Can Write Into

Memory a device writes into directly has two addresses: the one your code uses and the one the device must be told, and on many machines it must also be arranged so that processor caches never hide the device's writes. A coherent allocation gives you both addresses and the cache guarantee in one object, tied to the device so it is freed when the device goes. Access to its contents goes through macros rather than plain field reads, because the compiler must not cache or reorder values the hardware may change underneath it. The C bugs this closes are passing a virtual address to hardware and reading stale cached data after a transfer.

Questions this Concept answers

  • Why must the contents of a coherent buffer be reached through the crate's dedicated accessor macros rather than ordinary field reads?