“C” programmatically clear L2 cache on Linux machi

2020-07-13 07:51发布

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

标签: c linux caching
2条回答
萌系小妹纸
2楼-- · 2020-07-13 08:40

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.

查看更多
3楼-- · 2020-07-13 08:49

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

查看更多
登录 后发表回答