skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.

    1. perf stat sleep 1 can provide reliable data about the CPU frequency (nominal at least).

    In QEMU, it shows,

    t@ubuntu:~$ sudo /usr/lib/linux-tools/4.15.0-189-generic/perf stat sleep 1
    
     Performance counter stats for 'sleep 1':
    
             37.075376      task-clock (msec)         #    0.035 CPUs utilized
                     2      context-switches          #    0.054 K/sec
                     0      cpu-migrations            #    0.000 K/sec
                    52      page-faults               #    0.001 M/sec
            37,039,955      cycles                    #    0.999 GHz
       <not supported>      instructions
       <not supported>      branches
       <not supported>      branch-misses
    
           1.055087406 seconds time elapsed
    

    Line of 'cycles' shows the emulated CPU is running at 1GHz.

    In real ARMv8 hardware (nominal frequency is 1GHz), it shows,

    :~# perf stat sleep 1
    
     Performance counter stats for 'sleep 1':
    
                  1.93 msec task-clock                #    0.002 CPUs utilized
                     2      context-switches          #    0.001 M/sec
                     0      cpu-migrations            #    0.000 K/sec
                    44      page-faults               #    0.023 M/sec
               1897778      cycles                    #    0.982 GHz
                779587      instructions              #    0.41  insn per cycle
                 94295      branches                  #   48.782 M/sec
                 12509      branch-misses             #   13.27% of all branches
    
           1.003847600 seconds time elapsed
    
           0.000000000 seconds user
           0.004177000 seconds sys
    

    The line of cycles shows it is running at 1GHz, which matches CPU's nominal frequency.

    1. Software can read pmccntr_el0 to calculate the CPU frequency, and the software needs to be designed to stress the CPU to 100% usage, to avoid CPU power management.

    Sleep testing result in QEMU emulator is.

    $ taskset -c 3 ./readpmc
    Got pmccntr: 0x35dcdf412, 0x410b77476, diff: 0xb2e98064 (3001647204)
    calculated CPU frequency: 1000549068
    

    It gets CPU frequency is 1GHz, matches QEMU's emulation.

    Sleeping testing result in real hardware (1GHz as nominal frequency).

    :~/temp# taskset -c 3 ./a.out
    Got pmccntr: 0xffffffff8311b937, 0xffffffff8357acf7, diff: 0x45f3c0 (4584384)
    calculated CPU frequency: 1528128
    

    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.

    :~/temp# taskset -c 3 ./b.out
    Inside handler function
    Got pmccntr: 0xffffffff8c6857c3, 0x3f39438b, diff: 0xb2d0ebc8 (3000036296)
    calculated CPU frequency: 1000012098
    

    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).


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search