The Central Processing Unit (CPU) is the main hardware unit on a computer that is responsible for executing instructions from programs. Because of that, the speed of the CPU has a significant impact on the system’s performance.
In this article, we will learn how to get both the base and real-time CPU speed information on Linux. There are various command-line utilities and scripts we can use to get the speed of our CPU.
2. CPU Speed
CPU speed is defined as clock speed or clock rate. The clock rate indicates the processing frequency of a processor. In other words, it determines how many instructions a CPU can interpret per second. Since modern processors are very fast, the clock speed is usually defined as MHz or GHz.
In general, a CPU has a base speed which can be seen from the hardware specifications. However, in practice, the clock rate is most often higher than this rate, and it might vary from time to time.
3. Inspecting /proc/cpuinfo File
The first method we can use to find CPU speed is reading the virtual file /proc/cpuinfo. In this file, there is a lot of information regarding the CPU. Since we are looking only for the clock speed, we can directly filter the information we need:
$ cat /proc/cpuinfo | grep Hz model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz cpu MHz : 2904.004 model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz cpu MHz : 2904.004
As we mentioned previously, there are base and real-time clock speeds. In this case, these values are 2.70 GHz and 2904.004 MHz, respectively.
Furthermore, the reason there are two outputs is that this file displays CPU information for each processor core. So, it means that there are two cores in this particular system that gives the above output. In this example, the clock rates are the same for both cores.
If we want to monitor the speed for some period of time, we can use the watch command:
$ watch -n1 "grep Hz /proc/cpuinfo" Every 1.0s: grep Hz /proc/cpuinfo baeldung: Sun Jun 26 16:21:32 2022 model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz cpu MHz : 2904.004 model name : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz cpu MHz : 2904.004
The above output will refresh every second. We can change the period by modifying the value after the -n option.
4. Using lscpu
Again, since we are not interested in all of the information about the CPU, we filter the output so that we get the speed information we’re looking for:
$ lscpu | grep CPU CPU op-mode(s): 32-bit, 64-bit CPU(s): 2 On-line CPU(s) list: 0,1 CPU family: 6 Model name: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz CPU MHz: 2904.000 NUMA node0 CPU(s): 0,1 Vulnerability Mds: Mitigation; Clear CPU buffers; SMT Host state unknown Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT Host state unknown
As we can see from the output of lscpu, the results are 2.70 GHz and 2904.004 MHz, just like before.
5. Looking at the Kernel Message Buffer With dmesg
dmesg is a command that prints message buffers generated by the kernel and device drivers. Similarly to previous methods, we can get the CPU speed information by filtering out the output of dmesg:
$ dmesg | grep Hz [ 0.000016] tsc: Detected 2904.004 MHz processor [ 0.238892] smpboot: CPU0: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz (family: 0x6, model: 0x8e, stepping: 0x9) ...
Here, we got the 2904.004 MHz clock rate, and we saw the CPU with a 2.70 GHz base frequency, like with the previous methods. Note that there may be some irrelevant outputs for the above command.
6. Parsing the SMBIOS Data With dmidecode
dmidecode is a tool that parses the System Management BIOS (SMBIOS) data in a human-readable format. SMBIOS provides data structures to get access to the information about the hardware components of a system, such as memory devices or processors, as well as the BIOS management.
$ sudo dmidecode -t processor | grep Hz Version: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz External Clock: 100 MHz Max Speed: 2900 MHz Current Speed: 2600 MHz
This time, the output is slightly different from others. Besides, we may want to keep in mind that dmidecode could sometimes give unreliable results because it extracts the data from SMBIOS tables instead of probing the actual hardware.
7. Utilizing the inxi Script
Another way to get CPU speed information is to use the inxi script. inxi can provide a variety of useful pieces of information from drivers to the kernel, but we are only interested in the CPU information. In order to use inxi, we need to install it with our package manager.
Let’s take a look at what types of information the script returns about the CPU:
$ sudo inxi -c CPU: Dual Core Intel Core i7-7500U (-MCP-) speed: 2904 MHz Kernel: 5.13.0-51-generic x86_64 Up: 22m Mem: 465.6/971.2 MiB (47.9%) Storage: 20.00 GiB (50.7% used) Procs: 201 Shell: bash 5.0.17 inxi: 3.0.38
Above, we used -c to retrieve data about the CPU. Correspondingly, we observe that the CPU speed is 2904 MHz.
8. Using the Hardware Level Information Tool hwinfo
hwinfo logs some useful information about general hardware in the system. We can install this manually too, by simply using our package manager.
After that, in a similar fashion to the other methods, we can use hwinfo to get the CPU speed:
$ hwinfo --cpu | grep Hz Model: 6.142.9 "Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz" Clock: 2904 MHz Model: 6.142.9 "Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz" Clock: 2904 MHz
As can be seen above, we got both the base and current clock speeds as 2.70 GHz and 2904 MHz like before.
9. Using i7z for Intel Processors
i7z is a basic utility that reports processor data, but only about Intel Core CPUs. After installing the package, we can see some real-time status information for every core:
$ sudo i7z Cpu speed from cpuinfo 2903.00Mhz cpuinfo might be wrong if cpufreq is enabled. To guess correctly try estimating via tsc Linux's inbuilt cpu_khz code emulated now True Frequency (without accounting Turbo) 2903 MHz CPU Multiplier 29x || Bus clock frequency (BCLK) 100.10 MHz Socket  - [physical cores=2, logical cores=2, max online cores ever=2] TURBO DISABLED on 2 Cores, Hyper Threading OFF Max Frequency without considering Turbo 2903.00 MHz (100.10 x ) Max TURBO Multiplier (if Enabled) with 1/2/3/4 Cores is 42x/42x/42x/42x Real Current Frequency 0.00 MHz [100.10 x 0.00] (Max of below) Core [core-id] :Actual Freq (Mult.) C0% Halt(C1)% C3 % C6 % Temp VCore Core 1 : inf (infx) 0 100 0 0 -1 1.9349 Core 2 : inf (infx) 0 100 0 0 -1 1.9349 ...
When we inspect the output, we see that the true frequency of the CPU is 2903 MHz. As we mentioned previously, the true frequency may vary in real-time. Hence this slight difference is not a problem.
In this article, we learned what a CPU is and what its speed means. We saw the difference between the base and true frequency and used several methods to retrieve the clock speed information.