2

I used the command perf record -a to measure the performance counters on my system and perf script to obtain the results, which look like this

[000] 109528.087598: 1 cycles [000] 109528.100038: 5072 cycles [000] 109528.120034: 4878 cycles [000] 109528.144032: 4514 cycles

Let's say I am running this on a 3.3GHz CPU. From the formula CPU freq = number of cycles / time we get that in a microsecond we have 3.3 * 10^3 cycles.

My question is why does it take on average 3.95 microseconds to measure one cycle, when from the formula it should clearly take less?

AN00
  • 325
  • 4
  • 13
  • My first intuitive thought was that this situation was caused by the CPU doing other operations before it starts executing another function (therefore using cycles), but I am not sure if this is the real reason. – AN00 Aug 03 '16 at 22:30
  • `Perf record` does the sampling - which means that perf will generate around 1000 - 4000 interrupts per second, and to get them it will setup performance counter to some amount of cycles. Perf record (or perf report / perf script) may also hide samples hit idle processes. To get number of cpu clock cycles, use `perf stat` tool which will use counting mode of PMU. – osgx May 30 '17 at 04:15

1 Answers1

1

perf record does the sampling - which means that perf will generate around 1000 - 4000 interrupts per second, and to get them it will setup performance counter to some amount of cycles (probably different between interrupts). It only records to perf.data when the interrupt was received and what was instruction address at the moment. perf report will report in units of "sample", not in exact ticks.

Perf record (or perf report / perf script) may also hide samples hit idle processes.

To get number of cycles, use perf stat / perf stat -a tool which will use counting mode of PMU. This mode will also do frequency calculation for you and print average effective frequency of CPU.

osgx
  • 90,338
  • 53
  • 357
  • 513