How many physical CPUs does my machine have?

I am a bit confused about the number of CPUs my server has.

It is running on Intel(R) Xeon(R) Gold 6242R CPU @ 3.10GHz which according to official Intel docs contains 20 physical cores.

The problem here is the output of lscpu command (some rows filtered):

CPU(s):                          80
On-line CPU(s) list:             0-79
Thread(s) per core:              2
Core(s) per socket:              20
Socket(s):                       2
NUMA node(s):                    2
Model name:                      Intel(R) Xeon(R) Gold 6242R CPU @ 3.10GHz
NUMA node0 CPU(s):               0-19,40-59
NUMA node1 CPU(s):               20-39,60-79

From what I understand actual physical cores = CPU(s) / thread(s) per core but then I get 40 which is double of what I expect.

Can someone please explain me what is going on here and what exactly CPU(s), thread(s) per core, core(s) per socket, socet(s) mean?


Solution 1:

  • Sockets represents how many physical CPUs are in the system.

  • Cores per socket is how many full CPU cores (including loading/decoding logic) there are per physical CPU.

  • Threads per core is how many threads can be scheduled on a single core (HyperThreading). Simply said, the hardware in the CPU that is used before the actual execution of code is doubled, allowing the CPU to have multiple different tasks ready for execution. It allows the CPU to fetch/decode instructions before they hit the execution core of the CPU. It prevents or reduces pipeline stall.

  • CPU means "schedulable entities", this is how many run queues the operating system will have, so that would be sockets x cores per socket x threads per core

In your case, you have 2 physical CPUs, which each have 20 cores, which each can run 2 threads (hyperthreading). So 2x20x2 = 80, which is the number of CPUs displayed.

Solution 2:

The confusion comes from a very simple detail that might be unclear from the info lscpu command is showing you.

The thing is: your server actually has 2 Intel(R) Xeon(R) Gold 6242R CPUs, which is mentioned in the Socket(s) row.

As the Intel documentation states, each one of those CPUs contains 20 physical cores (the Core(s) per socket line) which gives a total of 40 physical cores.

Each one of those cores is able to run 2 threads "simultaneously" (the Thread(s) per core line).

So: 2 Intel Xeon, 20 physical cores each one, 2 threads each core, gives a total of 80 "units that can execute a process" or "CPUs"

Solution 3:

The idea of a CPU is a bit of an abstraction now, and this started with hyperthreading (late 90's) and then the Intel Core (early 00's) series. Before then you definitely had multiple-CPU systems but they were all multiple-physical-CPU.

But with hyperthreading and multiple-core single CPUs, the physical # of CPUs is different than the logical # of CPUs the running code on the CPUs sees.

Socket(s):                       2

You have 2 physical CPUs as in "thing with heatsink plugged into your motherboard"

Core(s) per socket:              20

Each physical CPU has 20 cores, which look and mostly work like independent CPUs to Linux. Cores share at least the same L3 cache, probably L2 cache, and probably have their own L1 cache - so not quite as peformant as individual sockets with their own L3/L2/L1 but nearly there.

Since that's each socket, you have 2 * 20 = 40.

Thread(s) per core:              2

Each core has 2 SMT threads, which are implemented by your CPU's microarchitecture to basically look mostly like independent CPUs to Linux

They're not going to be anywhere as fast as real independent cores.

Threads on the microarchitecture try to grab currently unused pipeline stages from cores but might have to end up waiting if busy--and CPUs already try to keep themselves very busy, so again 2 threads on 2 cores is nowhere near equivalent to 4 cores, but it is something that can make code run a bit faster.

Note that Spectre and similar vulnerabilities are much more possible across threads than cores or sockets because core resources are shared.

Anyway, since that's per core, and also per socket, that's 2 * 20 * 2, which gives you:

CPU(s):                          80

Solution 4:

Dual CPU… processors x2, 20 cores per socket…x2 = 40 cores = 80 with HT.
This is probably very easy to verify by simply taking the lid/side off.