"C"表示以编程方式清除Linux机器上的L2缓存

问题描述:

用"C"编写的与清除Linux OS计算机上的L2缓存相关的编程步骤是什么?

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 8CPU

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

您可以通过任何远程清洁/便携式方式获得的最接近的东西:

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

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

取决于您的CPU,可能会有特权操作码可以清除缓存,但是我对它们一无所知,也不知道如何访问它们.如果它们存在,您可能仍需要内核级代码才能使用它们.

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.