1

In a benchmarking harness, I'm using a IA32_APERF/IA32_MPERF ratio to decide if the CPU clocked down during benchmarking. I sample the registers twice, once before the benchmark, and once after, then take a delta and compute a ratio. The registers are read in the same order both times.

Since turbo mode is disabled on the machine, in theory it shouldn't be possible to get a ratio of > 1. That's true for most cases, but one benchmark is the "empty benchmark". It does nothing, so it's runtime is close to 0 seconds. We are talking in the order of 10^{-6} seconds.

In this case, sometimes the ratio goes over 1. In an extreme case to >3. E.g. aperf_delta = 62049, mperf_delta = 17948, giving a ratio of around 3.46.

I know that to get an accurate ratio, the sample rate needs to be much (much) longer, but even so, the above result suggests that the IA32_APERF counter incremented faster than the IA32_MPERF. Since turbo mode is off, I don't think that should happen.

Should this be possible? Is there something I don't know about the accuracy of these two registers? As I say, it only seems to happen in this degenerate "empty benchmark" case.

Thanks

Edd Barrett
  • 3,425
  • 2
  • 29
  • 48
  • 10us is still ~3000 cycles on a 3GHz CPU. Out of order execution doesn't explain a huge delay in one or the other, only about 200 instructions. – Peter Cordes Oct 31 '16 at 14:50
  • total guess, never heard of these MSRs until just now [but did find this which explains them](http://stackoverflow.com/questions/65095/assembly-cpu-frequency-measuring-algorithm): A timer interrupt between the first pair or second pair of measurements could be part of one delta but not the other. This can happen in either direction. Do you also sometimes see ratios that are unusually small, about as often as you see ones that are over 1? – Peter Cordes Oct 31 '16 at 14:53
  • That sounds plausible. – Edd Barrett Oct 31 '16 at 16:34
  • We do see some which are about 0.8, but they are indistinguishable from the CPU clocking down. – Edd Barrett Oct 31 '16 at 16:34

0 Answers0