www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Accessing x86 Performance Counters

reply "Maxime Chevalier-Boisvert" <maximechevalierb gmail.com> writes:
I was wondering if anyone has written D code to access the x86 
performance counters, to get information such as the number of 
cache misses and cycle count.
May 12 2015
next sibling parent reply "Benjamin Thaut" <code benjamin-thaut.de> writes:
On Wednesday, 13 May 2015 at 03:38:33 UTC, Maxime 
Chevalier-Boisvert wrote:
 I was wondering if anyone has written D code to access the x86 
 performance counters, to get information such as the number of 
 cache misses and cycle count.
I considered doing that at one point. So I looked for resources on the topic and it turns out that you need a kernel mode executable to be able to read the performance counters. Luckly there is a open source driver for windows which gives you some API to access the counters from user mode executables. Unfortunately you need to either switch your windows into a "unsafe mode" to allow for loading unsigned drivers or you need to somehow get a certificate to sign the driver (these are quite expensive). At that point I stopped looking into this, because both of these options weren't viable for my use case. Once I find some time I could dig up the resources I found if you are interested.
May 12 2015
parent reply "Kagamin" <spam here.lot> writes:
There was no word about windows, but process explorer shows page 
faults and cycles per process from unprivileged account, so I 
guess, this information is available through some API. Not sure 
is such system-wide statistics is available too.
May 13 2015
parent reply "Benjamin Thaut" <code benjamin-thaut.de> writes:
On Wednesday, 13 May 2015 at 08:53:10 UTC, Kagamin wrote:
 There was no word about windows, but process explorer shows 
 page faults and cycles per process from unprivileged account, 
 so I guess, this information is available through some API. Not 
 sure is such system-wide statistics is available too.
He is talking about the performance counters build into intel x86 processors (at least thats what I understood) thats something completely different from page faults and cycles per process. And as it is processor specific there is _no_ general api for it.
May 13 2015
parent "CraigDillabaugh" <craig.dillabaugh gmail.com> writes:
On Wednesday, 13 May 2015 at 09:26:40 UTC, Benjamin Thaut wrote:
 On Wednesday, 13 May 2015 at 08:53:10 UTC, Kagamin wrote:
 There was no word about windows, but process explorer shows 
 page faults and cycles per process from unprivileged account, 
 so I guess, this information is available through some API. 
 Not sure is such system-wide statistics is available too.
He is talking about the performance counters build into intel x86 processors (at least thats what I understood) thats something completely different from page faults and cycles per process. And as it is processor specific there is _no_ general api for it.
That should be "She is talking about ... " :o)
May 13 2015
prev sibling next sibling parent "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Wednesday, 13 May 2015 at 03:38:33 UTC, Maxime 
Chevalier-Boisvert wrote:
 I was wondering if anyone has written D code to access the x86 
 performance counters, to get information such as the number of 
 cache misses and cycle count.
For linux, you could try: https://www.google.no/search?q=perf_events
May 13 2015
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 13 May 2015 at 03:38:33 UTC, Maxime
Chevalier-Boisvert wrote:
 I was wondering if anyone has written D code to access the x86 
 performance counters, to get information such as the number of 
 cache misses and cycle count.
It would probably be easiest to write some bindings to PAPI-C or similar. As far as I know, DIY hardware performance monitoring isn't worth the effort.
May 13 2015
prev sibling parent "Dmitri Makarov" <dmakarv gmail.com> writes:
On Wednesday, 13 May 2015 at 03:38:33 UTC, Maxime 
Chevalier-Boisvert wrote:
 I was wondering if anyone has written D code to access the x86 
 performance counters, to get information such as the number of 
 cache misses and cycle count.
Intel made available the source of their performance counter monitor, which runs as a service and can be interacted with from a client program running in the user space. PAPI is a big API and it would be a lot of work to write bindings in D. Writing a D application that talks to PCM should be fairly straightforward. https://software.intel.com/en-us/articles/intel-performance-counter-monitor
May 13 2015