I was googling about how I could find the number of CPUs in a machine and I found some posts but I am confused as some mentioned that you get the logical cores vs physical cores etc.
So what is the difference between logical and physical cores and is there a way I could get the physical cores only? Or does it make sense to include logical cores in our count?
So what are logical cpu cores (as opposed to physical cpu cores)
cpumultiprocessor
Best Answer
Physical cores are just that, physical cores within the CPU. Logical cores are the abilities of a single core to do 2 or more things simultaneously. This grew out of the early Pentium 4 CPUs ability to do what was termed Hyper Threading (HTT).
It was a bit of a game that was being played where sub components of the core weren't being used for certain types of instructions while, another long running instruction might have been being executed. So the CPU could in effect work on 2 things simultaneously.
Newer cores are more full-fledged CPUs so they're working on multiple things simultaneously, but they aren't true CPUs as the physical cores are. You can read more about the limitations of the hyperthreading functionality vs. the physical capabilities of the core here on tomshardware in this article titled: Intel Core i5 And Core i7: Intel’s Mainstream Magnum Opus.
You can see the breakdown of your box using the
lscpu
command:In the above my Intel i5 laptop has 4 "CPUs" in total
of which there are 2 physical cores (1 socket × 2 cores/socket = 2 cores)
of which each can run up to 2 threads
at the same time. These threads are the core's logical capabilities.