Oracle Solaris: Show Me the CPU, vCPU, Core Counts and the Socket-Core-vCPU Mapping

[Replaced old code with new code on 10/03/11]

It should be easy to find this information just by running an OS command. However for some reason it ain't the case as of today. The user must know few details about the underlying hardware and run multiple commands to figure out the exact number of physical processors, cores etc.,

For the benefit of our customers, here is a simple shell script that displays the number of physical processors, cores, virtual processors, cores per physical processor, number of hardware threads (vCPUs) per core and the virtual CPU mapping for all physical processors and cores on a Solaris system (SPARC or x86/x64). This script showed valid output on recent T-series, M-series hardware as well as on some older hardware - Sun Fire 4800, x4600. Due to the changes in the output of cpu_info over the years, it is possible that the script may return incorrect information in some cases. Since it is just a shell script, tweak the code as you like. The script can be executed by any OS user.

Download the script : showcpucount


% cat showcpucount

--------------------------------------- CUT HERE -------------------------------------------
#!/bin/bash

/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" > /var/tmp/cpu_info.log

nproc=`(grep chip_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`
ncore=`(grep core_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`
vproc=`(grep 'module: cpu_info' /var/tmp/cpu_info.log | awk '{ print $4 }' | sort -u | wc -l | tr -d ' ')`

nstrandspercore=$(($vproc/$ncore))
ncoresperproc=$(($ncore/$nproc))

speedinmhz=`(/usr/bin/kstat -m cpu_info | grep clock_MHz | awk '{ print $2 }' | sort -u)`
speedinghz=`echo "scale=2; $speedinmhz/1000" | bc`

echo "Total number of physical processors: $nproc"
echo "Number of virtual processors: $vproc"
echo "Total number of cores: $ncore"
echo "Number of cores per physical processor: $ncoresperproc"
echo "Number of hardware threads (strands or vCPUs) per core: $nstrandspercore"
echo "Processor speed: $speedinmhz MHz ($speedinghz GHz)"

# now derive the vcpu-to-core mapping based on above information #

echo -e "\n** Socket-Core-vCPU mapping **"
let linenum=2

for ((i = 1; i <= ${nproc}; ++i ))
do
        chipid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`
        echo -e "\nPhysical Processor $i (chip id: $chipid):"

        for ((j = 1; j <= ${ncoresperproc}; ++j ))
        do
                let linenum=($linenum + 1)
                coreid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`
                echo -e "\tCore $j (core id: $coreid):"

                let linenum=($linenum - 2)
                vcpustart=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

                let linenum=(3 * $nstrandspercore + $linenum - 3)
                vcpuend=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

                echo -e "\t\tvCPU ids: $vcpustart - $vcpuend"
                let linenum=($linenum + 4)
        done
done

rm /var/tmp/cpu_info.log
--------------------------------------- CUT HERE -------------------------------------------

# prtdiag | head -1
System Configuration:  Sun Microsystems  sun4u SPARC Enterprise M4000 Server

# ./showcpucount
Total number of physical processors: 4
Number of virtual processors: 32
Total number of cores: 16
Number of cores per physical processor: 4
Number of hardware threads (strands or vCPUs) per core: 2
Processor speed: 2660 MHz (2.66 GHz)

** Socket-Core-vCPU mapping **

Physical Processor 1 (chip id: 1024):
        Core 1 (core id: 0):
                vCPU ids: 0 - 1
        Core 2 (core id: 2):
                vCPU ids: 2 - 3
        Core 3 (core id: 4):
                vCPU ids: 4 - 5
        Core 4 (core id: 6):
                vCPU ids: 6 - 7

Physical Processor 2 (chip id: 1032):
        Core 1 (core id: 8):
                vCPU ids: 8 - 9
        Core 2 (core id: 10):
                vCPU ids: 10 - 11
        Core 3 (core id: 12):
                vCPU ids: 12 - 13
        Core 4 (core id: 14):
                vCPU ids: 14 - 15

Physical Processor 3 (chip id: 1040):
        Core 1 (core id: 16):
                vCPU ids: 16 - 17
        Core 2 (core id: 18):
                vCPU ids: 18 - 19
        Core 3 (core id: 20):
                vCPU ids: 20 - 21
        Core 4 (core id: 22):
                vCPU ids: 22 - 23

Physical Processor 4 (chip id: 1048):
        Core 1 (core id: 24):
                vCPU ids: 24 - 25
        Core 2 (core id: 26):
                vCPU ids: 26 - 27
        Core 3 (core id: 28):
                vCPU ids: 28 - 29
        Core 4 (core id: 30):
                vCPU ids: 30 - 31
Comments:

kstat(1M) is just a perl script that extracts and formats the kstat data using a C extension to perl. Yous example would be a \*whole\* lot more efficient if you wrote it as a single perl script.

Posted by Alan Burlison on April 14, 2011 at 06:39 PM PDT #

Giri-

A small thing - this script appears to return incorrect information for some x86 hardware. I have a server with an x86 CPU for which your script returns:

Total number of physical processors: 1
Number of virtual processors: 8
Total number of cores: 8
Number of cores per physical processor: 8
Number of hardware threads (strands) per core: 1

I have a similar script which parses the kstat data and returns the correct value for the Intel x5560 CPU of:

1 physical CPU
4 cores per physical CPU
2 threads per core

The error is in the calculation of "nproc". This should work as a replacement, I think:

ncore=`(/usr/bin/kstat -m cpu_info | grep core_id | awk '{print $2}' | sort -u | wc -l | tr -d ' ')`

Best,

James

Posted by James Ervin on April 17, 2011 at 11:46 PM PDT #

Thank you, James, for the feedback. Eliminating duplicates and counting the remaining literal core ids should also result in a similar output. Since you tried it out on latest x86 hardware, I made the change to the script as you suggested. Thanks again.

Posted by Giri Mandalika on April 19, 2011 at 10:02 AM PDT #

Giri -

I'm trying to determine Processor-CPU-core-thread mappings on LDOMs aka Sparc VM, in order to restrict an LDOM to specific full CPUs, and then to be sure it is restricted.

Using your script and comparing psrinfo -pv, I note that it is only informing me of the VM assigned hardware (I'm Ok with that, though I would like to determine the base system as well) and the output of the two commands is in conflict as well. This was run on an LDOM on a T5440 base system; the LDOM has "64 CPUs asssigned", aka 64 vCPUs or threads.

psrinfo -pv
The physical processor has 40 virtual processors (0-39)
UltraSPARC-T2+ (chipid 0, clock 1414 MHz)
The physical processor has 24 virtual processors (40-63)
UltraSPARC-T2+ (chipid 1, clock 1414 MHz)

kstat script:
Total number of physical processors: 2
Number of virtual processors: 64
Total number of cores: 8
Number of cores per physical processor: 4
Number of hardware threads (strands or vCPUs) per core: 8

** Socket-Core-vCPU mapping **

Physical Processor 1:
Core 1:
vCPU ids: 0-7
Core 2:
vCPU ids: 8-15
Core 3:
vCPU ids: 16-23
Core 4:
vCPU ids: 24-31

Physical Processor 2:
Core 1:
vCPU ids: 32-39
Core 2:
vCPU ids: 40-47
Core 3:
vCPU ids: 48-55
Core 4:
vCPU ids: 56-63

If you know how to reconcile the two outputs, I would appreciate it very much. I need to restrict this LDOM to a full CPU and verify that restriction.

Thanks,
Ken

Posted by guest on June 17, 2011 at 03:38 AM PDT #

Script shows incorrect order for the VCPU assignments.

Solaris doesnt follow an ordered list as calculated in the script but uses its own enumeration logic to assign cores/threads to Vcpu's.

Better to use "psrinfo -pv". See example on a X4150M2 below (Vcpu ids are between brackets in the psrinfo output):

# psrinfo -pv
The physical processor has 4 virtual processors (0 2-4)
x86 (chipid 0x0 GenuineIntel family 6 model 23 step 6 clock 2826 MHz)
Intel(r) Xeon(r) CPU E5440 @ 2.83GHz
The physical processor has 4 virtual processors (1 5-7)
x86 (chipid 0x1 GenuineIntel family 6 model 23 step 6 clock 2826 MHz)
Intel(r) Xeon(r) CPU E5440 @ 2.83GHz

This doesnt match up with the output off showcpucount at all:

# showcpucount
Total number of physical processors: 2
Number of virtual processors: 8
Total number of cores: 8
Number of cores per physical processor: 4
Number of hardware threads (strands or vCPUs) per core: 1

** Socket-Core-vCPU mapping **

Physical Processor 1:
Core 1:
vCPU ids: 0-0
Core 2:
vCPU ids: 1-1
Core 3:
vCPU ids: 2-2
Core 4:
vCPU ids: 3-3

Physical Processor 2:
Core 1:
vCPU ids: 4-4
Core 2:
vCPU ids: 5-5
Core 3:
vCPU ids: 6-6
Core 4:
vCPU ids: 7-7

Posted by Rick on September 21, 2011 at 11:14 PM PDT #

thanks

Posted by guest on May 03, 2012 at 03:34 PM PDT #

Has anyone tried this on a T4 machine?
Here is what I get, it doesn't seem correct:

Total number of physical processors: 1
Number of virtual processors: 64
Total number of cores: 64
Number of cores per physical processor: 64
Number of hardware threads (strands or vCPUs) per core: 1
Processor speed: 2848 MHz (2.84 GHz)

Posted by guest on June 28, 2012 at 07:21 AM PDT #

guest: here is the output from a T4-1 box.

% prtconf | grep SPARC
ORCL,SPARC-T4-1

% ./showcpucount
Total number of physical processors: 1
Number of virtual processors: 64
Total number of cores: 8
Number of cores per physical processor: 8
Number of hardware threads (strands or vCPUs) per core: 8
Processor speed: 2848 MHz (2.84 GHz)

** Socket-Core-vCPU mapping **

Physical Processor 1 (chip id: 0):
Core 1 (core id: 514):
vCPU ids: 0 - 7
Core 2 (core id: 518):
vCPU ids: 8 - 15
Core 3 (core id: 522):
vCPU ids: 16 - 23
Core 4 (core id: 526):
vCPU ids: 24 - 31
Core 5 (core id: 530):
vCPU ids: 32 - 39
Core 6 (core id: 534):
vCPU ids: 40 - 47
Core 7 (core id: 538):
vCPU ids: 48 - 55
Core 8 (core id: 542):
vCPU ids: 56 - 63

Posted by Giri Mandalika on June 28, 2012 at 10:21 AM PDT #

Giri Mandalika: Which OS do you use on the T4-1 machine, Solaris 10 or 11?

Posted by guest on July 12, 2012 at 01:53 AM PDT #

guest: I have access to T4-1s running both Solaris 10 and 11 operating systems. In both cases, the output is consistent and reflects the actual CPU information.

On a related note, "psrinfo -pv" on Solaris 11 shows the core, vCPU breakdown -- so, we don't even need this script on Solaris 11

Posted by Giri Mandalika on July 12, 2012 at 08:11 PM PDT #

Hi,

May i know what is the fomula to calculate the number of virtual processors? Based on the result below, i can't seem to understand how it actually calculate that my virtual processors are 30. Pls kindly advise.

Total number of physical processors: 1
Number of virtual processors: 30
Total number of cores: 4
Number of cores per physical processor: 4
Number of hardware threads (strands or vCPUs) per core: 7
Processor speed: 1415 MHz (1.41 GHz)

** Socket-Core-vCPU mapping **

Physical Processor 1 (chip id: 0):
Core 1 (core id: 516):
vCPU ids: 0 - 6
Core 2 (core id: 516):
vCPU ids: 7 - 13
Core 3 (core id: 521):
vCPU ids: 14 - 20
Core 4 (core id: 526):
vCPU ids: 21 - 27

Posted by Terence on September 03, 2012 at 08:59 PM PDT #

Thanks,

Its very useful.

BR//

Posted by guest on April 30, 2013 at 02:06 AM PDT #

Hi,

On a M9000 :

psrinfo -pv
The physical processor has 8 virtual processors (0-7)
SPARC64-VII (portid 1024 impl 0x7 ver 0xa0 clock 2880 MHz)
The physical processor has 8 virtual processors (8-15)
SPARC64-VII (portid 1032 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (16-23)
SPARC64-VII (portid 1040 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (24-31)
SPARC64-VII (portid 1048 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (32-39)
SPARC64-VII (portid 1056 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (40-47)
SPARC64-VII (portid 1064 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (48-55)
SPARC64-VII (portid 1072 impl 0x7 ver 0xa1 clock 2880 MHz)
The physical processor has 8 virtual processors (56-63)
SPARC64-VII (portid 1080 impl 0x7 ver 0xa1 clock 2880 MHz)

./showcpucount
Total number of physical processors: 8
Number of virtual processors: 64
Total number of cores: 32
Number of cores per physical processor: 4
Number of hardware threads (strands or vCPUs) per core: 2
Processor speed: 2880 MHz (2.88 GHz)

Posted by Hartyshow on September 03, 2013 at 01:14 PM PDT #

Thanks for this script. It is definitely handy. However, this appears to show only details about the currently assigned hardware for the particular domain. I'm trying to determine what commands I can use to calculate the total capacity for hardware assignment, even after vpcus and memory have been assigned to other logical domains and including whatever has not been assigned.

In particular I'd like to be able to run a command to:
1) Calculate the total number of vcpus a server has across all logical domains and including those that are not assigned to any domain
2) Calculate the total amount of memory a server has across all logical domains and including any extra memory that has not been assigned to any domain

Does anyone have any suggestions?

Posted by guest on November 01, 2013 at 11:00 AM PDT #

To the last "guest":

When executed from a control/primary domain, "ldm list-devices -a" command lists out all the CPU/Core, memory, IO, Crypto resources that are available/assigned across the board on a supported SPARC server. (this command is the answer to both of your questions).

To find out which resources are currently available/unassigned, execute "ldm list-devices" (-? option shows the other arguments to limit the output to a specific resource).

"ldm list"(optionally with "-l" option for long listing) shows the current CPU, memory resource assignments to various domains configured on the system.

Please check the man page of ldm(1M) for the complete list of options and explanations.

Posted by Giri Mandalika on November 05, 2013 at 04:02 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Benchmark announcements, HOW-TOs, Tips and Troubleshooting

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today