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

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.

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.

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.

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

# 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

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)

% ./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)

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)

./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)

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

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.

Anyone know why some machines/OSs don't return core_id from the kstat output? This results in the script incorrectly determining the number of cores and number of threads per core. I think this is what the person with the T4 that posted on June 28, 2012 encountered.