Finding how many CPUs/Cores/Threads in a Solaris server
I think this will only work in Solaris 10, but this should give a nice output of how many Physical CPUs, Physical Cores, and Threads [Virtual CPUs] are recognized by Solaris. This will work on Solaris 10 for SPARC or x86.
Note: I’m told that the script gives strange results when run in an LDOM. I don’t have any LDOMs to test with and I’m not really familiar with them. The script was meant to be run in the global zone. It does give proper results in an un-capped local zone.
The output looks like this:
**********
user@host:~$ ~/bin/cpucount.sh
In host.example.com there are:
1 Physical CPUs/Sockets
8 Physical Cores across all CPUs
8 Cores per Physical CPU
64 Total virtual CPUs recognized by the OS
8 Threads per Core (Virtual CPUs per Core)
**********
You can download cpucount.sh script [Right-Click -> Save Link As] or:
Here’s the actual script to produce the above output:
#!/bin/bash
# Quick and **dirty** script to count the number of physical CPUs,
# physical cores and virtual CPUs recognized by the OS
# The CORES part will only work in Solaris 10
# The rest I'm not sure about.
# Gives odd results in an LDOM I'm told.
# But don't have any to test on
HOSTNAME=`hostname`
# Physical - the number of physical sockets/CPUs
PHYSICAL=`/usr/sbin/psrinfo -pv | grep physical | wc -l`
# Cores - The number of physical cores total [across all CPUs]
# I'm pretty sure this part will only work in Solaris 10
CORES=`/usr/bin/kstat cpu_info | \
egrep "cpu_info |core_id" | \
awk \
'BEGIN { printf "%4s %4s", "CPU", "core" } \
/module/ { printf "\n%4s", $4 } \
/core_id/ { printf "%4s", $2} \
END { printf "\n" }' | awk '{print $2}' | grep -v core | sort -u | wc -l`
CORESPER=`expr ${CORES} / ${PHYSICAL}`
# This is the TOTAL number of processors [virtual and real]
# that the OS recognizes
VIRTUAL=`/usr/bin/mpstat | grep -v CPU | wc -l`
VIRTUALPER=`expr ${VIRTUAL} / ${CORES}`
# Remove odd whitespaces from beginning of results
PHYSICAL="${PHYSICAL#"${PHYSICAL%%[![:space:]]*}"}"
CORES="${CORES#"${CORES%%[![:space:]]*}"}"
CORESPER="${CORESPER#"${CORESPER%%[![:space:]]*}"}"
VIRTUAL="${VIRTUAL#"${VIRTUAL%%[![:space:]]*}"}"
VIRTUALPER="${VIRTUALPER#"${VIRTUALPER%%[![:space:]]*}"}"
## Print results in a pretty form :^)
echo
printf "In ${HOSTNAME} there are:\n"
printf "%4s %3s Physical CPUs/Sockets\n" ${PHYSICAL}
printf "%4s %3s Physical Cores across all CPUs\n" ${CORES}
printf "%4s %3s Cores per Physical CPU\n" ${CORESPER}
printf "%4s %3s Total virtual CPUs recognized by the OS\n" ${VIRTUAL}
printf "%4s %3s Threads per Core (Virtual CPUs per Core)\n" ${VIRTUALPER}
##################### END SCRIPT #################
UPDATE: 2010-04-05 – updated script to print the output a little more nicely and aligned.
Comments
Comment from edgar
Time March 28, 2010 at 2:35 pm
nice script. just made my auditing a lot easier. thanks.
Comment from Nilesh Joshi
Time March 9, 2010 at 10:09 am
Gr8 script. Good one, it helped me a lot for addressing end users queries….