I am doing some benchmarking and I need to clear the cache before each test. I have this example here:
Caches and Self-Modifying Code
However, I just want to clean the whole cache. Is there an easy way to do that? I do not need to know the start and end address of the functions. I just want some simple code
Thanks.
The ARMv7-A/R Architecture gives an example sequence for cleaning the entire data and unified cache, using set/way operations. It's right at the end of chapter B2.2.7 (Cache and branch predictor maintenance operations), under a sub-heading of "Performing cache maintenance operations". My recommendation would to use that code.
If you have DS-5 installed, the "startup_Cortex-A9" example in the Bare-metal_examples.zip includes a version of this code. The difference is the code in the example is doing an invalidate rather than a clean operation. But that is easy enough to change.
I am doing this in user side code. I thought that this was only possible via the clean_cache function. So, running your suggested code will work there too?
Ahh, sorry - I had misunderstood your question. No, you can't directly clean/invalidate the caches from User mode. If you're are running under an OS, you will have to make a call to the OS to have it do it for you.
Which OS are you using?
I am using the Linux Kernel 3.7 on a Altera Cyclone V board.
Are you able to say if this is enough to clean the whole cache? Using the example in the OP
uint32_t * code = mmap(
NULL,
32768, // 32kb -- Whole Cache.
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0);
Hi there,
I know that this is an old post, but I have a related question.
I should clean and invalidate the L2 cache on Cortex A9. Can I use your function? Instead of 32768 I will use 512000, the size of L2 cache.
It works?
View all questions in Cortex-A / A-Profile forum