Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"C" programmatically clear L2 cache on Linux machines

Tags:

c

linux

caching

What would be the programmatic steps written in "C" associated with clearing the L2 cache on a Linux OS machine?

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

like image 347
Rob Schein Avatar asked Nov 06 '22 10:11

Rob Schein


1 Answers

The closest you can get in any remotely clean/portable way:

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

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

like image 176
R.. GitHub STOP HELPING ICE Avatar answered Nov 11 '22 04:11

R.. GitHub STOP HELPING ICE