Linux processors and cores

How to Check Processor and CPU Details on Linux – Command Examples

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.

Читайте также:  Linux ntp проверить время

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

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 —

Читайте также:  Ubuntu linux headers deb

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

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.

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

10 Comments

  1. reli February 19, 2016 at 11:11 pm If you are looking for physical CPU count /proc/cpuinfo is confusing . It gives the number of threads . To get physical CPU count . [[email protected]~]# 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 [[email protected] ~]# cat /proc/cpuinfo | egrep processor | wc -l
    24 So its means i have a 24 threads system , so dont rely on cpuinfo . -R
  1. Richard Prior July 11, 2016 at 6:06 am 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
  1. mmu_man August 18, 2016 at 4:04 am 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)
Читайте также:  Цифровой медиаплеер на linux

Источник

How to Get the Number of Processors/Cores in Linux

It is a no-brainer that the various Linux operating system distributions that provide irreplaceable performance prowess in a development or production environment will lose their performance identity in the absence of processors/cores.

These processors/cores are hardware entities of a computer system responsible for computing how fast the Linux operating system and its hosted programs complete user/system assigned tasks.

The evolution/innovation of various computer hardware infrastructures has led to the production of modern CPUs whose processors/cores embrace features like hyper-threading and multiple cores.

Importance of Knowing the Number of Processors/Cores in Linux

When working under an open-source operating system distribution like Linux, performance is everything. You need both the hardware and software components of your computing system to be at their best.

Therefore, knowing the number of processors/cores on the machine that powers your Linux operating system helps gauge how best your OS can perform under specific/customizable computing conditions.

For instance, you might be able to understand why multiple cores/hyper-threading CPUs have a speed and performance advantage over single-Core CPUs without hyper-threading.

1. Find Linux CPU Processors/Cores Using /proc/cpuinfo File

Whether on a remote Linux server or desktop Linux system, this method will query the /proc/cpuinfo file for lines matching the keyword processor via grep command which passes the processor keyword to a wc (word count) function that sums it up for display.

$ cat /proc/cpuinfo | grep processor | wc -l 4 

A more detailed output of the above file will look like the following:

Check Linux CPU Info

2. Get Linux CPU Processors/Cores Using lscpu Command

To understand what lscpu command does, we first need to run it:

Check Linux CPU Architecture Information

The lscpu command also highlights the CPU’s Architecture, op-mode(s), address sizes, thread(s) per core, core(s) per socket, family, model name, etc.

3. Check Linux CPU Processors/Cores Using top Command

Key in the command (top) on your Linux system and hit [Enter] on your keyboard. You should get a detailed output on what is going on with your processors/cores.

Monitor Linux CPU Usage

4. List Linux CPU Processors/Cores Using nproc Command

This approach is straightforward and will only output the available CPUs on your Linux system.

$ nproc --all 4 

An alternative approach to execute this command is as follows:

$ echo "Threads/core: $(nproc --all)"

Find Linux CPU Cores

5. List Linux CPU Processors/Cores Using getconf Command

This command is straightforward and can be executed in the following manner:

$ getconf _NPROCESSORS_ONLN 4 

An alternative approach to executing this command is as follows:

$ echo "Number of CPU/cores online at $HOSTNAME: $(getconf _NPROCESSORS_ONLN)"

List Linux CPU Cores

6. Find Linux CPU Processors/Cores Using dmidecode Command

The dmidecodeis command is used to get the Linux system’s hardware related information such as Processor, RAM, BIOS detail, Memory, Serial numbers etc.

Check Linux Hardware Information

We can alternatively modify the execution of the above command to provide us with CPU details like version, core count, core enabled, and thread count.

$ sudo dmidecode -t 4 | egrep -i 'core (count|enabled)|thread count|Version'

Get Linux Hardware Information

The above discussed inbuilt Linux commands cover everything there is to know about the number of processors/cores in your Linux system and much more.

Источник

Оцените статью
Adblock
detector