From b473c3587388e06823c153c4fecc2104bcafedff Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 18 Jul 2022 00:20:26 -0700 Subject: [PATCH] windows: mark as HighQoS, ensure timer resolution is honored --- Source/Core/Common/Timer.cpp | 16 ++++++++++++++++ Source/Core/Common/Timer.h | 1 + 2 files changed, 17 insertions(+) diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index ef910f6c27..3d2a2ed777 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -102,6 +102,22 @@ u64 Timer::GetLocalTimeSinceJan1970() void Timer::IncreaseResolution() { #ifdef _WIN32 + // Disable execution speed and timer resolution throttling process-wide. + // This mainly will keep Dolphin marked as high performance if it's in the background. The OS + // should make it high performance if it's in the foreground anyway (or for some specific + // threads e.g. audio). + // This is best-effort (i.e. the call may fail on older versions of Windows, where such throttling + // doesn't exist, anyway), and we don't bother reverting once set. + // This adjusts behavior on CPUs with "performance" and "efficiency" cores + PROCESS_POWER_THROTTLING_STATE PowerThrottling{}; + PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION; + PowerThrottling.ControlMask = + PROCESS_POWER_THROTTLING_EXECUTION_SPEED | PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION; + PowerThrottling.StateMask = 0; + SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottling, + sizeof(PowerThrottling)); + + // Not actually sure how useful this is these days.. :') timeBeginPeriod(1); #endif } diff --git a/Source/Core/Common/Timer.h b/Source/Core/Common/Timer.h index 0d357aff2b..cf194e773e 100644 --- a/Source/Core/Common/Timer.h +++ b/Source/Core/Common/Timer.h @@ -21,6 +21,7 @@ public: bool IsRunning() const { return m_running; } u64 ElapsedMs() const; + // The rest of these functions probably belong somewhere else static u64 GetLocalTimeSinceJan1970(); static void IncreaseResolution();