This demo obtains the current CPU power state (if SpeedStep is enabled and the Power Scheme is Minimal, it should show "dynamic throttling").
It also shows (and this 'should' work for any CPU on Windows 2000 or above) the maximum MHz and current MHz for each CPU in the system. On mine, with dynamic throttling enabled and low CPU usage, it correctly shows the current stepped-down speed. Running a CPU-hogging demo showed the cores stepping up (separately, interestingly, and it took a few seconds before they did so).
Not exactly sure if this is any use at all, but it was fun anyway. I *think* the demo will run on 2000, but you won't see the current power setting, that's all. If any of this doesn't work... oh well.

Code: Select all
; Obtain CPU power state (XP only) and other useful information (2000 or above)...
; For PB 4...
; *** DEMO REQUIRES DEBUG ON! ***
; Processor Performance Control Policy Structures...
Structure PROCESSOR_POWER_POLICY_INFO
TimeCheck.l
DemoteLimit.l
PromoteLimit.l
DemotePercent.c
PromotePercent.c
Spare.c[2]
AllowDemotion.l
AllowPromotion.l
Reserved.l
EndStructure
Structure PROCESSOR_POWER_POLICY
Revision.l
DynamicThrottle.b
Spare.b[3]
DisableCStates.l
Reserved.l
PolicyCount.l
Policy.PROCESSOR_POWER_POLICY_INFO[3]
EndStructure
Structure MACHINE_PROCESSOR_POWER_POLICY
Revision.l
ProcessorPolicyAc.PROCESSOR_POWER_POLICY
ProcessorPolicyDc.PROCESSOR_POWER_POLICY
EndStructure
Structure PROCESSOR_POWER_INFORMATION
Number.l
MaxMhz.l
CurrentMhz.l
MhzLimit.l
MaxIdleState.l
CurrentIdleState.l
EndStructure
; Processor Performance Control Policy Constants...
#PO_THROTTLE_NONE = 0
#PO_THROTTLE_CONSTANT = 1
#PO_THROTTLE_DEGRADE = 2
#PO_THROTTLE_ADAPTIVE = 3
Dim PowerState.s (3)
PowerState (0) = "No throttling"
PowerState (1) = "Constant throttling"
PowerState (2) = "Throttling according to battery, heat, etc"
PowerState (3) = "Dynamic throttling"
; D e m o . . .
Debug ""
; Power Management API reference:
; http://msdn2.microsoft.com/en-us/library/aa373163.aspx
pwr = OpenLibrary (#PB_Any, "powrprof.dll")
If pwr
; Get functions...
GetActivePwrScheme = GetFunction (pwr, "GetActivePwrScheme") ; Requires 2000 or above
CallNtPowerInformation = GetFunction (pwr, "CallNtPowerInformation") ; Requires 2000 or above
ReadProcessorPwrScheme = GetFunction (pwr, "ReadProcessorPwrScheme") ; Requires *XP* or above
; Get number of CPUs...
GetSystemInfo_ (sys.SYSTEM_INFO)
cpus = sys\dwNumberOfProcessors
; Prepare buffer(s) for information...
buffsize = SizeOf (PROCESSOR_POWER_INFORMATION) * cpus
Dim buffer.PROCESSOR_POWER_INFORMATION (cpus - 1)
; Get CPU information...
CallFunctionFast (CallNtPowerInformation, 11, #Null, #Null, @buffer (0), buffsize)
; Show CPU information...
For cpu = 0 To cpus - 1
Debug "CPU: " + Str (buffer (cpu)\Number)
Debug ""
Debug "Max MHz: " + Str (buffer (cpu)\MaxMhz)
Debug "Current MHz: " + Str (buffer (cpu)\CurrentMhz)
Debug "MHz Limit: " + Str (buffer (cpu)\MhzLimit)
Debug "Max idle state: " + Str (buffer (cpu)\MaxIdleState)
Debug "Current idle state: " + Str (buffer (cpu)\CurrentIdleState)
Debug ""
Next
; Get CPU power state (XP only due to ReadProcessorPwrScheme () call)...
If CallFunctionFast (GetActivePwrScheme, @pwrid)
If ReadProcessorPwrScheme ; Should be Null on < XP!
CallFunctionFast (ReadProcessorPwrScheme, pwrid, @policy.MACHINE_PROCESSOR_POWER_POLICY)
Debug "CPU power state: " + PowerState (policy\ProcessorPolicyAc\DynamicThrottle)
EndIf
EndIf
CloseLibrary (pwr)
EndIf
Debug ""