How to find the number of physical cpus, cpu cores, and logical cpus

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 4
  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9

Issue

  • What's the difference between physical CPUs, CPU cores, and logical CPUs on an x86/x86_64 system?
  • How to get the list of available processors from the RHEL operating system?

Resolution

  • Number of physical CPUs

    • The following command will show how many active physical processors a system has. Example: If this number is 2, one could potentially open up the system chassis and remove 2 physical processors with one's hands.

        $ grep physical.id /proc/cpuinfo | sort -u | wc -l
        2
      
  • Number of cores per CPU

    • On a system with multi-core processors, the following command should report the number of CPU cores per physical processor (though in rare cases it might not). Example: If this number is 4 and physical CPUs is 2, then each of the 2 physical processors has 4 CPU cores, leading to a total of 8 cores.

        $ grep cpu.cores /proc/cpuinfo | sort -u
        cpu cores : 4
      
  • Number of logical processors

    • This last command will show the total number of "logical" processors seen by the Linux kernel. This number is usually the most important of the three stats. It is the effective number of processors -- as far as the operating system is concerned, this is the number of distinct CPUs that can do work at any given microsecond. Example: Continuing with the above example scenario, the number seen below could be 16 instead of 8. Simply put, if this command shows a different number than the total number of CPU cores, it's because hyper-threading is enabled on the CPUs, further dividing each core (in this example, into 2 usable "threads").

        $ grep processor /proc/cpuinfo | wc -l
        16
      

 

Licensing?

  • To determine the number of CPUs for RHEL licensing reasons, the first command above is sufficient; however, for more discussion, consult How to determine number of CPU sockets on a system.

  • If purchasing 3rd-party software whose licensing varies based on the number of sockets (filled or unfilled), processors, or cores, contact the software vendor to find out exactly how they calculate number of CPUs.

Tools

  • Note that Red Hat Enterprise Linux 6, 7, 8 and 9 ship with the lscpu command which can print out a simple readable summary of a system's processors. Additionally, in RHEL6 the hwloc package is available (RHEL7) -- hwloc includes the lstopo command, as well as various hwloc-* commands.

  • Prior to RHEL6, direct inspection of /proc/cpuinfo (as above) or use of the x86info or dmidecode commands (RPMs of the same name) would be the supported options to discover the same information.

  • Other 3rd-party options which are offered with no guarantees: xsos (developed by the original author of this article) and lshw (available in EPEL).

  • For any version of Red Hat Enterprise Linux: the BASH script attached to this article parses /proc/cpuinfo to print an easily-readable summary like the following. (Note that it is provided with no guarantees or official support.)

      $ cpu
      128 logical processors (64 CPU cores)
      8 Intel Xeon CPU X7560 @ 2.27GHz (flags: constant_tsc,ht,lm,pae,vmx) 
      └─16 threads / 8 cores each
    
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.