1

I'm trying to read the MPERF and APERF MSRs. However, when I do so, the machine reboots, probably because of a GP exception.

Here is the code I use:

; Read MPERF register
mov ecx, 0xe7
rdmsr

The code breaks on rdmsr. I have an Intel Haswell processor. I'm running in long mode.

I'm pretty sure I'm running in Ring 0, as I'm running my own operating system. Moreover, if I do:

; Read PAT register
mov ecx, 0x277
rdmsr

it works without exception.

What are the other conditions to read this specific register (MPERF) ?

Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110

1 Answers1

2

I guess in your case the required MSR is fused out or not supported by design , CPUID can ratify it. As alternative for computing the core frequency, please refer to Finding out the CPU clock frequency (per core, per processor), in the answer there there is a recipe which does't rely on MPERF MSR register

Community
  • 1
  • 1
Shmil The Cat
  • 4,548
  • 2
  • 28
  • 37
  • I didn't know about the IOPL. But, I'm already using IN/OUT instructions with the 8042 controller, so I'm thing I'm really in Ring 0. – Baptiste Wicht Oct 16 '13 at 06:06
  • @Baptiste Wicht - cool your own OS :) , I like it so in this case *maybe* this register is fused out, one need to check its enabled via reading of CPUID I guess – Shmil The Cat Oct 16 '13 at 06:56
  • :) I checked with CPUID and indeed the hardware coordination is disabled so I cannot get APERF/MPERF. I wanted these to compute the frequency (max * (aperf/mperf)). Is there any other to compute the current frequency ? – Baptiste Wicht Oct 16 '13 at 07:21
  • Please take a look at http://stackoverflow.com/questions/8351944/finding-out-the-cpu-clock-frequency-per-core-per-processor especially the last comment in the last post. Please also consider accepting my answer since my first comment shows why one can't read from the MPERF MSR – Shmil The Cat Oct 16 '13 at 12:39
  • @BaptisteWicht: This answer is wrong! You shouldn't accept it. If the answerer (Shmil The Cat) wants credit, he should write a new answer and not expect me to read through the comments to find what might be the right answer. – Nathan Fellman Dec 02 '13 at 10:51
  • @ShmilTheCat: I downvoted this answer, and I recommend you delete it. I'll happily upvote an answer that is correct, as is reflected in your comment. – Nathan Fellman Dec 02 '13 at 10:53
  • @NathanFellman Thx for your feedback, I've re-edit the original answer in order to reflect all the info within the answer body and not scatter it along the comments. – Shmil The Cat Mar 20 '14 at 19:12