Jump to content
wxinix

Any Delphi library for setting E-Core and P-Core Affinity for a process?

Recommended Posts

I wonder if there is any existing Delphi library for setting E-Core and P-Core Affinity?

Share this post


Link to post

I made some times ago this to retrive the p-core (I think is similar to that used in the post from @Anders Melander ) :
 

use Windows.System.SystemInformation; //this come from WINMD (getit)

//Result = 0 	--> No Hybrid system
//Result = -1 	--> DIFFERENT RECORD LENGTH (API VERSION OLD OR NEW)
//Result = -2 	--> API Error
//Result > 0	--> mask with Power Core (no more than 63 core, or the result type should be change)
//Tested only with Intel x64 CPU (no Xeon, no Numa system)
function GetCPUPowerArray: INT64;
var CPUInfoSet: TArray<SYSTEM_CPU_SET_INFORMATION>;
    dwlengthsize: ULong;
begin
  Result := 0;
  dwlengthsize := 0;
  setlength(CPUInfoSet, 0);
  GetSystemCpuSetInformation(nil, 0, dwlengthsize, 0, nil);
  if (dwlengthsize <= 0) then
    begin
      Result := -2;
      exit;
    end;
  if ((dwlengthsize mod sizeof(SYSTEM_CPU_SET_INFORMATION)) <> 0) then
    begin
      Result := -1;
      exit;
    end;
  setlength(CPUInfoSet, dwlengthsize div sizeof(SYSTEM_CPU_SET_INFORMATION));
  GetSystemCpuSetInformation(@CPUInfoSet[0], dwlengthsize, dwlengthsize, 0, nil);
  for var i := Low(CpuInfoSet) to High(CpuInfoSet) do
    if (CpuInfoSet[i].CpuSet.EfficiencyClass > 0) and (i < (sizeof(INT64)*8 -1)) then
      begin
        Result := Result or (1 shl i);
      end;
  setlength(CPUInfoSet, 0);
end;

 

Edited by DelphiUdIT
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×