I am currently testing a comstomized SOC with ARM1176JZF-S core, 32KB-cache on Linux-188.8.131.52, and I encountered a cache-DMA data coherence problem in SD host driver. The phenonmenon is random data error while file copying. The error occurs once or twice during 100 iterations of 1GB-file copying test.
The implementation of the DMA operation has followed the suggestion of the kernel document “DMA-API.txt”, that is, the DMA_TO_DEVICE synchronisation is done after the last modification of the memory region that will be read by the DMA device, and the DMA_FROM_DEVICE synchronisation is done before the driver accesses data that was changed by the DMA device. However, the data coherence still cannot be guaranteed.
I referred to an ARM technical support knowledge article at http://infocenter.ar...qs/ka14041.html . For the ARMv6\v7 speculative execution, the DSB and DMB instructions are necessary to ensure data access correctness. The Linux ARMv6 cache operation has utlized DSB instruction, “mcr p15, 0, r0, c7, c10, 4” in the kernel source file, “linux-184.108.40.206/arch/arm/mm/cache-v6.S” to handle the speculative execution issue, but that cannot fix the stale data problem in my case.
Finally, I added a DMB instruction, “mcr p15, 0, r0, c7, c10, 5” after each cache invalidation and clean operation, and then the data error problem does not occur anymore. But I am still not sure if my modification is reasonable. I have some questions about the DSB and DMB instructions as listed below:
1. The Linux kernel utilizes DSB instruction only. Is the DSB instruction sufficient for ensuring the cache coherence?
2. If the DSB instruction is sufficient, why is the stale data still written into the SD card until I added a DMB instruction after the cache invalidation and clean operation?
3. Although the ARM technical article has described the functions of DSB and DMB instructions, I still cannot tell the critical difference between the two instructions. Could anyone explain?
Thanks for helping me!!
This post has been edited by Vincent Wu: 30 September 2011 - 06:13 AM