【问题标题】:Why is the L3 cache ignored by cachegrind, contradicting documentation?为什么 cachegrind 忽略了 L3 缓存,与文档相矛盾?
【发布时间】:2013-12-31 00:50:16
【问题描述】:

我想了解人们如何进行缓存优化,一位朋友建议我使用 cachegrind 作为实现这一目标的有用工具。

Valgrind 作为 CPU 模拟器,在使用 cachegrind 时假设有 2 级缓存,如 here 所述

Cachegrind 模拟您的程序如何与机器的缓存交互 层次结构和(可选)分支预测器。它模拟一台机器 具有独立的一级指令和数据缓存(I1 和 D1), 由统一的二级缓存 (L2) 支持。这完全符合 许多现代机器的配置。

下一段继续

但是,一些现代机器具有三级或四级缓存。为了 这些机器(在 Cachegrind 可以自动检测 缓存配置)Cachegrind模拟一级最后一级缓存。选择这个的原因是最后一级 缓存对运行时的影响最大,因为它屏蔽了对 main 的访问 记忆。

但是,当我尝试在我的简单矩阵-矩阵乘法代码上运行 valgrind 时, 我得到以下输出。

==6556== Cachegrind, a cache and branch-prediction profiler
==6556== Copyright (C) 2002-2010, and GNU GPL'd, by Nicholas Nethercote et al.
==6556== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==6556== Command: ./a.out
==6556== 
--6556-- warning: L3 cache detected but ignored
==6556== 
==6556== I   refs:      50,986,869
==6556== I1  misses:         1,146
==6556== L2i misses:         1,137
==6556== I1  miss rate:       0.00%
==6556== L2i miss rate:       0.00%
==6556== 
==6556== D   refs:      20,232,408  (18,893,241 rd   + 1,339,167 wr)
==6556== D1  misses:       150,194  (   144,869 rd   +     5,325 wr)
==6556== L2d misses:        10,451  (     5,506 rd   +     4,945 wr)
==6556== D1  miss rate:        0.7% (       0.7%     +       0.3%  )
==6556== L2d miss rate:        0.0% (       0.0%     +       0.3%  )
==6556== 
==6556== L2 refs:          151,340  (   146,015 rd   +     5,325 wr)
==6556== L2 misses:         11,588  (     6,643 rd   +     4,945 wr)
==6556== L2 miss rate:         0.0% (       0.0%     +       0.3%  )

根据文档,应该使用 L1 和 L3 缓存,但输出显示 L3 缓存被忽略。这是为什么?

cachegrind 是否也预先假定 L1 和最后一级缓存大小是多少,或者它是否使用当前运行的 CPU 的 L1 和最后一级缓存大小?

【问题讨论】:

    标签: performance caching cachegrind


    【解决方案1】:

    您运行在 cachegrind 似乎没有完全支持的英特尔 CPU 上。他们检查 cpuid 标志并根据针对不同处理器的大量案例语句确定支持。

    这是来自代码的非官方副本,但只是说明性的 - https://github.com/koriakin/valgrind/blob/master/cachegrind/cg-x86-amd64.c:

    /* Intel method is truly wretched.  We have to do an insane indexing into an
     * array of pre-defined configurations for various parts of the memory
     * hierarchy.
     * According to Intel Processor Identification, App Note 485.
     */
    static
    Int Intel_cache_info(Int level, cache_t* I1c, cache_t* D1c, cache_t* L2c)
    {
    ...
          case 0x22: case 0x23: case 0x25: case 0x29:
          case 0x46: case 0x47: case 0x4a: case 0x4b: case 0x4c: case 0x4d:
          case 0xe2: case 0xe3: case 0xe4: case 0xea: case 0xeb: case 0xec:
              VG_(dmsg)("warning: L3 cache detected but ignored\n");
              break;
    

    【讨论】:

    • 这是否意味着,最好不要对这个特定的 CPU 使用 cachegrind?
    • 好吧,我猜它不会那么准确或信息丰富,但总比没有好,不是吗?除非您有自己的 CPU 选择,但无论如何都是这样。
    猜你喜欢
    • 2018-07-22
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 2016-10-06
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    相关资源
    最近更新 更多