使用英特尔的 PMU 库分析缓存命中/未命中次数
Using Intel's PMU library to profile the number of cache hits/misses
是否可以使用英特尔的PMU库来计算C程序中特定代码段的缓存命中/未命中次数?计数似乎被系统上运行的其他应用程序污染了。
库是否支持单独隔离与某个特定代码片段相对应的缓存统计信息(即,不受系统上运行的其他应用程序的干扰)?
这是我用测试的代码片段
SystemCounterState before = getSystemCounterState();
SystemCounterState after = getSystemCounterState();
cout << "===========================================================" << endl;
cout << "Instructions per Clock: " << getIPC(before, after) <<
"nL2 cache hits: " << getL2CacheHits(before, after) <<
"nL2 cache misses: " << getL2CacheMisses(before, after) <<
"nL2 cache hit ratio: " << getL2CacheHitRatio(before, after) <<
"nL3 cache hits: " << getL3CacheHits(before, after) <<
"nL3 cache misses: " << getL3CacheMisses(before, after) <<
"nL3 cache hit ratio: " << getL3CacheHitRatio(before, after) <<
"nWasted cycles caused by L3 misses: " << getCyclesLostDueL3CacheMisses(before, after) <<
"nBytes read from DRAM: " << getBytesReadFromMC(before, after) << endl;
cout << "===========================================================" << endl;
这些是我得到的统计数据(注意,尽管我不做任何计算,但缓存命中/未命中计数很高):
===========================================================
Instructions per Clock: 0.410805
L2 cache hits: 2677
L2 cache misses: 2658
L2 cache hit ratio: 0.501781
L3 cache hits: 2151
L3 cache misses: 507
L3 cache hit ratio: 0.809255
Wasted cycles caused by L3 misses: 0.0242752
Bytes read from DRAM: 514048
===========================================================
提前谢谢。
仅仅打印"根本不打印计算"实际上就是在进行计算。
您正在调用C++例程"cout",这将导致相当多的代码执行。如果你想看到这个,编译这个程序:
#include <iostream>
using namespace std;
int main()
{
int i;
i = 1;
cout << "Hello World" << endl;
i = 2;
}
使用gdb,在cout上设置一个断点,然后执行"stepi"命令。您将看到在执行"cout"时执行了多少指令。
所有这些执行访问内存的指令,包括指令本身和指令使用的数据,这可能导致相当多的缓存未命中。
您可能想尝试在不进行任何打印的情况下抓取计数器。
相关文章:
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 将gsl c++程序与"英特尔MKL"链接
- 使用英特尔 PIN 修改寄存器
- 使用英特尔内联函数将打包的 8 位整数乘以浮点数向量
- 如何使用英特尔 PIN 捕获阵列的所有负载?
- 英特尔 TBB 程序不会终止,可能会误用参考计数器
- 将"-01"替换为"-02" 英特尔编译器选项会导致 FPE 在较小的 for 循环行程计数中抛出
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 如何要求 macports 用英特尔编译器包装 openmpi?
- 实施英特尔实感和 SDL2 时出现问题
- OpenGL 片段着色器未在英特尔 HD 4000 显卡上编译
- 英特尔将指令存储在重叠的内存区域
- 如何指示 CMAKE 在 Visual Studio 中使用英特尔 MKL
- 使用英特尔内部函数 (AVX) 中的混合说明
- 英特尔 PIN:如何查看推测性指令?
- 获取英特尔 Kaby Lake 架构上最后一级高速缓存未命中计数的确切代码是什么?
- 在英特尔 x86 中读取缓存行与部分缓存行
- 英特尔 CPU 在处理大于其高速缓存行的类型时的预期行为是什么
- 使用英特尔的 PMU 库分析缓存命中/未命中次数