I am running some basic testing in Ubuntu for ARMv8 (Linux-aarch64) with QEMU emulator.
I want to get current CPU’s frequency (nominal frequency is preferred), but from the output of lscpu or cat /proc/cpuinfo, there is NO CPU frequency info.
The answers to a similar question in stackexchange can NOT help me much.
The output of perf stat sleep 1
is as follows,
Performance counter stats for 'sleep 1':
36.845824 task-clock (msec) # 0.034 CPUs utilized
1 context-switches # 0.027 K/sec
0 cpu-migrations # 0.000 K/sec
49 page-faults # 0.001 M/sec
36,759,401 cycles # 0.998 GHz
<not supported> instructions
<not supported> branches
<not supported> branch-misses
1.068524527 seconds time elapsed
May I say the CPU is 1GHz?
The output of cpupower
shows nothing about CPU frequency,
t@ubuntu:~/test/kermod$ sudo cpupower monitor
No HW Cstate monitors found
t@ubuntu:~/test/kermod$ sudo cpupower frequency-info
analyzing CPU 0:
no or unknown cpufreq driver is active on this CPU
CPUs which run at the same hardware frequency: Not Available
CPUs which need to have their frequency coordinated by software: Not Available
maximum transition latency: Cannot determine or is not supported.
Not Available
available cpufreq governors: Not Available
Unable to determine current policy
current CPU frequency: Unable to call hardware
current CPU frequency: Unable to call to kernel
t@ubuntu:~/test/kermod$ sudo cpupower info
System does not support Intel's performance bias setting
analyzing CPU 0:
The dmidecode -t processor
shows,
t@ubuntu:~/test/kermod$ sudo dmidecode -t processor
# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.
Handle 0x0400, DMI type 4, 42 bytes
Processor Information
Socket Designation: CPU 0
Type: Central Processor
Family: Other
Manufacturer: QEMU
ID: 00 00 00 00 00 00 00 00
Version: virt-4.2
Voltage: Unknown
External Clock: Unknown
Max Speed: 2000 MHz
Current Speed: 2000 MHz
Status: Populated, Enabled
Upgrade: Other
L1 Cache Handle: Not Provided
L2 Cache Handle: Not Provided
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 1
Core Enabled: 1
Thread Count: 1
Characteristics: None
It says the CPU is 2GHz, but I am not sure if that is correct.
Another way I can use is by sleeping for seconds and reading the difference of cycle counter in CPU to calculate the frequency. But I got the CPU frequency is about 1GHz.
Or is there any way in software or registers in hardware can tell me the ARM CPU’s frequency?
** Edit **
I asked my colleague to run perf stat sleep 1
in his real ARMv8 hardware, and we got,
Performance counter stats for 'sleep 1':
1.89 msec task-clock # 0.002 CPUs utilized
1 context-switches # 0.530 K/sec
0 cpu-migrations # 0.000 K/sec
43 page-faults # 0.023 M/sec
1859822 cycles # 0.985 GHz
758842 instructions # 0.41 insn per cycle
91818 branches # 48.632 M/sec
12077 branch-misses # 13.15% of all branches
1.003838600 seconds time elapsed
0.004158000 seconds user
0.000000000 seconds sys
His ARMv8 is running at 1GHz which matches the output of perf stat
.
Compared to that in QEMU emulation, the emulated CPU should be also running at 1GHz, am I correct?
2
Answers
Firstly, the question is to get the ARMv8 CPU core frequency (nominal or maximum). With all the discussion here and my testing in QEMU emulation and real ARMv8 hardware, there are 2 typical ways to get the CPU core frequency.
perf stat sleep 1
can provide reliable data about the CPU frequency (nominal at least).In QEMU, it shows,
Line of 'cycles' shows the emulated CPU is running at 1GHz.
In real ARMv8 hardware (nominal frequency is 1GHz), it shows,
The line of
cycles
shows it is running at 1GHz, which matches CPU's nominal frequency.Sleep testing result in QEMU emulator is.
It gets CPU frequency is 1GHz, matches QEMU's emulation.
Sleeping testing result in real hardware (1GHz as nominal frequency).
It shows 1.5MHz, which does NOT matches the nomimal frequency of the real hardware.
By changing the code from sleeping 3 seconds to busy looping 3 seconds, the result shows.
It shows CPU is running at 1GHz, matching CPU's real nominal hardware frequency.
The conclusion is software can calculate CPU's nominal frequency in ARMv8 as what can be done in X86 (through tsc).
Have you looked up any tools to assist in this?
Cpupower has an ARM release cpupower 5.19-1. This should give you the information that you want.
cpupower monitor
should display current frequency. Depending on what cpu you have, you will need to verify the core cluster type.As a note, the frequency an ARM cpu has is not always comparable to an x86 cpu frequency. The way that computations are handled are very different.
** Edit
So CPU frequency is measured in Hertz, which is cycles per second. According to your
perf stat sleep 1
the Emulated ARM cpu had 36,759,401 cycles in that one second. That would equate to 36.75Mhz, the task-clock result reflects this.