Never Ending Security

It starts all here

8 commands to check cpu information on Linux

CPU hardware information

The cpu information includes details about the processor, like the architecture, vendor name, model, number of cores, speed of each core etc. There are quite a few commands on linux to get those details about the cpu hardware, and here is a brief about some of the commands.

1. /proc/cpuinfo

The /proc/cpuinfo file contains details about individual cpu cores. Output its contents with less or cat.

$ less /proc/cpuinfo
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
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
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 pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority
bogomips        : 5303.14
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

Every processor or core is listed separately the various details about speed, cache size and model name are included in the description.

To count the number of processing units use grep with wc

$ cat /proc/cpuinfo | grep processor | wc -l
4
The number of processors shown by /proc/cpuinfo might not be the actual number of cores on the processor. For example a processor with 2 cores and hyperthreading would be reported as a processor with 4 cores.

To get the actual number of cores, check the core id for unique values

$ cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 2
core id         : 1
core id         : 3

So there are 4 different core ids. This indicates that there are 4 actual cores.

2. lscpu

lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a user-friendly format.

$ 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
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 23
Stepping:              10
CPU MHz:               1998.000
BogoMIPS:              5303.14
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              2048K
NUMA node0 CPU(s):     0-3

3. hardinfo

Hardinfo is a gtk based gui tool that generates reports about various hardware components. But it can also run from the command line only if there is no gui display available.

$ hardinfo | less

It would produce a large report about many hardware parts, by reading files from the /proc directory. The cpu information is towards the beginning of the report. The report can also be written to a text file.

Hardinfo also performs a few benchmark tests taking a few minutes before the report is displayed.

4. lshw

The lshw command can display limited information about the cpu. lshw by default shows information about various hardware parts, and the ‘-class’ option can be used to pickup information about a specific hardware part.

$ sudo lshw -class processor
  *-cpu                   
       description: CPU
       product: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
       vendor: Intel Corp.
       physical id: 0
       bus info: cpu@0
       version: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
       slot: LGA 775
       size: 1998MHz
       capacity: 4GHz
       width: 64 bits
       clock: 333MHz
       capabilities: fpu fpu_exception wp 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 pbe syscall nx x86-64 constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority cpufreq

The vendor, model and speed of the processor are being shown correctly. However it is not possible to deduce the number of cores on the processor from the above output.

5. nproc

The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.

$ nproc
4

6. dmidecode

The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags.

$ sudo dmidecode -t 4
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x0000, DMI type 4, 35 bytes
Processor Information
        Socket Designation: LGA 775
        Type: Central Processor
        Family: Pentium D
        Manufacturer: Intel(R) Corporation
        ID: 7A 06 01 00 FF FB EB BF
        Signature: Type 0, Family 6, Model 23, Stepping 10
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (FXSAVE and FXSTOR instructions supported)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Multi-threading)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
        Voltage: 1.6 V
        External Clock: 333 MHz
        Max Speed: 4000 MHz
        Current Speed: 2666 MHz
        Status: Populated, Enabled
        Upgrade: Socket LGA775
        L1 Cache Handle: 0x0003
        L2 Cache Handle: 0x0001
        L3 Cache Handle: Not Provided
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified

7. cpuid

The cpuid command fetches CPUID information about Intel and AMD x86 processors.

The program can be installed with apt on ubuntu

$ sudo apt-get install cpuid

And here is sample output

$ cpuid

.....

Vendor ID: "GenuineIntel"; CPUID level 13

Intel-specific functions:
Version 0001067a:
Type 0 - Original OEM
Family 6 - Pentium Pro
Model 7 - Pentium III/Pentium III Xeon - external L2 cache
Stepping 10
Reserved 4

Extended brand string: "Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz"
CLFLUSH instruction cache line size: 8
Initial APIC ID: 2
Hyper threading siblings: 4

Feature flags bfebfbff:
FPU    Floating Point Unit
VME    Virtual 8086 Mode Enhancements
DE     Debugging Extensions
PSE    Page Size Extensions
TSC    Time Stamp Counter
MSR    Model Specific Registers
PAE    Physical Address Extension
MCE    Machine Check Exception
CX8    COMPXCHG8B Instruction
APIC   On-chip Advanced Programmable Interrupt Controller present and enabled
SEP    Fast System Call
MTRR   Memory Type Range Registers
PGE    PTE Global Flag
MCA    Machine Check Architecture
CMOV   Conditional Move and Compare Instructions
FGPAT  Page Attribute Table
PSE-36 36-bit Page Size Extension
CLFSH  CFLUSH instruction
DS     Debug store
ACPI   Thermal Monitor and Clock Ctrl
MMX    MMX instruction set
FXSR   Fast FP/MMX Streaming SIMD Extensions save/restore
SSE    Streaming SIMD Extensions instruction set
SSE2   SSE2 extensions
SS     Self Snoop
HT     Hyper Threading
TM     Thermal monitor
31     reserved

.....

8. inxi

Inxi is a script that uses other programs to generate a well structured easy to read report about various hardware components on the system. Check out the full tutorial on inxi.

$ sudo apt-get install inxi

Print out cpu/processor related information

$ inxi -C
CPU:       Quad core Intel Core2 Quad CPU Q8400 (-MCP-) cache: 2048 KB flags: (lm nx sse sse2 sse3 sse4_1 ssse3 vmx) 
           Clock Speeds: 1: 1998.00 MHz 2: 1998.00 MHz 3: 1998.00 MHz 4: 1998.00 MHz


How to check processor and cpu details on Linux


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

linux hwloc command

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

hwloc hyper threading

The diagram indicates

Total L3 Cache – 8MB
Total Cores – 4
Processing units per Core – 2 [hyper threading]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s