Tuesday, July 22, 2014

How to find number of CPUs in Linux?

Nowadays, each CPU made up of multiple CORES and each CORE is now treated as a separate CPU.

Also, if HYPERTHREADING is enabled, then each CORE is treated as TWO SEPARATE LOGICAL UNITS and these two LOGICAL UNITS too are treated as separate CPUs.

dmidecode -t processor | egrep "Socket Designation|Core Count|Thread Count"
        Socket Designation: CPU1
        Core Count: 4
        Thread Count: 8
        Socket Designation: CPU2
        Core Count: 4
        Thread Count: 8

As per command dmidecode, there are
Two CPUs
Eight Cores - Each CPU has 4 cores
Sixteen Threads - Each Core has two threads

Hence, the number of CPUs in the system is 16

This can be verified by other means too

grep 'processor' /proc/cpuinfo
processor       : 0
processor       : 1
processor       : 2
processor       : 3
processor       : 4
processor       : 5
processor       : 6
processor       : 7
processor       : 8
processor       : 9
processor       : 10
processor       : 11
processor       : 12
processor       : 13
processor       : 14
processor       : 15



# Count the number of “physical processor(s)
grep "physical id" /proc/cpuinfo | sort -u | wc -l

# Count the number of “physical cores per CPU”
grep "cpu cores" /proc/cpuinfo |sort -u |cut -d":" -f2

# Count the number of “logical cores ” (including multi-threading cores)
grep -c "processor" /proc/cpuinfo





No comments:

Post a Comment