How to get an ARM CPU clock speed in Linux?

16

5

I have an ARM-based embedded machine based on S3C2416 board. According to the specifications I have available there should be a 533 MHz ARM9 (ARM926EJ-S according to /proc/cpuinfo), however the software running on it "feels" slow, compared to the same software on my Android phone with a 528MHz ARM CPU.

/proc/cpuinfo tells me that BogoMIPS is 266.24. I know that I should not trust BogoMIPS regarding performance ("Bogo" = bogus), however I would like to get a measurement on the actual CPU speed. On x86, I could use the rdtsc instruction to get the time stamp counter, wait a second (sleep(1)), read the counter again to get an approximation on the CPU speed, and according to my experience, this value was close enough to the real CPU speed.

How can I find the actual CPU speed of given ARM processor?

Update

I found this simple Pi calculator, which I compiled both for my Android phone and the ARM board. The results are as follows:

S3C2416

# cat /proc/cpuinfo
Processor   : ARM926EJ-S rev 5 (v5l)
BogoMIPS    : 266.24
Features    : swp half fastmult edsp java 
...
#./pi_arm 10000
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave
...
8.50 sec. (real time)

Android

# cat /proc/cpuinfo
Processor   : ARMv6-compatible processor rev 2 (v6l)
BogoMIPS    : 527.56
Features    : swp half thumb fastmult edsp java 
# ./pi_android 10000
Calculation of PI using FFT and AGM, ver. LG1.1.2-MP1.5.2a.memsave
...
5.95 sec. (real time)

So it seems that the ARM926EJ-S is slower than my Android phone, but not twice slower as I would expect by the BogoMIPS figures. I am still unsure about the clock speed of the ARM9 CPU.

MiKy

Posted 2012-03-29T12:07:58.433

Reputation: 275

I think it depends on the Linux distro. Linaro makes it easy, Debian does not. Also see How to retrieve CPU frequency when cpufreq is missing under 3.16.0-4-arm64? on the Debian-ARM mailing list.

– jww – 2016-06-06T02:05:25.483

http://elinux.org/S3C2416 says 400MHz? – ta.speot.is – 2012-03-29T12:21:16.413

Yes, that's the original, I should have got a newer model with 533MHz CPU, that is why I'm checking if I got what I should have... – MiKy – 2012-03-29T12:27:57.160

1266.24*2=532.48 So it seems like it's dead on. My 480MHz ARM CPU gets 239.2, 439.2*2=478.4. – David Schwartz – 2012-03-29T12:38:44.863

There are many things that can affect the speed of applications besides CPU speed, such as RAM speed, RAM bus width, and speed of storage/NAND. – LawrenceC – 2012-03-29T13:16:14.840

1I'm familiar with the S3C2416. It's an indeed an ARM9/ARMv4 design, not a "Cortex" ARMv6 or v7 design. The ARM in your Android smartphone probably is a Cortex, e.g. Cortex A5 design. – MSalters – 2012-03-29T13:45:51.197

Noticing Android has thumb while your S3C2416 doesn't. This can also affect execution speed. – LawrenceC – 2012-03-29T16:25:19.153

Answers

4

AFAICT the clock of a S3C2416 looks just like that of a S3C2443, or similar processors of its family. The Linux source code for it suggests that there are a number of closely-related clocks.

Choice snippet:

    pll = get_mpll(mpllcon, xtal);
    clk_msysclk.clk.rate = pll;

    fclk = pll / get_fdiv(clkdiv0);
    hclk = s3c2443_prediv_getrate(&clk_prediv);
    hclk /= s3c2443_get_hdiv(clkdiv0);
    pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);

    s3c24xx_setup_clocks(fclk, hclk, pclk);

    printk("CPU: MPLL %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03l MHz\n",
           (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
           print_mhz(pll), print_mhz(fclk),
           print_mhz(hclk), print_mhz(pclk));

Update from OP

I have been looking for this output from dmesg, but I could not find anything - the dmesg output was littered with debug messages, and the beginning was missing. Clearly the kernel message buffer was too short to hold all messages until I connect by telnet. By putting /bin/dmesg > /tmp/dmesg.log early in the startup process, I was able to get this output, confirming what I wanted to know:

Linux version 2.6.21 (gcc version 4.2.2)
CPU: ARM926EJ-S revision 5 (ARMv5TEJ)
Machine: SMDK2416
...
CPU S3C2416 EVT3
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C2416: mpll on 534.000 MHz, cpu 534.000 MHz, mem 133.500 MHz, pclk 66.750 MHz

MSalters

Posted 2012-03-29T12:07:58.433

Reputation: 7 587

9

Try cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq.

On my android this reads 1113600, so this is in kHz.

ThatGraemeGuy

Posted 2012-03-29T12:07:58.433

Reputation: 3 088

1

I believe it's in KHz according to https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt

– Gabe – 2015-06-13T16:06:08.903

Part of the tree is missing from Debian 3.16.7-ckt25-2. cpufreq is missing under /sys/devices/system/cpu/cpu0/ (and other cpu's). Its an early ARMv8/Aarch64 Mustang board, but I'm not sure if its part of the problem. An ARMv8/Aarch64 HiKey running 3.18.0-linaro-hikey has the tree. – jww – 2016-06-06T00:27:37.047

Doesn't exist on a Raspberry Pi 3 B+ running 64-bit Debian too. Do you need a package to get it? – Jon Harrop – 2019-05-17T22:56:33.067

Unfortunately ls -l /sys/devices/system/cpu/cpu0/ is giving me zero results. It seems like the board does not support frequency scaling (or the kernel is too old). – MiKy – 2012-03-29T16:02:30.383

1

With Linux, if you have the hwinfo command, then (as root) issue:
hwinfo --cpu | grep Clock

Tom

Posted 2012-03-29T12:07:58.433

Reputation: 11

This is a SuSE tool and usually not available by default on other distributions. – Evi1M4chine – 2015-12-06T01:04:14.597

For Debian Jessie: *"Package hwinfo is not available, but is referred to by another package."* – jww – 2016-06-06T05:20:28.740

hwinfo is available in Debian: https://packages.debian.org/sid/admin/hwinfo

– David Lechner – 2018-05-25T16:48:50.650

grepping for Clock on a ARM926EJ-S CPU comes up empty though – David Lechner – 2018-05-25T16:51:00.410

Empty on a Raspberry Pi 3 B+ running 64-bit Debian too. – Jon Harrop – 2019-05-17T22:54:51.197

-1

dmidecode is a useful little tool that dumps what is currently in the DMI table into a format you can read. Doing a dmidecode | grep "Current Speed" (as root or with sudo) will print out the CPU speed that is currently being reported in the DMI.

qweet

Posted 2012-03-29T12:07:58.433

Reputation: 3 652

1For Debian Jessie: *"Package dmidecode is not available, but is referred to by another package."* As far as I know, ARM boards don't use a PC BIOS. – jww – 2016-06-06T05:21:15.213

That would be great, unfortunately I have a limited environment, i.e. no Python. – MiKy – 2012-03-29T12:35:30.927

@MiKy: If I see this correctly, dmidecode is C, native. – Bobby – 2012-03-29T12:39:54.440

Oh, right, I was looking at the Debian dmidecode armel repository, and it listed Python as a dependency. I'll try to compile it and see how it goes. – MiKy – 2012-03-29T12:42:07.783

4Isn't DMI a BIOS thing, which doesn't exist on ARM platforms? – LawrenceC – 2012-03-29T13:12:25.013

3The "D" stands for desktop, so chances are that this embedded system won't have it. – MSalters – 2012-03-29T13:48:21.337