linuxperformancecounterperfcpu-cycles

Understanding the Frequency printed by Linux Perf Stat


perf stat <command> prints several stats associated with <command>. Most of the stats are easily understandable. But what does it mean by the frequency associated with the cycle stat (which looks like as follows)?

5,205,202,243 cycles # 3.046 GHz


Solution

  • It's just cycles / task-clock.

    So it can be lower than you'd expect with perf stat --all-user or cycles:u that means cycles only counts in user-space (not interrupts or system calls), but task-clock is from the kernel's software accounting of how long the thread(s) of this process were scheduled onto CPU core(s) for.

    This means it's a weighted average of the actual CPU core clock on the core(s) your thread(s) were running on.

    (Related: what's the meaning of cycles annotation in perf stat but that answer suggests it should be close to your CPU's rated frequency or max turbo, which is incorrect for short processes which don't get the core ramped up to max. Or when only counting user-space cycles.)