1

I know we can use wrmsr and rdmsr instruction to set the performance counter and read the general purpose performance counter register.

However, my question is:

Do we need to reset the general purpose performance counter register before we issue the wrmsr?

In other words, for the following code, do we need to reset the performance counter before the following code? If we have to, how can we reset it?

    mov $0x0001010E, %eax                # Write selector value to EAX
    xor %edx, %edx                       # Zero EDX
    mov $0x187, %ecx                     # Write logical register id to ECX (IA32_PERFEVTSEL1)
    wrmsr
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
Mike
  • 1,841
  • 2
  • 18
  • 34
  • You don't. You simple record the current value. Then sometime later you read it again and subtract the previous value. – Hans Passant Jan 29 '14 at 02:16
  • Thank you very much, @HansPassant! Yes, your method is a way to do it. But I'm wondering if I can reset it? If both ways work, what's their strength and weakness? – Mike Jan 29 '14 at 03:16
  • you can use the (user level) rdtsc instruction. it requires no setup, just return sequential values (as mentioned, read first and subtract from later value). wrmsr and rdmsr are priviledged. – Andreas H. Jan 29 '14 at 03:35
  • 2
    @AndreasH: `rdtsc` is useless if you want to measure (e.g) cache misses or branch mispredictions or unaligned reads or number of "non-bogus" uops retired on one logical CPU in a core but not the other, or... – Brendan Jan 29 '14 at 04:18
  • @MikeXu: Which CPU is it? Performance monitoring counters on "Ye Olde Pentium" are very different to Haswell.. – Brendan Jan 29 '14 at 04:20
  • @Brendan, my cpu is Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz It uses the SandyBridge Arch. – Mike Jan 29 '14 at 14:35

0 Answers0