13

When I run top, I show CPU 0-7. When i do:

cat /proc/cpuinfo | grep "cpu cores" | uniq

I get:

cpu cores : 4

If I grep "physical id" I have 1.

I am thinking my command is wrong and top is right. This is not a VM and it a physical server, RedHat. What am I doing wrong?

I am not sure these answer it:

How to know number of cores of a system in Linux?

Number of processors in /proc/cpuinfo

Edit: Am I correct that Physical ID, if it only shows 1, then I have one physical chip in the motherboard?

Edit: It is a Intel(R) Xeon(R) CPU X5560 @ 2.80GHz but the physical id is 1, and I thought it would be 0, but there is no physical id 0 in cpuinfo.

Edit: If it matters, I am trying to figure out licensing where they do .5 the core count.

johnny
  • 247

5 Answers5

27

The X5560 is a single chip. It looks like this:

enter image description here

grep "physical id" is telling you that you have ONE physical processor installed.

If you take the heat spreader off of the top you can see this - a single physical die (face down) :

enter image description here

If you could remove that die and flip it over, it would look like this :

enter image description here

On that single physical die there are four physical CPU cores built onto the silicon :

enter image description here

grep "cpu cores" is telling you that your processor has four physical cores built onto it.

Each core is a single processor with a floating point unit, a number of integer execution units, a pair of register stacks, and some other wizardry that allows each single core to effectively execute two independent instruction streams (threads) at a time.

enter image description here

top is telling you that all the processors and cores on your computer, collectively, can execute eight independent workflows at a time - it's telling you that the operating system is able to schedule eight simultaneous threads for execution at any given time.

J...
  • 371
  • Thanks a lot. I really appreciate your time on this. Helps me a great deal. – johnny Nov 22 '17 at 15:16
  • Out of curiosity, why is it two threads? How do they get two? Why not four or five, silly as that sounds. – johnny Nov 22 '17 at 15:19
  • 3
    @johnny Most cpus for most of time have been one chip, one core, one thread. Over time engineers noticed that some parts of a core spend a significant amount of time idle while they are waiting for other parts to finish their work. Hyperthreading is a relatively new technology that adds a few extra bits to the core to allow more of those previously idle parts to remain mostly busy most of the time by feeding them a separate independent workload. It doesn't double the performance of a core, but it does allow it to do about 30% more work than it otherwise would, so the buck stops there at two. – J... Nov 22 '17 at 16:30
15

What CPU are you using? How many thread present per physical core?

cat /proc/cpuinfo shows number of physical core whereas top shows total no of threads present.

I think your CPU has 4 physical core and 2 logical core per physical core. So it's top showing 8.

Moreover contents of /proc/cpuinfo is somewhat implementation dependent. Like in rooted android shell the cpuinfo file doesn't contain any term cpu cores.

However in cpuinfo each thread is named as processor : X, Where X is thread no. So the last thread no shall be same as top/htop output.

Result of nproc --all shall also be consistent with top/htop

Abhik Bose
  • 2,118
7

top shows one “CPU” per logical CPU; on x86, that’s the product of the number of sockets in the system, by the number of physical cores per socket, by the number of threads per core.

The cpu cores entry in /proc/cpuinfo, again on x86, shows the number of physical cores. To find the number of logical cores, as used in top, you should look at the siblings value instead:

cat /proc/cpuinfo | grep "siblings" | uniq

This is described in detail in the kernel documentation.

lscpu provides information on the installed CPU(s) which is easier to understand than /proc/cpuinfo (or rather, it presents the same information in a simpler fashion).

Stephen Kitt
  • 434,908
4

Likely, you have one CPU that is a "quad core" CPU, and have hyperthreading enabled so that each physical core presents itself to the OS (to the kernel) as two logical cores, able to have two threads assigned to that same physical core simultaneously.

The key terms to ensure you understand here are: CPU, or physical chip, or "die" (relates to "socket"); then, physical core; then ensure you have a grasp on "process" and "thread"; then clear up "hyperthreading" and "logical core."

I attended a talk at LISA 2017 that cleared this all up very nicely; the slides from that talk are available online, though of course they won't help as much as the actual talk did (since the spoken part is missing).

Wildcard
  • 36,499
2

cpuinfo show the actual cores while htop/top show both cores and thread as cores.You most likely have 4 cores and 4 threads that's why.

AsenM
  • 568