This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

v8.2 Atomic Instructions

Hello,

In the new v8.2, atomic instructions are presented which can be an alternative to the previous ld/st exclusive and other similar instructions.

My question is what is the advantage of using atomic instructions instead of for example a pair of ld/st exclusive or is there any document related to this part?

Thanks a lot

Parents
  • It depends on the system.

    Exclusives can be a problem in big systems, because there is a gap between the LDXR and STXR.  Imagine you want to atomically increment a count, your code does something like:

    LDXR  - Read current count
    ADD   - Add one
    STXR  - Attempt to store back
    CMP   - Did it work?

    There is a chance some other thread is also attempting to update the count, and hence the STXR fails.  That is, in the time between executing the LDXR and STXR someone else gets there first.  In a small (e.g. mobile) system this should be rare enough that it's uncommon and even if it does then you don't need many attempts before you succeed.In a much bigger system, this could become more of a problem. 

    Atomics solve this by telling the processor up front what you want to do.  The sequence above could be replaced by LDADD.  The processor might still do load, add, store internally - but because it knows upfront it has to add X to the value, you remove the "gap" where some other thread could get in.

    Note: The atomics were added in ARMv8.1-A, and so also in ARMv8.2-A.

Reply
  • It depends on the system.

    Exclusives can be a problem in big systems, because there is a gap between the LDXR and STXR.  Imagine you want to atomically increment a count, your code does something like:

    LDXR  - Read current count
    ADD   - Add one
    STXR  - Attempt to store back
    CMP   - Did it work?

    There is a chance some other thread is also attempting to update the count, and hence the STXR fails.  That is, in the time between executing the LDXR and STXR someone else gets there first.  In a small (e.g. mobile) system this should be rare enough that it's uncommon and even if it does then you don't need many attempts before you succeed.In a much bigger system, this could become more of a problem. 

    Atomics solve this by telling the processor up front what you want to do.  The sequence above could be replaced by LDADD.  The processor might still do load, add, store internally - but because it knows upfront it has to add X to the value, you remove the "gap" where some other thread could get in.

    Note: The atomics were added in ARMv8.1-A, and so also in ARMv8.2-A.

Children
No data