How to "invalidate" or "flush" a range of CPU cache in PowerPC architecture?

Viewed 266

I am working with an embedded device which communicates with my PowerPC CPU via PCIe. Due to the SDK constraints i have to use linux kernel version 4.1.8. This version doesn't have functions related to cache operations in $KERNEL_SOURCE/arch/powerpc/include/asm/, such as:

  • "invalidate_dcache_range()"
  • "flush_dcache_range()"
  • "clean_dcache_range()"

(in this directory "cacheflush.h" header just contains declaration of mentioned functions.)
Also, my embedded device's SDK needs to call these functions to prepare DMA access.
Note that Kernel versions higher than 4.5 provide declaration of these functions.

Now i have some questions:

  1. I can use and copy functions which are implemented in newer kernels, in my old kernel and rebuild it, but modifying the kernel source doesn't make sense, right?
  2. Can you suggest some workaround to resolve it?
  3. How can i test that cache invalidated or flushed correctly? is there any way to read cache blocks in userspace?

Thanks,

1 Answers

Yes it looks safe to port these. Its no more insane than a SDK restricting your kernel version.

There's no easy way to test, certainly not from userspace. Relying on architected instructions like dcbf, dcbst etc to do right thing is a pretty good assumption. Alternately for testing look at instrumenting performance counters in the kernel around L1 cache misses.

Related