From: Doug Coleman Date: Sun, 31 Jan 2021 04:35:06 +0000 (-0600) Subject: windows: Add cpu-mhz on Windows X-Git-Tag: 0.99~2634 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=3a7e4c7cda61f6679d383ff07d9162a5137add44 windows: Add cpu-mhz on Windows --- diff --git a/basis/system-info/windows/windows.factor b/basis/system-info/windows/windows.factor index d9f9317fb8..7e344d3c57 100644 --- a/basis/system-info/windows/windows.factor +++ b/basis/system-info/windows/windows.factor @@ -2,9 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.strings arrays byte-arrays classes.struct combinators kernel math -namespaces specialized-arrays system -vocabs.loader windows windows.advapi32 -windows.errors windows.kernel32 words system-info ; +namespaces sequences specialized-arrays +specialized-arrays.instances.alien.c-types.ushort system +system-info vocabs.loader windows windows.advapi32 +windows.errors windows.kernel32 windows.powrprof words ; SPECIALIZED-ARRAY: ushort IN: system-info.windows @@ -70,6 +71,9 @@ M: windows os-version M: windows cpus system-info dwNumberOfProcessors>> ; +M: windows cpu-mhz + get-processor-power-information first MaxMhz>> 1,000,000 * ; + : memory-status ( -- MEMORYSTATUSEX ) MEMORYSTATUSEX MEMORYSTATUSEX heap-size >>dwLength diff --git a/basis/windows/powrprof/authors.txt b/basis/windows/powrprof/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/basis/windows/powrprof/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/basis/windows/powrprof/powrprof.factor b/basis/windows/powrprof/powrprof.factor new file mode 100644 index 0000000000..9460fd3502 --- /dev/null +++ b/basis/windows/powrprof/powrprof.factor @@ -0,0 +1,255 @@ +! Copyright (C) 2021 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types alien.syntax classes.struct kernel math +specialized-arrays system-info windows.errors windows.types +windows.user32 ; +IN: windows.powrprof + +LIBRARY: powrprof + +TYPEDEF: UINT NTSTATUS +TYPEDEF: void* PHPOWERNOTIFY + +CONSTANT: STATUS_SUCCESS 0 + +ENUM: SYSTEM_POWER_STATE + PowerSystemUnspecified + PowerSystemWorking + PowerSystemSleeping1 + PowerSystemSleeping2 + PowerSystemSleeping3 + PowerSystemHibernate + PowerSystemShutdown + PowerSystemMaximum ; +TYPEDEF: SYSTEM_POWER_STATE* PSYSTEM_POWER_STATE + +ENUM: POWER_PLATFORM_ROLE + PlatformRoleUnspecified + PlatformRoleDesktop + PlatformRoleMobile + PlatformRoleWorkstation + PlatformRoleEnterpriseServer + PlatformRoleSOHOServer + PlatformRoleAppliancePC + PlatformRolePerformanceServer + PlatformRoleSlate + PlatformRoleMaximum ; +TYPEDEF: POWER_PLATFORM_ROLE* PPOWER_PLATFORM_ROLE + +ENUM: POWER_INFORMATION_LEVEL + SystemPowerPolicyAc + SystemPowerPolicyDc + VerifySystemPolicyAc + VerifySystemPolicyDc + SystemPowerCapabilities + SystemBatteryState + SystemPowerStateHandler + ProcessorStateHandler + SystemPowerPolicyCurrent + AdministratorPowerPolicy + SystemReserveHiberFile + ProcessorInformation + SystemPowerInformation + ProcessorStateHandler2 + LastWakeTime + LastSleepTime + SystemExecutionState + SystemPowerStateNotifyHandler + ProcessorPowerPolicyAc + ProcessorPowerPolicyDc + VerifyProcessorPowerPolicyAc + VerifyProcessorPowerPolicyDc + ProcessorPowerPolicyCurrent + SystemPowerStateLogging + SystemPowerLoggingEntry + SetPowerSettingValue + NotifyUserPowerSetting + PowerInformationLevelUnused0 + SystemMonitorHiberBootPowerOff + SystemVideoState + TraceApplicationPowerMessage + TraceApplicationPowerMessageEnd + ProcessorPerfStates + ProcessorIdleStates + ProcessorCap + SystemWakeSource + SystemHiberFileInformation + TraceServicePowerMessage + ProcessorLoad + PowerShutdownNotification + MonitorCapabilities + SessionPowerInit + SessionDisplayState + PowerRequestCreate + PowerRequestAction + GetPowerRequestList + ProcessorInformationEx + NotifyUserModeLegacyPowerEvent + GroupPark + ProcessorIdleDomains + WakeTimerList + SystemHiberFileSize + ProcessorIdleStatesHv + ProcessorPerfStatesHv + ProcessorPerfCapHv + ProcessorSetIdle + LogicalProcessorIdling + UserPresence + PowerSettingNotificationName + GetPowerSettingValue + IdleResiliency + SessionRITState + SessionConnectNotification + SessionPowerCleanup + SessionLockState + SystemHiberbootState + PlatformInformation + PdcInvocation + MonitorInvocation + FirmwareTableInformationRegistered + SetShutdownSelectedTime + SuspendResumeInvocation + PlmPowerRequestCreate + ScreenOff + CsDeviceNotification + PlatformRole + LastResumePerformance + DisplayBurst + ExitLatencySamplingPercentage + RegisterSpmPowerSettings + PlatformIdleStates + ProcessorIdleVeto + PlatformIdleVeto + SystemBatteryStatePrecise + ThermalEvent + PowerRequestActionInternal + BatteryDeviceState + PowerInformationInternal + ThermalStandby + SystemHiberFileType + PhysicalPowerButtonPress + QueryPotentialDripsConstraint + EnergyTrackerCreate + EnergyTrackerQuery + UpdateBlackBoxRecorder + SessionAllowExternalDmaDevices + SendSuspendResumeNotification + PowerInformationLevelMaximum ; + +STRUCT: BATTERY_REPORTING_SCALE + { Granularity DWORD } + { Capacity DWORD } ; +TYPEDEF: BATTERY_REPORTING_SCALE* PBATTERY_REPORTING_SCALE + + +STRUCT: PROCESSOR_POWER_INFORMATION + { Number ULONG } + { MaxMhz ULONG } + { CurrentMhz ULONG } + { MhzLimit ULONG } + { MaxIdleState ULONG } + { CurrentIdleState ULONG } ; +TYPEDEF: PROCESSOR_POWER_INFORMATION* PPROCESSOR_POWER_INFORMATION + +STRUCT: SYSTEM_POWER_CAPABILITIES + { PowerButtonPresent BOOLEAN } + { SleepButtonPresent BOOLEAN } + { LidPresent BOOLEAN } + { SystemS1 BOOLEAN } + { SystemS2 BOOLEAN } + { SystemS3 BOOLEAN } + { SystemS4 BOOLEAN } + { SystemS5 BOOLEAN } + { HiberFilePresent BOOLEAN } + { FullWake BOOLEAN } + { VideoDimPresent BOOLEAN } + { ApmPresent BOOLEAN } + { UpsPresent BOOLEAN } + { ThermalControl BOOLEAN } + { ProcessorThrottle BOOLEAN } + { ProcessorMinThrottle BYTE } + { ProcessorThrottleScale BYTE } + { spare2 BYTE[4] } + { ProcessorMaxThrottle BYTE } + { FastSystemS4 BOOLEAN } + { Hiberboot BOOLEAN } + { WakeAlarmPresent BOOLEAN } + { AoAc BOOLEAN } + { DiskSpinDown BOOLEAN } + { spare3 BYTE[8] } + { HiberFileType BYTE } + { AoAcConnectivitySupported BOOLEAN } +! #else +! BYTE spare3[6]; +! #endif + { SystemBatteriesPresent BOOLEAN } + { BatteriesAreShortTerm BOOLEAN } + { BatteryScale BATTERY_REPORTING_SCALE[3] } + { AcOnLineWake SYSTEM_POWER_STATE } + { SoftLidWake SYSTEM_POWER_STATE } + { RtcWake SYSTEM_POWER_STATE } + { MinDeviceWakeState SYSTEM_POWER_STATE } + { DefaultLowLatencyWake SYSTEM_POWER_STATE } ; +TYPEDEF: SYSTEM_POWER_CAPABILITIES* PSYSTEM_POWER_CAPABILITIES + +STRUCT: SYSTEM_BATTERY_STATE + { AcOnLine BOOLEAN } + { BatteryPresent BOOLEAN } + { Charging BOOLEAN } + { Discharging BOOLEAN } + { Spare1 BOOLEAN[3] } + { Tag BYTE } + { MaxCapacity DWORD } + { RemainingCapacity DWORD } + { Rate DWORD } + { EstimatedTime DWORD } + { DefaultAlert1 DWORD } + { DefaultAlert2 DWORD } ; +TYPEDEF: SYSTEM_BATTERY_STATE* PSYSTEM_BATTERY_STATE + +STRUCT: SYSTEM_POWER_INFORMATION + { MaxIdlenessAllowed ULONG } + { Idleness ULONG } + { TimeRemaining ULONG } + { CoolingMode UCHAR } ; +TYPEDEF: SYSTEM_POWER_INFORMATION* PSYSTEM_POWER_INFORMATION + + +SPECIALIZED-ARRAY: PROCESSOR_POWER_INFORMATION + +FUNCTION: NTSTATUS CallNtPowerInformation ( + POWER_INFORMATION_LEVEL InformationLevel + PVOID InputBuffer, + ULONG InputBufferLength, + PVOID OutputBuffer, + ULONG OutputBufferLength +) + +FUNCTION: BOOLEAN GetPwrCapabilities ( + PSYSTEM_POWER_CAPABILITIES lpspc +) + +FUNCTION: POWER_PLATFORM_ROLE PowerDeterminePlatformRoleEx ( + ULONG Version +) +FUNCTION: DWORD PowerRegisterSuspendResumeNotification ( + DWORD Flags, + HANDLE Recipient, + PHPOWERNOTIFY RegistrationHandle +) +FUNCTION: DWORD PowerUnregisterSuspendResumeNotification ( + HPOWERNOTIFY RegistrationHandle +) + +: get-processor-power-information ( -- structs ) + ProcessorInformation + f 0 + cpus + PROCESSOR_POWER_INFORMATION heap-size cpus * + [ + CallNtPowerInformation win32-error=0/f + ] keepd ; + +: get-power-capabilities ( -- struct ) + SYSTEM_POWER_CAPABILITIES + [ GetPwrCapabilities win32-error=0/f ] keep ; diff --git a/basis/windows/windows.factor b/basis/windows/windows.factor index 938ceae370..56c836a185 100644 --- a/basis/windows/windows.factor +++ b/basis/windows/windows.factor @@ -26,4 +26,5 @@ CONSTANT: MAX_UNICODE_PATH 32768 { "winmm" "winmm.dll" stdcall } { "ntdll" "ntdll.dll" stdcall } { "crypt32" "crypt32.dll" stdcall } + { "powrprof" "powrprof.dll" stdcall } } [ first3 add-library ] each