-
-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Memory caches are very important for getting good performance from modern CPUs, but they also introduce additional complexity because caches introduce opportunities for different agents to have a different view of what memory contains. Additionally, when there are multiple agents all accessing memory, complexity can arise if they try to access the same memory locations at the same time. Although the ARM926EJ-S is a relatively simple CPU in a single-core configuration, the AM1808 SoC contains multiple DMA controllers and other bus mastering peripherals. These concerns will be of increasing relevance as we make additional use of them.
In order to prevent extremely-difficult-to-debug bugs in this area, we need to have a clear plan for how this will be approached, such as by doing the following:
- Figure out what state the caches are currently being left in, and enable them if they are not enabled.
- Check if DMA controllers are cache-coherent with the CPU, or if CPU caches need to be flushed before performing DMA
- Write an internal API for managing memory issues around DMA transfers. When writing data to be accessed by peripherals, this requires at minimum a compiler memory barrier and possibly also a cache flush. When reading memory written by peripherals, this may require a cache invalidate or an uncached mapping.
- Figure out what happens if two agents (e.g. the CPU and a DMA controller) access the same memory at the same time (which is currently used by the WIP new ADC implementation). Are word accesses atomic, or can torn values be observed?
- Decide what memory model will be followed, in order to make sure the compiler does not miscompile code (for example: adopting the C/C++ memory model which requires atomic types, adopting the Linux kernel memory model, adopting a simplified memory model tailored to GCC/clang behavior)