最近のプロセッサの速度ステッピング機能が問題である可能性があることに気付いたいくつかのコードで状況がありました。プロセッサに負荷をかけて修正するスレッドを作成することもできたと思いますが (これはまったく適切な解決策ではないことを示すものもあります)、機能を無効にするよりエレガントなものを見つけようとしましたが、他のコードが実行されています。今、私はいくつかの調査を行い、これに出くわしました。これは質問に答えるのに役立ち、いくつかのコードを思いつくことができました.
私が抱えている問題は、予算が限られている熱心なプログラマーであるため、実際に機能するかどうかをテストするために、この機能を備えたコンピューターをすぐに購入することができないことです。私は可能な限りこれらをテストしました。それで、その機能を備えたコンピューターを持っている人が、実際に機能するかどうか教えてくれるのではないかと思っていましたか?
// 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;