Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Total Number of Cores from a computer WITHOUT HyperThreading

This is a tough one.

I need to use a command to output the exact number of cores from my servers.

My tests:

  • X: On a Windows server with 4 processors (sockets) and 2 cores each without HT.
  • Y: On a Windows Server with 2 processors (sockets) and 6 cores each with HT.

GetSystemInfo only gets me the number of processors installed: 4 for X, 2 for Y.

|                | X: 8 cores  | Y: 12 cores |
|                | 4x2 (no HT) | 2x6 (HT)    |
|----------------|-------------|-------------|
| Desired output | 8           | 12          |
| GetSystemInfo  | 4           | 2           | 

%NUMBER_OF_PROCESSORS% is a good one, but it takes HT into account. It tells me 8 for X and 24 for Y (since it has HT, I needed it to show 12 instead).

|                        | X: 8 cores  | Y: 12 cores |
|                        | 4x2 (no HT) | 2x6 (HT)    |
|------------------------|-------------|-------------|
| Desired output         | 8           | 12          |
| GetSystemInfo          | 4           | 2           | 
| %NUMBER_OF_PROCESSORS% | 8           | 24          |

"wmic cpu get NumberOfCores" gets me info for each socket. For example:

X:

>wmic cpu get NumberOfCores
NumberOfCores
2
2
2
2

Y:

>wmic cpu get NumberOfCores
NumberOfCores
6
6

Meaning

|                            | X: 8 cores  | Y: 12 cores |
|                            | 4x2 (no HT) | 2x6 (HT)    |
|----------------------------|-------------|-------------|
| Desired output             | 8           | 12          |
| GetSystemInfo              | 4           | 2           | 
| %NUMBER_OF_PROCESSORS%     | 8           | 24          |
| wmic cpu get NumberOfCores | 2,2,2,2     | 6,6         |

Sigh.

I wished to keep it simple, inside the CMD, but I'm thinking about starting a Powershell script to do all that math and stuff.

Any thoughts?

like image 559
David Lago Avatar asked Sep 01 '16 14:09

David Lago


2 Answers

You can use Get-ComputerInfo and scope to the property you want.

$processor = Get-ComputerInfo -Property CsProcessors
$processor.CsProcessors

That should give you something like

Name                      : Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Manufacturer              : GenuineIntel
Description               : Intel64 Family 6 Model 78 Stepping 3
Architecture              : x64
AddressWidth              : 64
DataWidth                 : 64
MaxClockSpeed             : 2808
CurrentClockSpeed         : 2607
NumberOfCores             : 2 <== that one
NumberOfLogicalProcessors : 4 
…
…

Then, just look for NumberOfCores in the results.

like image 188
JKmeister Avatar answered Oct 18 '22 08:10

JKmeister


suggested command does not work on computer with mote than 64 logical cores

(Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors

provide number of logical cores (HT cores)

like image 32
Syc Avatar answered Oct 18 '22 08:10

Syc