Simpleperf: the result of cpu freqency is wrong ?
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 ?
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.
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
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.
The fix https://android-review.googlesource.com/c/platform/system/extras/+/634646 has been merged.