2

I had a situation with some code where it's come to my attention that the speed-stepping feature on modern processors might be an issue. While I guess I could have created a thread putting load on the processor to try and fix it (and some things I find indicate this isn't a good solution at all), I tried to find something more elegant that will disable the feature while the other code is running. Now I did some research and came across this, which helped to answer the question, and allowed me to come up with some code.

The problem I have is, being an enthusiast programmer with a limited budget, that I can't run out the door and purchase a computer with this feature in order to test whether it actually works or not. I tested these as far as I possibly could test them. So, I was wondering if someone with a computer that has the feature on it could tell me if they actually work?

// following code uses the definitions out of the JEDI project.
function GetCPUThrottle(var min, max: byte): Boolean;
// get CPU throttling info.
// min - minimum CPU throttle value, in % (1-100)
// max - maximum CPU throttle value, in % (1-100)
// Result - does CPU support throttling?
var
  PowerCap: TSystemPowerCapabilities;
  Status: NTSTATUS;
begin
  Result := false;
  Status := CallNtPowerInformation(SystemPowerCapabilities, nil, 0, @PowerCap,
            SizeOf(PowerCap));
  if Status = STATUS_SUCCESS then
    begin
      Result := PowerCap.ProcessorThrottle;
      min := PowerCap.ProcessorMinThrottle;
      max := PowerCap.ProcessorMaxThrottle;
    end;
end;

function SetCPUThrottle(min, max: byte): Boolean;
  // set CPU throttling info.
  // min - minimum CPU throttle value, in % (1-100)
  // max - maximum CPU throttle value, in % (1-100)
  // Result - does CPU support throttling, AND was the values set?
var
  PowerCap: TSystemPowerCapabilities;
  Status: NTSTATUS;
begin
  Result := false;
  Status := CallNtPowerInformation(SystemPowerCapabilities, nil, 0, @PowerCap,
            SizeOf(PowerCap));
  if Status = STATUS_SUCCESS then
    begin
      if PowerCap.ProcessorThrottle then
        begin
          PowerCap.ProcessorMinThrottle := min;
          PowerCap.ProcessorMaxThrottle := max;
          Status :=  CallNtPowerInformation(SystemPowerCapabilities, @PowerCap,
              SizeOf(PowerCap), nil, 0);
          if Status = STATUS_SUCCESS then
            Result := true;
        end;
    end;
end;
Community
  • 1
  • 1
Glenn1234
  • 2,482
  • 1
  • 14
  • 20

0 Answers0