05.02.2013 Views

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A3.4.6 Semaphores<br />

Application Level Memory Model<br />

The Swap (SWP) <strong>and</strong> Swap Byte (SWPB) instructions must be used with care to ensure that expected behavior<br />

is observed. Two examples are as follows:<br />

1. A system with multiple bus masters that uses Swap instructions to implement semaphores that control<br />

interactions between different bus masters.<br />

In this case, the semaphores must be placed in an uncached region of memory, where any buffering<br />

of writes occurs at a point common to all bus masters using the mechanism. The Swap instruction<br />

then causes a locked read-write bus transaction.<br />

2. A systems with multiple threads running on a uniprocessor that uses the Swap instructions to<br />

implement semaphores that control interaction of the threads.<br />

In this case, the semaphores can be placed in a cached region of memory, <strong>and</strong> a locked read-write bus<br />

transaction might or might not occur. The Swap <strong>and</strong> Swap Byte instructions are likely to have better<br />

performance on such a system than they do on a system with multiple bus masters such as that<br />

described in example 1.<br />

Note<br />

From <strong>ARM</strong>v6, use of the Swap <strong>and</strong> Swap Byte instructions is deprecated. All new software should use the<br />

Load-Exclusive <strong>and</strong> Store-Exclusive synchronization primitives described in Synchronization <strong>and</strong><br />

semaphores on page A3-12, for example LDREX <strong>and</strong> STREX.<br />

A3.4.7 Synchronization primitives <strong>and</strong> the memory order model<br />

The synchronization primitives follow the memory order model of the memory type accessed by the<br />

instructions. For this reason:<br />

Portable code for claiming a spin-lock must include a Data Memory Barrier (DMB) operation,<br />

performed by a DMB instruction, between claiming the spin-lock <strong>and</strong> making any access that makes<br />

use of the spin-lock.<br />

Portable code for releasing a spin-lock must include a DMB instruction before writing to clear the<br />

spin-lock.<br />

This requirement applies to code using:<br />

the Load-Exclusive/Store-Exclusive instruction pairs, for example LDREX/STREX<br />

the deprecated synchronization primitives, SWP/SWPB.<br />

A3.4.8 Use of WFE <strong>and</strong> SEV instructions by spin-locks<br />

<strong>ARM</strong>v7 <strong>and</strong> <strong>ARM</strong>v6K provide Wait For Event <strong>and</strong> Send Event instructions, WFE <strong>and</strong> SEV, that can assist with<br />

reducing power consumption <strong>and</strong> bus contention caused by processors repeatedly attempting to obtain a<br />

spin-lock. These instructions can be used at application level, but a complete underst<strong>and</strong>ing of what they do<br />

depends on system-level underst<strong>and</strong>ing of exceptions. They are described in Wait For Event <strong>and</strong> Send Event<br />

on page B1-44.<br />

<strong>ARM</strong> DDI 0406B Copyright © 1996-1998, 2000, 2004-2008 <strong>ARM</strong> Limited. All rights reserved. A3-23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!