我正在xeon服务器上运行一个基准测试,并重复执行2-3次。我想在重复运行时删除L1和L2中的缓存内容。你能建议什么方法吗?
发布于 2010-08-09 19:26:08
尝试通过CPU (即不是通过DMA)读取重复的大数据。比如:
int main() {
const int size = 20*1024*1024; // Allocate 20M. Set much larger then L2
char *c = (char *)malloc(size);
for (int i = 0; i < 0xffff; i++)
for (int j = 0; j < size; j++)
c[j] = i*j;
}然而,依赖于服务器,一个更大的问题可能是磁盘缓存(内存中),然后是L1/L2缓存。在Linux上(例如),可以使用:
sync
echo 3 > /proc/sys/vm/drop_caches编辑:生成什么都不做的大型程序是很简单的:
#!/usr/bin/ruby
puts "main:"
200000.times { puts " nop" }
puts " xor rax, rax"
puts " ret"在不同的名称下运行几次(不是脚本生成的代码)应该可以完成这项工作。
https://stackoverflow.com/questions/3446138
复制相似问题