windows 如何禁用动态频率缩放?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3975551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:26:44  来源:igfitidea点击:

How to Disable Dynamic Frequency Scaling?

c++windowsbenchmarkingcpu-speed

提问by martinus

I would like to do some microbenchmarks, and try to do them right. Unfortunately dynamic frequency scaling makes benchmarking highly unreliable.

我想做一些微基准测试,并尝试正确地完成它们。不幸的是,动态频率缩放使基准测试非常不可靠。

Is there a way to programmatically (C++, Windows) find out if dynamic frequency scaling is enabled? If, can this be disabled in a program?

有没有办法以编程方式(C++、Windows)找出是否启用了动态频率缩放?如果,可以在程序中禁用它吗?

Ive tried to just use a warmup phase that uses 100% CPU for a second before the actual benchmark takes place, but this turned out to be not reliable either.

我曾尝试在实际基准测试发生之前使用 100% CPU 一秒钟的预热阶段,但结果证明这也不可靠。

UPDATE: Even when I disable SpeedStep in the BIOS, cpu-z shows that the frequency changes between 1995 and 2826 GHz

更新:即使我在 BIOS 中禁用 SpeedStep,cpu-z 也显示频率在 1995 和 2826 GHz 之间变化

回答by Vantomex

In general, you need to do the following steps:

一般来说,您需要执行以下步骤:

  • Call CallNtPowerInformation()and pass SystemPowerCapabilitiesto InformationLevelparameter, set lpInputBufferand nInputBufferSizeto NULL, then set lpOutputBufferto SYSTEM_POWER_CAPABILITIESstructure, and set nOutputBufferSizeto the size of the structure. After this first call, SYSTEM_POWER_CAPABILITIESstructure containing the current system power capabilities. To check whether the system supports processor throttling, read the value of ProcessorThrottle.

  • There are other two members we are interested in, they are, ProcessorMinThrottleand ProcessorMaxThrottle; they represents the minimum and maximum level of system processor throttling supported, expressed as a percentage. If both members has already values 100%, this means CPU throttling is currently disabled, so you don't need to reconfigure it.

  • To disable CPU throttling, you need to set ProcessorMinThrottleand ProcessorMaxThrottleto 100%. To do this, call CallNtPowerInformation()again and pass SystemPowerCapabilitiesto InformationLevelparameter; but now, set lpInputBufferto the SYSTEM_POWER_CAPABILITIES structure in which the two members has been set to 100%. I'm sure you know what to do next.

  • 呼叫CallNtPowerInformation()并传递SystemPowerCapabilitiesInformationLevel参数,设定lpInputBuffernInputBufferSizeNULL,则设置lpOutputBufferSYSTEM_POWER_CAPABILITIES结构,并设置nOutputBufferSize到所述结构的尺寸。在第一次调用之后,SYSTEM_POWER_CAPABILITIES包含当前系统电源功能的结构。要检查系统是否支持处理器节流,请读取ProcessorThrottle的值。

  • 我们还对另外两个成员感兴趣,它们是ProcessorMinThrottleProcessorMaxThrottle;它们表示支持的系统处理器节流的最小和最大级别,以百分比表示。如果两个成员的值都为 100%,这意味着 CPU 节流当前已禁用,因此您无需重新配置它。

  • 要禁用 CPU 节流,您需要将ProcessorMinThrottleProcessorMaxThrottle设置为100%。为此,CallNtPowerInformation()再次调用并将SystemPowerCapabilities传递给InformationLevel参数;但是现在,将lpInputBuffer设置为SYSTEM_POWER_CAPABILITIES结构,其中两个成员已设置为100%。我相信你知道下一步该怎么做。

In non-programmatic way, you can also get/set Windows Power Optionsusing the Windows built-in command-line tools, that is, PowerCfg.

通过非编程方式,您还可以使用 Windows 内置命令行工具(即PowerCfg )获取/设置 Windows电源选项

Further Reading

进一步阅读

回答by Sebastian Graf

So far, none of the above CallNtPowerInformationoptions worked for me. The relevant ProcessorThrottlefield of SYSTEM_POWER_CAPABILITIESwas FALSEand changing some SYSTEM_POWER_POLICYs didn't work.

到目前为止,上述CallNtPowerInformation选项都不适合我。的相关ProcessorThrottle领域SYSTEM_POWER_CAPABILITIESFALSE,改变一些SYSTEM_POWER_POLICYs 不起作用。

However, https://www.geeks3d.com/20170213/how-to-disable-intel-turbo-boost-technology-on-a-notebook/#_24outlines a way to make an option available in the power management settings.

但是,https://www.geeks3d.com/20170213/how-to-disable-intel-turbo-boost-technology-on-a-notebook/#_24 概述了一种在电源管理设置中提供选项的方法。

With ProcMon, I was able to trace it back to the following registry manipulations:

使用 ProcMon,我能够将其追溯到以下注册表操作:

  1. Read the ActivePowerSchemeSZvalue under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemesto get the active power plan
  2. Set the ACSettingIndexand/or DCSettingIndexDWORDunder Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\<above active power plan GUID>\54533251-82be-4824-96c1-47b60b740d00\be337238-0d82-4146-a960-4f3749d470c7to 0 (Disabled, or whatever you choose) from 2 (High)
  1. 读取下面的ActivePowerSchemeSZHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes以获取活动电源计划
  2. ACSettingIndex和/或DCSettingIndexDWORD低于Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\User\PowerSchemes\<above active power plan GUID>\54533251-82be-4824-96c1-47b60b740d00\be337238-0d82-4146-a960-4f3749d470c72(高)设置为 0(禁用,或您选择的任何内容)

Unfortunately, the relevant keys are owned by the system, which either means you have to prompt the user (which has to have admin access) to change the permissions of the key or you have to use powercfgto manipulate the setting. The latter is preferrable and actually seems to work, even without admin access (courtesy of https://docs.microsoft.com/en-us/windows-server/administration/performance-tuning/hardware/power/power-performance-tuning#processor-performance-boost-mode):

不幸的是,相关密钥归系统所有,这意味着您必须提示用户(必须具有管理员访问权限)更改密钥的权限,或者您必须使用它powercfg来操作设置。后者更可取,实际上似乎也能工作,即使没有管理员访问权限(由https://docs.microsoft.com/en-us/windows-server/administration/performance-tuning/hardware/power/power-performance-tuning 提供) #processor-performance-boost-mode):

powercfg -setacvalueindex scheme_current sub_processor PERFBOOSTMODE 0
powercfg -setdcvalueindex scheme_current sub_processor PERFBOOSTMODE 0
powercfg -setactive scheme_current

回答by VladV

In Windows XP and later CPU speed is managed by power policy. Doesn't it turn off the scaling if you set "Max performance" mode in Windows power management dialog?

在 Windows XP 和更高版本中,CPU 速度由电源策略管理。如果在 Windows 电源管理对话框中设置“最大性能”模式,它不会关闭缩放吗?

There're also some third party tools - SpeedSwitchXPfor example.

还有一些第三方工具 -例如SpeedSwitchXP

Programmatically this could be done, I suppose, using CallNtPowerInformationfunction.

我想这可以通过编程方式完成,使用CallNtPowerInformation函数。