Processor/Cpu details
The details about the processor that we shall be talking about include, number of cores, availability of hyper threading, architecture, cache size etc.
To find these details about the cpu on your system can be a bit difficult because the way different commands check them.
The commands that we are going to use include lscpu, /proc/cpuinfo and lstopo (hwloc).
These commands show detailed information about the cpu cores/processing units.
The examples following next would explain how to interpret the output of these commands.
1. Vendor and model of the processor
To find the vendor and model name of the processor, search the /proc/cpuinfo file with the grep command.
$ cat /proc/cpuinfo | grep vendor | uniq vendor_id : GenuineIntel
Its an Intel processor. Next find the model name that can be used to lookup the exact specifications online on Intel's website.
$ cat /proc/cpuinfo | grep 'model name' | uniq model name : Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz
Its a "Core 2 Quad Q8400" processor.
2. Architecture
The lscpu commands reports the architecture.
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian .....
The architecture is x86_64 which is 64 bit.
3. Frequency
The frequency/speed of the processor is reported by both lscpu and /proc/cpuinfo.
$ lscpu | grep -i mhz CPU MHz: 1998.000
$ cat /proc/cpuinfo | grep -i mhz | uniq cpu MHz : 1998.000
The frequency reported might be lower than the actual frequency specified for the processor because most modern processors operate at lower frequencies to save power. Under load condition they would switch to higher frequency.
The change of frequency can be seen by monitoring the output of /proc/cpuinfo using watch.
$ watch -n 0.1 "cat /proc/cpuinfo | grep -i mhz"
Run the above command in a terminal and while it is running, launch some cpu intensive task in parallel and the frequency would increase.
Every 0.1s: cat /proc/cpuinfo | grep -i mhz Sun Jun 29 15:28:38 2014 cpu MHz : 2664.000 cpu MHz : 2664.000 cpu MHz : 2664.000 cpu MHz : 2664.000
4. Number of cores
Each core on the processor is an actual independant cpu or processing unit. Multiple cores enable the processor to execute multiple program instructions in parallel, thereby increasing the processing speed.
The lscpu command indicates the "cores per socket".
$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 1
So in this case the number of cores on the processor is 4.
The /proc/cpuinfo file also indicates the number of cores, but it can be bit tricky and confusing.
Simply counting the number of processors may give wrong numbers.
$ cat /proc/cpuinfo | grep 'processor'
In case of hyper threaded processors, the number of processors that the operating system sees is twice the number of cores.
However /proc/cpuinfo has a field named 'core id' which is a unique id for each core in a single processor. Counting the core id would give a clear indication of the number of actual cores on the processor
$ cat /proc/cpuinfo | grep -i 'core id' core id : 0 core id : 2 core id : 1 core id : 3
Multiple processors
Rare, but in case you are on a system that has multiple physical processors (yes, it means 2 or more processors fitted on the motherboard), then the results of /proc/cpuinfo would be different. In case of multiple processors, the 'physical id' would indicate multiple values.
$ cat /proc/cpuinfo | grep -i 'physical id' | uniq physical id : 0
If there are more than 1 physical ids, then there are multiple physical processors on the system. And you have to count the cores on each processor separately.
5. Hyper threading
Hyper threading is an Intel technology that allows individual cores to perform like 2 logical processing units. This, in a way increases the processing power of each core in a limited manner.
To check whether the processor has hyper-threading, 2 different values have to be compared. First is the number of actual cores, and second is the number of logical processing units.
If the number of cores is equal to the number of processing units as seen by the OS, then NO hyper threading. Otherwise if the number of processing units is greater/twice the number of cores, then YES hyper threading.
number of processing units = number of cores [ no hyper threading ] number of processing units = number of cores * 2 [ hyper threading present ]
Take this example of a Core 2 Quad Q8400 processor
Number of processors as shown by /proc/cpuinfo is 4
$ cat /proc/cpuinfo | grep processor processor : 0 processor : 1 processor : 2 processor : 3
Number of 'cpu cores' = 4 as well as 'siblings' = 4 and unique 'core id' = 4
processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 23 model name : Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz stepping : 10 microcode : 0xa07 cpu MHz : 1998.000 cache size : 2048 KB physical id : 0 siblings : 4 core id : 0 cpu cores : 4 apicid : 0 .....
Therefore total number of processing units = number of actual cores. So there is no hyper threading on this processor, and the same can be confirmed from the specs of the processor on Intel's website.
Hyper-threaded processor
Incase of hyper threading being present the output of /proc/cpuinfo or lscpu would be different.
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit CPU(s): 8 Thread(s) per core: 2 Core(s) per socket: 4 CPU socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 30 Stepping: 5 CPU MHz: 1199.000 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 8192K
Note the "Thread(s) per core: 2" which indicate that there are 2 threads per core, with a total of 4 cores. So the number of processing units seen by the OS is 8.
Now lets take a look at the output of /proc/cpuinfo.
$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz stepping : 3 microcode : 0x12 cpu MHz : 800.000 cache size : 6144 KB physical id : 0 siblings : 8 core id : 0 cpu cores : 4 apicid : 0
The 'cpu cores' = 4 and siblings = 8 which means there are 4 cores and 2 hyperthreads per core. Number of processors as shown by /proc/cpuinfo would also be 8.
$ cat /proc/cpuinfo | grep processor processor : 0 processor : 1 processor : 2 processor : 3 processor : 4 processor : 5 processor : 6 processor : 7
The HTT flag in dmidecode output and ht flag in /proc/cpuinfo flags might not correctly report hyper threading.
For the Core2Quad Q8400 processor, both dmidecode and /proc/cpuinfo show the hyperthreading flag enabled, inspite of hyper threading not being available on the processor.
$ sudo dmidecode -t processor | grep HTT HTT (Multi-threading) $ cat /proc/cpuinfo | grep ht | uniq flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm .....
Hwloc / lstopo
Hwloc (Portable hardware locality) is a small utility that reports the structure of the processor in a neat visual diagram. The diagram shows the number of cores, hyperthreads and cache size. A single diagram tells it all.
$ sudo apt-get install hwloc $ hwloc
The above diagram clearly shows -
Total L2 Cache - 4096 KB - 4MB
Total Cores - 4
Processing unit per core - 1
Hyper-threaded processor
For a hyperthreaded processor, the hwloc output diagram could look like this
The diagram indicates
Total L3 Cache - 8MB
Total Cores - 4
Processing units per Core - 2 [hyper threading]
Conclusion
To learn more about commands for checking CPU information on Linux check this post:
9 Commands to Check CPU Information on Linux
If you have any feedback or questions let us know in the comments below.
If you are looking for physical CPU count /proc/cpuinfo is confusing . It gives the number of threads .
To get physical CPU count .
[root@xxx~]# dmidecode -t 4 | egrep -i “Designation|Intel|core|thread”
Socket Designation: CPU1
Manufacturer: Intel
HTT (Multi-threading)
Version: Intel(R) Xeon(R) CPU L5640 @ 2.27GHz
Core Count: 6
Core Enabled: 6
Thread Count: 12
Socket Designation: CPU2
Manufacturer: Intel
HTT (Multi-threading)
Version: Intel(R) Xeon(R) CPU L5640 @ 2.27GHz
Core Count: 6
Core Enabled: 6
Thread Count: 12
The same server if i give
[root@xxxx ~]# cat /proc/cpuinfo | egrep processor | wc -l
24
So its means i have a 24 threads system , so dont rely on cpuinfo .
-R
Useless use of cat.
cat /proc/cpuinfo | grep processor
Better do:
grep processor /proc/cpuinfo
In the last example you have hwloc as the command to run. You meant to have $ lstopo.
$ sudo apt-get install hwloc
$ hwloc
or lstopo-ls
or hwloc-ls
I was struggling to get the graphical hardware utility on Kubuntu 14.04 to run until I read the comments:
No Response with hwloc as per the instructions, however lstopo and hwloc-ls worked fine. Thanks for sharing the information.
Rich
Note a user space util designed to be used from shell scripts etc. available on most systems through GNU coreutils is nproc. This returns the number of _available_ processors in a cross platform way. For example:
make -j $(nproc)
nproc is not so cross-platform as it is GNU-specific though. It’s still better than grepping /proc/cpuinfo, but if you really want something that works everywhere except maybe on windows (actually… oh yes, Cygwin has it too), use getconf.
cf. https://gist.github.com/jj1bdx/5746298
or just a oneliner:
cpus=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
(*_CONF will count all cpus while *_ONLN counts only online CPUs)
No bogomips? it is the first thing I do read to compare CPUs
Very nice and usefull commands collection!!
Pretty awesome!!
Cheers to you!