48

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?

61

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:

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
CPU(s):                4
Thread(s) per core:    2
Core(s) per socket:    2
CPU socket(s):         1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 37
Stepping:              5
CPU MHz:               2667.000
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3

In the above my Intel i5 laptop has 4 "CPUs" in total

CPU(s): 4

of which there are 2 physical cores

Core(s) per socket: 2

of which each can run up to 2 threads

Thread(s) per core: 2

at the same time. These threads are the core's logical capabilities.

  • I don't have lscpu.Is there any alternative tool? – Jim Aug 27 '13 at 19:12
  • 1
    The raw info that lscpu uses is exposed here: cat /proc/cpuinfo. What's your OS? – slm Aug 27 '13 at 19:16
  • The OS is is centos – Jim Aug 27 '13 at 20:44
  • @Jim - install this package on CentOS, util-linux-ng. This will do it for you, sudo yum install util-linux-ng. This tool is standard fare coming from the kernel.org: ftp.kernel.org/pub/linux/utils/util-linux-ng. It's probably not installed by default to save disk space. – slm Aug 27 '13 at 20:46
  • 1
    @ThomasWeller - see my other A'er here - unix.stackexchange.com/questions/113544/…. – slm Nov 7 '18 at 8:47
11

Physical cores are number of physical cores, actual hardware components.

Logical cores are the number of physical cores times the number of threads that can run on each core through the use of hyperthreading.

for example, my 4-core processor runs two threads per core, so I have 8 logical processors.

  • So this number makes sense only if using a processor that supports hyperthreading? And what does this mean?Still one thread will occupy each cpu at a time right?So what does this number mean? – Jim Aug 26 '13 at 22:11
  • So which number should I aim to get? – Jim Aug 26 '13 at 22:12
  • not necessarily, simultaneous multithreading, for example, allows for two threads to be run at the same time on a single core. There are a number of other advantages as well. – ash Aug 26 '13 at 22:15
  • I look at the number of physical cores. – ash Aug 26 '13 at 22:18
1

Hyperthreading technology allows a single physical processor core to behave like two logical processors.

So a single processor core can execute two independent threads simultaneously.

Intel refers to a physical processor as a socket.

Hyperthreading makes a Physical Processor to behave like it has two Physical Processors, which are called Logical Processor. why?

While hyperthreading does not double the performance of a system, it can increase performance by better utilizing idle resources leading to greater throughput for certain important workload types. An application running on one logical processor of a busy core can expect slightly more than half of the throughput that it obtains while running alone on a non-hyperthreaded processor.


Summary


Physical Processor are that we can see and fell.

Logical Processor is like, a Phsical Core acting as Two Physical Core

0
$ sudo dmidecode |egrep "Socket Designation: Proc|((Thread|Core) Count)"
Socket Designation: Proc 1
        Core Count: 14
        Thread Count: 28
Socket Designation: Proc 2
        Core Count: 14
        Thread Count: 28

Two sockets. Each socket has 14 physical cores. Each core has two threads (28/14). Total number of logical "cpus" or logical processing units is 56 (that's what "top" and some other commands would show you as number of "cpus").

  • What baffles me is that on my i3-3220 with your approach I get core count 2 and thread count 2 (=4) but lscpu shows CPUs 4 and threads per 2 (=8) but lshw -C cpu` shows 16 logical cpu's numbered 0 - 15 – Elder Geek Feb 7 '16 at 18:04
  • dmidecode interprets what's in BIOS.. not sure exactly what's wrong in your case, e.g. you may have hyperthreading disabled in BIOS or something like that. lscpu and lshw are OS commands so show what OS kernel has recognized. Intel spec for your processor show 2 cores 4 threads. – Tagar Feb 8 '16 at 5:10
  • Wouldn't having hyperthreading disabled result in fewer logical cores rather than more? – Elder Geek Feb 8 '16 at 18:17
  • I understood that you got 2 cores 2 threads reported by dmidecode instead of 2 cores 4 threads real number of threads/cores i3-3220 has. So it is smaller. And that was just a guess, I don't know if you actually have hyperthreading disabled in BIOS or not. – Tagar Feb 8 '16 at 21:36
  • It seems I've misinterpreted lscpu output and it's actually 4 threads total but "lshw -C cpu` shows 16 logical CPU’s" I'm not sure what to make of that. – Elder Geek Feb 9 '16 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.