Skip to content

Disable Windows background power and timer throttling (#568) - #667

Open
psieg wants to merge 2 commits into
masterfrom
fix/568-win-power-throttling
Open

psieg wants to merge 2 commits into
masterfrom
fix/568-win-power-throttling

Conversation

@psieg

@psieg psieg commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Addresses #568.

Background

On Windows 11 (especially on hybrid P/E-core CPUs), hiding SettingsWindow to the system tray leaves Prismatik without visible top-level windows. Windows treats background windowless processes as eligible for EcoQoS execution-speed throttling (PROCESS_POWER_THROTTLING_EXECUTION_SPEED) and timer-resolution throttling (PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION), which can degrade grabber loop cadence and frame updates when running behind fullscreen/heavy games.

Changes

  • Added Software/src/WindowsPowerThrottling.hpp (registered in Software/src/src.pro and Software/tests/tests.pro):
    • Provides platform-independent power-throttling decision, fallback, and logging logic (WindowsPowerThrottling::disablePowerThrottling, WindowsPowerThrottling::logPowerThrottlingResult) using fixed-width types and an injectable SetProcessInformationFn callback.
    • Under #ifdef Q_OS_WIN, WindowsPowerThrottling::disableWindowsPowerThrottling() dynamically resolves SetProcessInformation from kernel32.dll via GetModuleHandleW + GetProcAddress (with -Wcast-function-type guarded for Clang/GCC) for compatibility across Windows 7+ and different Windows SDK / MinGW / MSVC toolchains.
    • Uses ProcessPowerThrottling directly when PROCESS_POWER_THROTTLING_CURRENT_VERSION is defined by the Windows SDK and enforces ABI alignment at compile time with static_assert checks against ProcessPowerThrottling, PROCESS_POWER_THROTTLING_CURRENT_VERSION, PROCESS_POWER_THROTTLING_EXECUTION_SPEED, PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION, and sizeof(NativePowerThrottlingState).
    • Attempts to disable both execution-speed (EcoQoS) and timer-resolution throttling (ControlMask = 0x1 | 0x4, StateMask = 0); falls back to disabling execution-speed throttling only (ControlMask = 0x1, StateMask = 0) when the combined call fails (e.g., Windows 10 RS3+ returning ERROR_INVALID_PARAMETER for IGNORE_TIMER_RESOLUTION).
    • Treats ERROR_INVALID_PARAMETER (87) on both the initial and fallback calls (e.g., Windows 8 / 8.1 / pre-RS3 Windows 10) as Status::Unsupported logged via qDebug(), while retaining qWarning() (Status::Failed) for unexpected errors such as ERROR_ACCESS_DENIED.
  • Updated Software/src/main.cpp under #ifdef Q_OS_WIN to invoke WindowsPowerThrottling::disableWindowsPowerThrottling() during startup (mirroring macOS's NSActivityLatencyCritical opt-out) and log the result via WindowsPowerThrottling::logPowerThrottlingResult() once LogWriter has initialized.
  • Added Software/tests/WindowsPowerThrottlingTest.hpp and Software/tests/WindowsPowerThrottlingTest.cpp (registered in Software/tests/TestsMain.cpp and Software/tests/tests.pro) covering DisabledAll, DisabledExecutionSpeedOnly, Unavailable, Unsupported, Failed error combinations, log severity (qDebug vs qWarning), and state layout/constants across all platforms.

Verification

  • Built Prismatik and LightpackTests on Linux (qmake6 -r && make -j2) and ran QT_QPA_PLATFORM=offscreen ./bin/LightpackTests (all 9 test suites passed, 0 failed, 0 skipped, including WindowsPowerThrottlingTest: 8 passed).
  • Compiled and executed simulated #ifdef Q_OS_WIN Windows 11, Windows 10 RS3, and legacy Windows SDK scenarios with g++ -std=c++17 -Wall -Wextra -Wsign-compare -Wcast-function-type -Werror.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant