如何清除CPU L1和L2缓存 [英] How to clear CPU L1 and L2 cache

查看:158
本文介绍了如何清除CPU L1和L2缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在至强服务器上运行基准测试,并且重复执行2-3次。我想在重复运行时擦除L1和L2中的缓存内容。您能建议使用任何方法吗?

I'm running a benchmark on xeon server , and i repeat the executions 2-3 times. I'd like to erase the cache contents in L1 and L2 while repeating the runs. Can you suggest any methods for doing so ?

推荐答案

尝试通过CPU(即不是通过DMA)读取重复的大数据。
像:

Try to read repetitly large data via CPU (i.e. not by DMA). Like:

 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上,例如,使用以下命令进行删除:

However depend on server a bigger problem may be a disk cache (in memory) then L1/L2 cache. On Linux (for example) drop using:

 sync
 echo 3 > /proc/sys/vm/drop_caches

编辑:生成不执行任何操作的大型程序:

It is trivial to generate large program which do nothing:

#!/usr/bin/ruby
puts "main:"
200000.times { puts "  nop" }
puts "  xor rax, rax"
puts "  ret"

以不同的名称运行几次(代码生成而不是脚本)应该可以完成工作

Running a few times under different names (code produced not the script) should do the work

这篇关于如何清除CPU L1和L2缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆