ndk icon indicating copy to clipboard operation
ndk copied to clipboard

Simpleperf: the result of cpu freqency is wrong ?

Open magicse7en opened this issue 8 years ago • 4 comments

Execute simpleperf stat -a sleep 1 command and the result as below:

Performance counter statistics:

  91,821,403  cpu-cycles            # 0.089234 GHz                      (100%)
   54,545,727  instructions          # 1.683384 cycles per instruction   (100%)
   7,173,539  branch-instructions   # 6.971 M/sec                       (100%)
      639,383  branch-misses         # 8.913076% miss rate               (100%)

1030.213619(ms) task-clock # 100.118106% cpu usage (100%) 617 context-switches # 599.612 /sec (100%) 362 page-faults # 351.798 /sec (100%)

The 91,821,403 cpu-cycles # 0.089234 GHz (100%) shows cpu frequency is 0.089234GHz, in fact, the cpu real frequency is 1.7GHz. Does simpleperf miscalculate ?

magicse7en avatar Mar 05 '18 12:03 magicse7en

In my understanding, modern CPUs have several low power modes. CPUs enter low power modes when there isn't any thing to do. In some low power modes, cpu-cycles doesn't increase.

yabinc avatar Mar 05 '18 19:03 yabinc

I disabled DVFS, hotplug and keep all cpus on-line. I guess the simpleperf uses below formula to calculate cpu frequency: frequency = cycles / time ?

But I use linux-tool perf, the result is correct:

Performance counter stats for 'ls': 25.190308 task-clock (msec) # 0.939 CPUs utilized
0 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
331 page-faults # 0.013 M/sec
42514492 cycles # 1.688 GHz
stalled-cycles-frontend
stalled-cycles-backend
27491753 instructions # 0.65 insns per cycle
3803236 branches # 150.980 M/sec
272886 branch-misses # 7.18% of all branches 0.026814000 seconds time elapsed

magicse7en avatar Mar 06 '18 01:03 magicse7en

I see. linux-tools-perf uses freq = cycles / task_clock_count (or cpu_clock count). But simpleperf uses freq = cycles / (time stopping recording - time starting recording). The difference also happens when calculating context-switches per second, page-faults per second and others. Thanks for reporting this! I will fix it tomorrow.

yabinc avatar Mar 06 '18 02:03 yabinc

The fix https://android-review.googlesource.com/c/platform/system/extras/+/634646 has been merged.

yabinc avatar Mar 06 '18 22:03 yabinc