【发布时间】:2014-12-02 08:43:07
【问题描述】:
是否可以使用英特尔的 PMU 库来计算 C 程序中特定 sn-p 代码的缓存命中/未命中次数?计数似乎被系统上运行的其他应用程序污染了。
该库是否支持单独隔离对应于特定代码 sn-p 的缓存统计信息(即,不受系统上运行的其他应用程序的干扰)?
这是我一直在测试的代码的 sn-p
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++ performance caching intel