February 04, 2020

Linux barriers and implementations

The Linux kernel has a family of barrier functions suitable for communicating across processors (smp_*), with DMA devices (dma_*), and for other uses (mb/rmb/wmb).

I've often found it useful to know what hardware instructions a particular barrier maps to; this table maps each Linux barrier to its corresponding implementation on x86-64 and aarch64.

x86_64aarch64
smp_rmb__asm__ __volatile__("": : :"memory") [1] dmb ishld [1]
smp_wmb__asm__ __volatile__("": : :"memory") [1] dmb ishst [1]
smp_mbasm volatile("lock; addl $0,-4(%%rsp)" ::: "memory", "cc") [1] dmb ish [1]
dma_rmb__asm__ __volatile__("": : :"memory") [1] dmb oshld [1]
dma_wmb__asm__ __volatile__("": : :"memory") [1] dmb oshst [1]
mbmfence [1]dsb sy [1]
rmblfence [1] dsb ld [1]
wmbsfence [1] dsb st [1]

  1. mmiowb was formerly used to enforce partial orders of MMIO writes with respect to main memory writes. It is no longer generally used, the required ordering properties have been folded into other primitives.

linux

Posted by vsrinivas at February 4, 2020 09:56 PM