Search code examples
cmemorycompiler-constructionarmcpu-cache

How to bypass caches on an ARM machine


How can I bypass caches on all accessed to a certain memory location from user space on ARM?

Here's an example:

uint16_t* ptr = (uint16_t*) malloc(MEM_SIZE * sizeof(uint16_t));

*ptr = 0xFFFF;

Can I make ptr to be uncached to avoid cache pollution? I am running in Syscall Emulation mode (very limited OS support) on an ARMv7 architecture.

UPDATE:

Addressing some of the comments below:

I am running this code on the gem5 simulator (http://www.gem5.org/) in Syscall Emulation mode, which is in short described as follows:

gem5 can simulate a complete system with devices and an operating system in full system mode (FS mode), or user space only programs where system services are provided directly by the simulator in syscall emulation mode (SE mode).

SE mode is using an MMU. I am currently modeling after the ARM Cortex-A9, but I am assuming if there is a way to solve this issue it should be ISA dependent and not processor implementation dependent? I am using L1/L2 caches, but as I am studying various architectures this should also be irrelevant, as I am looking for a general mechanism of bypassing all caches for a specific memory location.


Solution

  • From user space - no. Memory from malloc() comes from the heap.

    Through a kernel module, probably yes. Page(s) of memory can be set by MMU as uncached using e.g. dma_alloc_coherent(), then made available to userspace, see LDD3 15.2.7. Remapping Kernel Virtual Addresses. However, that may be more trouble than you wish.