delphicpuhyperthreadingsystem-information

How to get correct number of logical processors


In Delphi, we need to know the number of CPUs for parallelization. Until now, we have used the GetNativeSystemInfo() function, which has worked fine, also with servers with hyperthreading.

But now, we have a server (Intel Xeon Gold 6230) with 40 physical processors and 80 logical processors with hyperthreading, and GetNativeSystemInfo() only shows 40 CPUs.

We made a small test program that uses 3 calls:

  1. GetNativeSystemInfo()

  2. GetLogicalProcessorInformation() (code from How to detect number of logical and physical processors efficiently?)

  3. And looking into the Registry for number of CPUs:

    Computer\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor

For all of our servers, these 3 calls give the same number of CPUs:

image

But for the Intel Xeon, only the Registry gives us the 80 CPUs:

image

Does anybody know why it is not working for the Intel server, or know a way to be sure to get the max number of CPUs?


Solution

  • To query logical processor count greater than 64, you have to use the newer GetLogicalProcessorInformationEx API, which the NumCPULib4Pascal library wraps in an easy-to-use manner.

    Unfortunately, I can't paste the full code here because it won't fit the word limit of StackOverflow.

    Sample usage below:

    uses
      NumCPULib;
    
    var
      lcc, pcc: Int32;
    begin
      // count logical cpus
     lcc := TNumCPULib.GetLogicalCPUCount();
      // count physical cpus
     pcc := TNumCPULib.GetPhysicalCPUCount();
    end;