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,542
  • 1
  • 16
  • 21
  • What problem are you trying to tackle? – David Heffernan Feb 28 '13 at 16:44
  • 1
    @DavidHeffernan the actual code the person had issue with runs another program (a game, after doing a few things in my code). The game then uses the current CPU timing to determine its speed of execution. The problem comes when the CPU scales down, resulting in the game not working properly. Hence, the issue is stopping the CPU from doing that. – Glenn1234 Feb 28 '13 at 16:50
  • 2
    In other words, your question is "Could someone please test my code for me?" That's not really what Stack Overflow is for. Get in contact with some of the people who reported the bug to you, and ask them to test your program. – Rob Kennedy Feb 28 '13 at 17:29
  • If I test your code, what should I see? – Gabriel Feb 28 '13 at 18:38
  • sorry, your code does not compile on XE. – Gabriel Feb 28 '13 at 18:44
  • @Altar it will compile fine on XE, the problem is that you are missing part of the code – David Heffernan Feb 28 '13 at 19:11
  • 1
    @david - which means... it doesn't compile – Gabriel Feb 28 '13 at 19:57
  • 1
    @altar I'm making the distinction between code that compiles and code that is incomplete. It's nothing at all to do with Delphi version. – David Heffernan Feb 28 '13 at 20:07

0 Answers0