Finding how many CPUs/Cores/Threads in a Solaris server
Now 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.
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)
**********
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.
HOSTNAME=`hostname`
# Physical - the number of physical sockets/CPUs
PHYSICAL=`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=`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=`mpstat | grep -v CPU | wc -l`
VIRTUALPER=`expr ${VIRTUAL} / ${CORES}`
echo
echo "In ${HOSTNAME} there are:"
echo "${PHYSICAL} Physical CPUs/Sockets"
echo "${CORES} Physical Cores across all CPUs"
echo " ${CORESPER} Cores per Physical CPU"
echo "${VIRTUAL} Total virtual CPUs recognized by the OS"
echo " ${VIRTUALPER} Threads per Core (Virtual CPUs per Core)"
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….