Figuring out CPUs and Sockets - Updated!

Latest response

So a while back I posted this article in our older portal group system. It was fairly popular and generated quite a bit of good conversation. I'm reposting here and have attempted to weave in some of the great comments we received from the Community. As with anything in this exciing world of open source, there are literally dozens of ways to skin this cat. So please read on and let us know if you other options we can share.

I had a recent email from one of my customers. His organization was about ready to go through some licensing true-ups and he was in a bit of a pickle. He had a few 3rd-party products they needed to do some accounting on and each product was licensed using a different model. Sadly they did not have any type of CMDB in place to help (Configuration Management Database - something very handy to have when it comes to looking at your server inventory). I thought back to my years of running a large Enterprise *NIX team and shuddered; easily once every month or so someone came by asking me the exact same questions.

So we worked on a few simple commands that can be used to produce this data. First we tried this:

$ lscpu | grep 'socket'
Core(s) per socket: 2
CPU socket(s): 1

At this command's "core" [ha ha, pun intended] we got exactly what my pal Tom wanted, and then some. Not only can we see how many sockets he was using (which is what he was reporting for) but we also found out how many cores there were in each socket.

Next we tried something that while much less pretty, zeroed in on the exact requirement:

$ cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l
1

This told us exactly how many sockets we had. And then for fun (Tom is nothing if not fun) we wondered how you could account for if something was hyperthreaded or not so he whipped out this:

$ egrep -e "core id" -e ^physical /proc/cpuinfo|xargs -l2 echo|sort -u
physical id : 0 core id : 0
physical id : 0 core id : 1

So Tom went back to work, happy and ready to give his bosses EXACTLY what they needed (he was so happy he had a new scripting project to tinker with). These commands worked from RHEL6 back to RHEL4 so most everyone should be able to use them, So if you're interested in giving these a whirl, there are also a few official knowledge solutions produced by our esteemed Ryan Sawhill you may want to review too:

Check if Server is VM?

dmidecode | grep -i product

        Product Name: VMware Virtual Platform 

Get number of CPU

grep -i "physical id" /proc/cpuinfo | sort -u | wc -l 

dmidecode |grep -i cpu

Socket Designation: CPU1

    Socket Designation: CPU2 
    Socket Designation: CPU3 
    Socket Designation: CPU4 
            CPU.Socket.1 
            CPU.Socket.2 
            CPU.Socket.3 
            CPU.Socket.4 

To check this a few different ways:

Check if HyperThreading is enabled

# of siblings = # of cores 

    cat /proc/cpuinfo |egrep 'sibling|cores' 
    grep -i "processor" /proc/cpuinfo | sort -u | wc -l 

Hyperthreading can be found with lscpu too:

# lscpu | grep -i thread
Thread(s) per core:    2
#cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l
0

But dmidecode still shows sockets:

# dmidecode -t4 | egrep 'Designation|Status'
        Socket Designation: CPU 1
        Status: Populated, Enabled
        Socket Designation: CPU 2
        Status: Populated, Enabled

And far and away the best hidden nugget from the older article was a tool that I use very often here during my day helping support customers: xsos

I use xsos to help look at infomration provided in sosreports, but it has a lot of great uses (like our proc/socket question here). You can get xsos here:

https://github.com/ryran/xsos

Yum repo available for xsos -- a tool for sysadmins

On a machine here in the lab I ran xsos so you can see typical output:

# xsos
OS
  Hostname:  LINUXizTHAawesome
  Distro:    Red Hat Enterprise Linux Workstation release 6.4 (Santiago)
  Kernel:    2.6.32-358.18.1.el6.x86_64
  Runlevel:  N 5 (default: 5)
  SELinux:   enforcing (default: enforcing)
  Sys time:  Thu Sep 12 08:17:11 EDT 2013
  Boot time: Tue Sep 10 07:29:28 EDT 2013 (1378812568)
  Uptime:    2 days, 47 min,  2 users
  LoadAvg:   0.13 (3%), 0.14 (4%), 0.10 (2%)
  Cpu time since boot:
    us 7%, ni 0%, sys 1%, idle 91%, iowait 1%, irq 0%, sftirq 0%, steal 0%
  procs_running (procs_blocked):
    2 (0)
  Kernel taint-check: 0 (kernel untainted)

<snip>
CPU
  4 logical processors (2 CPU cores)
  1 Intel Core i7-2640M CPU @ 2.80GHz (flags: aes,ht,lm,pae,vmx) 
  └─4 threads / 2 cores each
<snip>

So BAM! Right there exactly what we wanted in a nicely-wrapped output.

So we have some formal articles you can refer back to as well:

How to determine number of CPU sockets on a system

and

Difference between physical cpus, cpu cores, and logical cpus

So what do you think? Is this useful stuff? Will this save you any time or even help you start off your own CMDB? We'd love to hear from you!

Cheers,

CRob
Technical Account Manager
Red Hat Inc.

Responses