GNU/Linux, Open Source, Cloud Computing, DevOps and more...

Differences between physical CPU vs logical CPU vs Core vs Thread vs Socket

No comments

When we try to know a computer’s architecture and performance at CPU level using Linux commands like nproc or lscpu, we often find out that we are not able to properly interpret their results because we confuse terms such as physical CPU, logical CPU, virtual CPU, core, thread, socket, etc. If we add concepts like HyperThreading (not to be confused with multithreading), we are in a situation where we can not be sure how many cores our box has, we don’t understand why commands like htop indicate that we have 8 cpus when we thought we had bought a single quad-core processor, etc. In short, it’s a mess.

htop-command-outputIn order to clarify I will explain all these concepts using a pair of simple diagrams that I hope will help you to easily understand and never again have these doubts.

The origins: single core CPUs and HyperThreading

Before concepts such as multi-core, virtual or logical cpu would exist, back in the days of Pentium processors, most computers mounted on their motherboard a single chip of considerable size that we called microprocessor, processor or simply CPU. Only a few enterprise computers or larger servers that required more processing power could afford to mount 2 or more of these chips on the same board: they were multiprocessor systems. These chips communicated with other motherboard elements through a connector or socket. And the math was simple: so many connectors or sockets had a board, so many CPUs a computer could have at most. If you wanted more processing power, you just had to look for a motherboard with a larger number of these processors or wait for them to evolve to offer higher performance.

But then Intel realized that communications between the different processors of a multiprocessor system were very inefficient since they had to be done through the system bus, which usually worked at much lower speed. This frecuently caused bottlenecks that made impossible to make the most of the computing capacity offered by each CPU.

single-core-hyperthreading-cpu-diagramIn order to improve this situation the HyperThreading technology was invented. HT is about duplicating some CPU internal components within the same chip, such as registers or first level caches so that information could be shared between two different execution threads without having to go through the system bus with the corresponding bottlenecks and loss of speed issues. This also allowed that if a process had to wait for an interruption, another process could continue to use the CPU without it being stopped.

This way it was possible to speed up several cumputing processes and began to offer processors with a greater overall performance than traditional ones. The operating system was kind of cheated because it was offered 2 virtual or logical cpus (LCPU) instead of single one as it was allowed to execute 2 processes “at the same time”. But it is important to remark that it was impossible to yield twice the processing power of a traditional processor, nor was it possible to offer full parallel processing capabilities.

Thus, from the point of view of Linux or any other operating system, a box with 1 single core processor but HT appears before our eyes as having 2 CPUs. But these are 2 logical cpus running within the same single physical cpu.

One more twist: the emergence of multi-core architectures

But as I said in the previous section, although CPUs with hyperthreading offer more processing power, they can not perform as 2 complete and independent processors, so it was decided to go further miniaturizing all processor components and encapsulating them next to others in a single chip. Each of these encapsulated processors was called core, and it allowed to achieve faster communications between them by means of an internal bus sharing the same silicon. From that moment it was no longer necessary to turn to the system bus, much slower.

quad-core-hyperthreading-cpu-diagramUnlike HT tehcnology, now we have multiple completely independent CPUs to all intents and purposes, one per core. Indeed, from a performance point of view it’s better to have a single multicore processor than the equivalent number of single core CPUs on the same board. Of course it would still be better to have 2 dual-core processors than one, but even better would be to have a single quad-core.

At the operating system level, a physical quad-core processor would be shown as a 4 cpu computer. But these would be 4 logical CPUs or non-physical LCPUs. If the processor additionaly offers HyperThreading technology, commands such as htop or nproc would indicate that there are 8 cpus in the system, but would perform lower than 8 cpus from a single octa-core processor without HyperThreading.

1 LCPU = 1 thread

Finally, often we’ll find processors featuring 4 threads, 2 threads per core and things like that. This is simply about the number of execution threads or processing jobs that can be run simultaneously, which is the equivalent of the processing capacity offered by a LCPU. If a processor allows 2 threads per core it means that it is HT. Otherwise it’s normal for the number of cores to match threads.

Logical CPU vs Virtual CPU

The virtual CPU term is comparable to logical CPU but it adds a certain nuance: it’s more framed in terms of computing virtualization. It refers to those cpus mapped to virtual machines from the underlying host hardware, wich can be physical or logical cpus, HT or not. Normally 1 logical cpu from host server is mapped to 1 virtual cpu inside virtual machine, so they are almost equivalent terms.

Recommended reading:
  How to know how many cores and processors has a Linux box


About the author

Daniel López Azaña
Cloud Solutions Architect

Entrepreneur, a generator of ideas and restless mind. Passionate about new technologies, especially Linux systems and Open Source Software. I also like to write about Technology News, Cloud Computing, DevOps, System Security, Web Development and Programming, SEO, Science, Innovation, Entrepreneurship, etc.

DanielDifferences between physical CPU vs logical CPU vs Core vs Thread vs Socket

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.