Memory Barrier

In the newer ARM processors (ARMv6 and above) it is architecturally defined that the software must perform a Data Memory Barrier operation every time a resource is either acquired or released, to ensure a consistent memory view to all running processes.

These newer processors can optimize the execution order of instructions and data accesses, but these optimizations may create speculative accesses to memory or out-of-order execution of instructions, leading to undesirable and unintended program behavior.

In those situations we want the processor to behave as the classical ARM processors and execute instructions and access memory in program order.

There are three types of barrier instructions, considering a uni-processor environment like the Raspberry Pi:

  • Data Synchronization Barrier (DSB) – does not complete until all the previous instructions complete;
  • Data Memory Barrier (DMB) – ensures that any explicit memory access after the DMB instruction only start when all explicit memory accesses before the DMB instruction complete;
  • Instruction Synchronization Barrier (ISB) – flushes the pipeline in the processor, so all the following instructions are fetched from cache or memory once the ISB completes.

The RPi BSP must then  implement a routine or macro that provides the DMB  inline assembly code, since several peripherals may need to access the same registers in the future (to use the MailBox interface, for instance).

The memory barrier instructions can be found at:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s