0

I use perf_event_open syscall to capture the PMU data,in my code,I print the number of PERF_COUNT_HW_CPU_CYCLES per second. But it's irregular, (i use cpufreq to set the frequence of CPU, and guess the number of PERF_COUNT_HW_CPU_CYCLES will be a constant, but this is not the truth)

(left line is cpu_cycles, right line is cpu_clock) idle: idle

stress -c 4: stress_cpu

what will change the number of PERF_COUNT_HW_CPU_CYCLES ?

O. Jones
  • 92,698
  • 17
  • 108
  • 152
  • Even with active CPU frequency fixed, that doesn't stop CPU cores from doing into power-save sleep states where the clock doesn't tick at all. If you just want a wall-clock-equivalent count that ticks even when cores are asleep, use `rdtsc` to get reference cycles (which tick even when the core clock is halted) instead of PMU events at all. (The `ref_tsc` pmu event does halt with the core clock, though: [Lost Cycles on Intel? An inconsistency between rdtsc and CPU\_CLK\_UNHALTED.REF\_TSC](https://stackoverflow.com/q/45472147)) – Peter Cordes Aug 15 '21 at 14:17

0 Answers0