"C" programmatically flushes L2 cache on Linux machines

What will be the program steps written in "C" related to flushing the L2 cache on a Linux OS machine?

/ sys / devices / system / cpu / cpu0 / cache / index2 / size = 6144K x 8CPUs

+5
source share
2 answers

Closest you can get any remote / portable way:

char dummy[L2_CACHE_SIZE]; memset(dummy, 0, sizeof dummy); 

Depending on your processor, there may be privileged opcodes that can clear the cache, but I don't know anything about them or how you can access them. Probably, if they exist, you might still need kernel-level code to use them.

+2
source

You cannot access low-level memory from user space; you must implement your own device driver to access physical memory in Linux.

0
source

Source: https://habr.com/ru/post/893059/


All Articles