硬件性能计数器的API用于Windows [英] Hardware performance counter APIs for Windows

查看:289
本文介绍了硬件性能计数器的API用于Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用硬件性能计数器,具体的x86 CPU获得高速缓存未命中或分支误prediction。性能计数器在先进的剖析像英特尔VTune大量使用。请不要在Windows操作系统上混淆性能计数器。

I'd like to use hardware performance counter, specifically x86 CPUs to obtain cache misses or branch mis-prediction. Performance counters are heavily used in advanced profilers like Intel VTune. Please don't be confused performance counters on Windows operating systems.

在为了使用C / C ++程序这些计数器,可以使用PAPI: HTTP://icl.cs.utk埃杜/ PAPI /

In order to use these counters in C/C++ program, one may use PAPI: http://icl.cs.utk.edu/papi/

这可以让你轻松使用性能计数器,但只有Linux。一旦PAPI支持的Windows,但不是现在。

This allows you to easily use performance counters, but on only Linux. PAPI once supported Windows, but not now.

是否有任何人谁最近尝试PAPI或其他API在Windows上使用硬件性能计数器?

Is there anyone who recently tried PAPI or other APIs to use hardware performance counters on Windows?

推荐答案

您可以使用的 RDPMC 指令或 __readpmc MSVC编译器的内部,这是同样的事情。

You can use RDPMC instruction or __readpmc MSVC compiler intrinsic, which is the same thing.

但是,Windows禁止用户模式应用程序通过设置CR4.PCE 0 presumably执行此指令,因为每个计数器的含义由MSR寄存器,这是仅在内核模式下访问确定这样做。换句话说,除非你是一个内核模式的模块(例如设备驱动程序),你会得到特权指令的陷阱,如果你试图执行这一指令。

However, Windows prohibits user-mode applications to execute this instruction by setting CR4.PCE to 0. Presumably, this is done because the meaning of each counter is determined by MSR registers, which are only accessible in kernel mode. In other words, unless you're a kernel-mode module (e.g. a device driver), you are going to get "privileged instruction" trap if you attempt to execute this instruction.

如果你正在写一个用户模式应用程序,你唯一的选择是(如@Christopher在评论中提到的)写一个内核模块这将执行这一指令对你(你会招致用户可>内核调用罚款)和您的计算机上启用测试签名让你的presumably自签名的司机可以加载。这意味着你不能轻易分发此应用,但会为内部调整工作。

If you're writing a user-mode application, your only option is (as @Christopher mentioned in comments) to write a kernel module which would execute this instruction for you (you'll incur user->kernel call penalty) and enable test signing on your machine so your presumably self-signed "driver" can be loaded. This means you can't easily distribute this app, but that'll work for in-house tuning.

这篇关于硬件性能计数器的API用于Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆