如何读取 i5、i7 CPU 上的性能计数器
现代 CPU 有相当多的性能计数器 - http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-system-programming-manual-325384。 html 如何读取它们? 我对缓存未命中和分支预测错误感兴趣。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来 PAPI 有非常干净的 API 并且工作得很好乌班图11.04。
安装后,以下应用程序将执行我想要的操作:
在 Intel Q6600 上对此进行了测试,它最多支持 4 个性能事件。您的处理器可能支持或多或少。
Looks like PAPI has very clean API and works just fine on Ubuntu 11.04.
Once it's installed, following app will do what I wanted:
Tested this on Intel Q6600, it supports up to 4 performance events. Your processor may support more or less.
perf 怎么样?
perf list hw cache
显示 33 个不同的事件,手册页显示如何使用原始性能计数器描述符。What about perf?
perf list hw cache
shows 33 different events and the man page shows how to use raw performance counter descriptors.性能计数器通过 RDPMC insn 读取。
编辑:要添加更多信息,读取性能计数器并不是很容易,如果我们要在这里描述它,则需要一页又一页,此外它还涉及对模型特定寄存器的写入,这需要特权指示。相反,我建议使用现成的分析器 - oprofile 或 Intel VTune,它们基于性能计数器构建。
Performance counters are read with the
RDPMC
insn.EDIT: To add a bit more info, reading performance counters is not very easy and it would take pages upon pages if we are to describe it here, besides it involves writes to Model Specific Registers, which require privileged instructions. I would instead advise to use ready profilers - oprofile or Intel VTune, which are built upon performance counters.
我认为有一个可用的库可以使用,称为perfmon2,http://perfmon2.sourceforge.net/,文档可在 http://www.hpl.hp.com/research/linux/perfmon/perfmon.php4 和 http://www.hpl.hp.com/techreports/2004/HPL-2004-200R1.html,我最近正在挖掘这个库,我会尽快发布示例代码我明白了~
I think there is a available library that can be used, called perfmon2, http://perfmon2.sourceforge.net/, and documentations are available at http://www.hpl.hp.com/research/linux/perfmon/perfmon.php4 and http://www.hpl.hp.com/techreports/2004/HPL-2004-200R1.html, I am recently digging this lib out, I would post example code as soon as I figure it out~