gpt4 book ai didi

arm - Cortex-M4 中的未对齐访问是原子的吗?

转载 作者:行者123 更新时间:2023-12-03 17:25:14 26 4
gpt4 key购买 nike

ARM documentation ,它提到

The Cortex-M4 processor supports ARMv7 unaligned accesses, and performs all accesses as single, unaligned accesses. They are converted into two or more aligned accesses by the DCode and System bus interfaces.



我不清楚这是否意味着数据访问对程序员来说是原子的。然后我发现了一个 StackOverflow comment将文档解释为:

Actually some ARM processors like the Cortex-M3 support unaligned access in HW, so even an unaligned read/write is atomic. The access may span multiple bus cycles to memory, but there is no opportunity for another instruction to jump in between, so it is atomic to the programmer.



然而,我又环顾四周,发现 claims这与先前的主张相矛盾:

Another one is the fact that on cores beginning ARMv6 and later, in order for the hardware to “fix-up” an unaligned access, it splits it up into multiple smaller, byte loads. However, these are not atomic!.



那么,我相信谁呢?在某些情况下,我为 中的每个元素设置了 setter/getter。包装在我的项目中构建。换句话说,某些结构元素可能未对齐。我想知道在 Cortex-M4 上访问结构元素是否总是保证是原子的。如果不是,我想我将不得不手动启用/禁用中断或添加一些互斥锁,但如果 ARM Cortex M4 可以保证数据访问是原子的,我宁愿不这样做。

最佳答案

不,它不是。

https://static.docs.arm.com/ddi0403/eb/DDI0403E_B_armv7m_arm.pdf 处的 A3.5.3 节

引自 ARMv7-M 引用手册

In ARMv7-M, the single-copy atomic processor accesses are:
• All byte accesses.
• All halfword accesses to halfword-aligned locations.
• All word accesses to word-aligned locations

因此,如果您要复制未与 32 位边界对齐(在 v7-M 中允许)的 uint32,则该副本不是原子的。

还引述,
When an access is not single-copy atomic, it is executed as a sequence of smaller accesses,
each of which is single-copy atomic, at least at the byte level.

关于arm - Cortex-M4 中的未对齐访问是原子的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59112957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com