0

I'm looking for a way to flush the L1-L2 cache using a kernel module. Is there a way to completely flush the whole cluster cache (4 core configuration) or even better, write back the dirty cache lines into main memory?

3 Answers3

0

It sounds weird that you want to flush your caches from a kernel module. That should be done by the core-kernel part and as a driver you should not have to worry about that.

Is there any specific reason you need to do that in a driver?

matthias.bgg
  • 165
  • 4
  • I want to achieve data coherency between the SoC and external devices. So if data in an allocated page are modified by X, i want to make sure that the changes will be visible to Y, which is outside the cache coherency of X – Κυριάκος Παρασκευάς Sep 12 '18 at 11:15
  • so why not just use the `volatile` keyword [(see here)](https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c?) ? It prevents data to be written to cache in first place – jonnyx Sep 20 '18 at 07:04
  • @jonnyx volatile keyword tells the compiler to reread data value instead of assuming that it has stayed the same. This is not what I want. – Κυριάκος Παρασκευάς Sep 21 '18 at 11:07
0

I think you want to have a look at 3.9 of "Understanding the Linux Virtual Memory Manager" [1] from Mel Gorman. I think what you are looking for is flush_cache_page(...)

[1] https://www.kernel.org/doc/gorman/

matthias.bgg
  • 165
  • 4
0

Well it seems that it is actually different the way that the caches are flushed in different architectures. Nevertheless, I didn't find an implementation that works. BUT, what I did was to find the Page table entry (PTE) of the particular page that I want to flush, and changed the memory attributes to Non-Cacheable. Then, the data went directly to the DRAM. (ARMv8) Cheers