Wrong number of logical processors

delphi package - automated exception handling
Post Reply
Han312
Posts: 54
Joined: Mon Mar 14, 2016 3:49 pm

Wrong number of logical processors

Post by Han312 »

Within of a report we got:
processors : 16x AMD Ryzen 9 3900X 12-Core Processor
The 16x seems to be wrong.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong number of logical processors

Post by madshi »

Maybe you can debug the code on your side?

Code: Select all

function GetCpuCount : integer;
var i1 : integer;
begin
  result := 16;
  for i1 := 1 to 15 do
    if RegReadStr(HKEY_LOCAL_MACHINE, 'hardware\description\system\centralProcessor\' + IntToStrExW(i1), 'ProcessorNameString') = '' then begin
      result := i1;
      break;
    end;
end;
Han312
Posts: 54
Joined: Mon Mar 14, 2016 3:49 pm

Re: Wrong number of logical processors

Post by Han312 »

There are values for 0 to 23.

So you shouldn't stop at 15.
Since you check for an empty string a simple inc( i1 ) should also do?

I guess that cpu with more than 8 cores will become more and more common.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong number of logical processors

Post by madshi »

Ah, makes perfect sense, I'll change the code accordingly.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong number of logical processors

Post by madshi »

New version, should support up to 256 cores:

Code: Select all

function GetCpuCount : integer;
var i1, i2 : integer;
begin
  result := 256;
  for i1 := 0 to 15 do
    if RegReadStr(HKEY_LOCAL_MACHINE, 'hardware\description\system\centralProcessor\' + IntToStrExW(i1 * 16 + 16), 'ProcessorNameString') = '' then begin
      result := i1 * 16 + 16;
      for i2 := 1 to 15 do
        if RegReadStr(HKEY_LOCAL_MACHINE, 'hardware\description\system\centralProcessor\' + IntToStrExW(i1 * 16 + i2), 'ProcessorNameString') = '' then begin
          result := i1 * 16 + i2;
          break;
        end;
      break;
    end;
end;
Post Reply