英文:
__sync_add_and_fetch triggers an sError interrupt on raspberry pi 4b
问题
当我在我的树莓派 Pi 4B 上使用 gcc 的 __sync_add_and_fetch
来原子地增加一个整数时,生成了以下代码:
172e4: c85f7e60 ldxr x0, [x19]
172e8: 91000400 add x0, x0, #0x1
172ec: c801fe60 stlxr w1, x0, [x19]
172f0: 35ffffa1 cbnz w1, 172e4 <kernel_start+0xc4>
172f4: d5033bbf dmb ish
我已经启用了 MMU,使用 MAIR 属性为 0xff
的普通内存。页表映射为内部和外部可共享。我可以以非独占方式读写内存。然而,当上述代码运行时,我在 ldxr
指令处收到了一个 sError interrupt
(类别为 0x2f
)。ISS 是 0x2
,根据 Exception Syndrome Register, EL1,这是对外部访问的 SLVERR
。
根据 Arm Cortex®-M7 Processor,发生这种情况的原因是:
> 系统中无法处理独占事务的 AXI 从设备返回 OKAY 以响应独占读取。这也被视为外部错误,处理器会将响应视为 SLVERR。
我需要采取特定措施来启用独占内存事务吗?
英文:
When I use gcc's __sync_add_and_fetch
to atomically increment an integer on my raspberry pi4b, the following code is generated:
172e4: c85f7e60 ldxr x0, [x19]
172e8: 91000400 add x0, x0, #0x1
172ec: c801fe60 stlxr w1, x0, [x19]
172f0: 35ffffa1 cbnz w1, 172e4 <kernel_start+0xc4>
172f4: d5033bbf dmb ish
I have the MMU enabled, using normal memory with MAIR attribute 0xff
. Page tables are mapped with inner & outer shareable. I am able to read/write the memory in a non-exclusive way. However when the above code runs, I get an sError interrupt
(class 0x2f
) at the ldxr
instruction. ISS is 0x2
, which according to Exception Syndrome Register, EL1 is an SLVERR
on external access.
According to Arm Cortex®-M7 Processor, this happens when:
> An AXI slave device in the system that cannot handle exclusive transactions returns OKAY in response to an exclusive read. This is also treated as an external error, and the processor behaves as if the response was SLVERR.
Is there something specific I need to do to enable exclusive memory transactions?
答案1
得分: 2
答案在这里:
> 必须启用数据缓存(SCTLR_EL1 位 2 设置为 0b1)
一旦我启用了数据缓存,原子增量就可以正常工作。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论