“C” programmatically clear L2 cache on Linux machines

落花浮王杯 提交于 2020-01-01 11:45:13

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3453995/c-programmatically-clear-l2-cache-on-linux-machines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!