Tuesday 3 April 2018

Tips to check processor and cpu details on Linux

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.

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.

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, 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.
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 clflu

Reference:  1

No comments:

Post a Comment

Note: only a member of this blog may post a comment.