Hardware performance counter APIs for Windows

后端 未结 2 1484
小蘑菇
小蘑菇 2020-12-10 05:14

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 profi

相关标签:
2条回答
  • 2020-12-10 06:03

    What about this HCP Reference? Does it not provide what you want?

    0 讨论(0)
  • 2020-12-10 06:13

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题