Query CPU Performance Data,...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
keremg
Posts: 12
Joined: Fri Jan 11, 2008 5:31 am

Query CPU Performance Data,...

Post by keremg »

Hi,

well, since i never did soemthing like that before, i would like to know
how i can query performance data from the (intel) cpu internals. I would
like to do something similar like this application:

http://www.cpuid.com/perfmonitor.php

AFAIK it uses a kernel driver, so this seems to be only
available in kernel mode. Well, i know how to write a
Windows Kernel Driver and IOCTL Data from ring0 to
ring3 and vice versa, but what do i have to do, to get
those data in kernel mode? Amazing would be some example,
either in Assembler or if it can be done (i dont think so)
in C,...

Can i Query this Data from Usermode maybe, maybe by using
some undocumented calls? I am mainly using NT based OS like
Windows 2000 up to Windows 7 (32 bit), no need for 64 bit yet,..

Thanks in Advance,...

Regards

Kerem
stlw
Member
Member
Posts: 357
Joined: Fri Apr 04, 2008 6:43 am
Contact:

Re: Query CPU Performance Data,...

Post by stlw »

keremg wrote:Hi,

well, since i never did soemthing like that before, i would like to know
how i can query performance data from the (intel) cpu internals. I would
like to do something similar like this application:

http://www.cpuid.com/perfmonitor.php

AFAIK it uses a kernel driver, so this seems to be only
available in kernel mode. Well, i know how to write a
Windows Kernel Driver and IOCTL Data from ring0 to
ring3 and vice versa, but what do i have to do, to get
those data in kernel mode? Amazing would be some example,
either in Assembler or if it can be done (i dont think so)
in C,...

Can i Query this Data from Usermode maybe, maybe by using
some undocumented calls? I am mainly using NT based OS like
Windows 2000 up to Windows 7 (32 bit), no need for 64 bit yet,..

Thanks in Advance,...

Regards

Kerem
This is all about perfmons (hardware performance monitor counters).
Intel® 64 and IA-32 Architectures
Software Developer’s Manual
Volume 3B:System Programming Guide, Part 2
18.13 ARCHITECTURAL PERFORMANCE MONITORING

Stanislav
User avatar
keremg
Posts: 12
Joined: Fri Jan 11, 2008 5:31 am

Re: Query CPU Performance Data,...

Post by keremg »

stlw wrote: This is all about perfmons (hardware performance monitor counters).
Intel® 64 and IA-32 Architectures
Software Developer’s Manual
Volume 3B:System Programming Guide, Part 2
18.13 ARCHITECTURAL PERFORMANCE MONITORING

Stanislav
Hi Stanislav,

thanks for your reply. I must honestly confess that i really dont know
what and where i have to start. Can you provide some lines of assembly,
maybe a example to query the Number of memory data reads/writes as
it is provided on Pentium processor performance monitoring events
(manual Page 529/A.9 (Appendix A on Sheet)? This would be really great!

Thanks in advance,...


Regards

Kerem
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Query CPU Performance Data,...

Post by 01000101 »

This is the blind leading the blind, but I too have been looking into performance monitoring and may have some help that I can provide.

From what I understand (and I hope someone will correct/elaborate when necessary), you need to set one of the IA32_PERFEVTSELx MSRs with appropirate values (OS/USR mode, the desired bit mask [UnHalted instructions, etc...]. Then when one of the events happens (UnHalted instruction is executed) the cooresponding IA32_PMCx MSR will reflect the current count. It can also be set so that the APIC will generate an interrupt when the counter overflows. I'd assume the IA32_PMCx MSR must be manually read in order to query its counter state.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Query CPU Performance Data,...

Post by 01000101 »

I just tried some performance monitoring in BOCHS, QEMU, and VirtualBox-OSE and it seems that none of them properly support it. BOCHS doesn't support it at all, QEMU gives a valid version but supports no events (in CPUID.0x0A.EBX, or an > 0 count in EAX), and VirtualBox gives all valid results except for CPUID.0x0A.EBX being null (no supported counters). The counters all return 0 when read.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Query CPU Performance Data,...

Post by Brendan »

Hi,
01000101 wrote:I just tried some performance monitoring in BOCHS, QEMU, and VirtualBox-OSE and it seems that none of them properly support it. BOCHS doesn't support it at all, QEMU gives a valid version but supports no events (in CPUID.0x0A.EBX, or an > 0 count in EAX), and VirtualBox gives all valid results except for CPUID.0x0A.EBX being null (no supported counters). The counters all return 0 when read.
If an emulator tried to support performance monitoring, then it'd need to do a series of checks for every instruction emulated, and it would probably make the emulator about 50 times slower. Performance monitoring is also CPU specific, which makes it a lot of work to implement, and it's something that's rarely used (e.g. only used by specialized profiling tools). Basically it's not something I'd expect any emulator will ever support.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Query CPU Performance Data,...

Post by bewing »

Hey, I'm trying! I expect (hope for) my version of bochs to have one CPU model that supports it. It'll be really slow, as you say -- but if I put in all that memory-fetch-time modeling that you want, that model will be really super slow anyway.
User avatar
keremg
Posts: 12
Joined: Fri Jan 11, 2008 5:31 am

Re: Query CPU Performance Data,...

Post by keremg »

Hi,

does someone have some example code for me?


TIA

Regards

Kerem
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Query CPU Performance Data,...

Post by 01000101 »

keremg wrote: does someone have some example code for me?
stop looking for a free handout, and read the intel manuals. All the info about reading performance counters are there, you just need to look. Program the select MSR and read from the counter MSR, it's fairly simple.
Post Reply