linux - 为什么 perf 不报告缓存未命中?

标签 linux caching optimization profiling perf

根据perf tutorials , perf stat 应该使用硬件计数器报告缓存未命中。但是,在我的系统(最新的 Arch Linux)上,它没有:

[joel@panda goog]$ perf stat ./hash

 Performance counter stats for './hash':

    869.447863 task-clock                #    0.997 CPUs utilized          
            92 context-switches          #    0.106 K/sec                  
             4 cpu-migrations            #    0.005 K/sec                  
         1,041 page-faults               #    0.001 M/sec                  
 2,628,646,296 cycles                    #    3.023 GHz                    
   819,269,992 stalled-cycles-frontend   #   31.17% frontend cycles idle   
   132,355,435 stalled-cycles-backend    #    5.04% backend  cycles idle   
 4,515,152,198 instructions              #    1.72  insns per cycle        
                                         #    0.18  stalled cycles per insn
 1,060,739,808 branches                  # 1220.015 M/sec                  
     2,653,157 branch-misses             #    0.25% of all branches        

   0.871766141 seconds time elapsed

我错过了什么?我已经搜索了手册页和网络,但没有发现任何明显的内容。

编辑:我的 CPU 是 Intel i5 2300K,如果这很重要的话。

最佳答案

在我的系统上,Intel Xeon X5570 @ 2.93 GHz我能够得到perf stat通过像这样明确地请求这些事件来报告缓存引用和未命中

perf stat -B -e cache-references,cache-misses,cycles,instructions,branches,faults,migrations sleep 5
Performance counter stats for 'sleep 5':

         10573 cache-references                                            
          1949 cache-misses              #   18.434 % of all cache refs    
       1077328 cycles                    #    0.000 GHz                    
        715248 instructions              #    0.66  insns per cycle        
        151188 branches                                                    
           154 faults                                                      
             0 migrations                                                  

   5.002776842 seconds time elapsed

默认事件集不包含缓存事件,匹配你的结果,不知道为什么

perf stat -B sleep 5

Performance counter stats for 'sleep 5':

      0.344308 task-clock                #    0.000 CPUs utilized          
             1 context-switches          #    0.003 M/sec                  
             0 CPU-migrations            #    0.000 M/sec                  
           154 page-faults               #    0.447 M/sec                  
        977183 cycles                    #    2.838 GHz                    
        586878 stalled-cycles-frontend   #   60.06% frontend cycles idle   
        430497 stalled-cycles-backend    #   44.05% backend  cycles idle   
        720815 instructions              #    0.74  insns per cycle        
                                         #    0.81  stalled cycles per insn
        152217 branches                  #  442.095 M/sec                  
          7646 branch-misses             #    5.02% of all branches        

   5.002763199 seconds time elapsed

关于linux - 为什么 perf 不报告缓存未命中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14674463/

相关文章:

c# - 如何缓存具有多个属性的对象

ios - 使用 NSCoding 缓存数据?

c - 符号扩展的必要性是什么?

android - 经常调用 ConnectivityManager.getActiveNetworkInfo() 是否很昂贵?

python - Pyserial 发送超过一个字节

Linux Bash,删除以空格分隔的文件

Linux 中的 Python shell

c - 对于非常大的整数值,我们如何将字符串转换为 int?

javascript - Cocoa - 防止在 WebKit 中缓存 Javascript - Safari Beta 4 错误?

php - 需要一些 PHP 逻辑来遍历一些 mysql 数据库结果