windows: mark as HighQoS, ensure timer resolution is honored

This commit is contained in:
Shawn Hoffman 2022-07-18 00:20:26 -07:00
parent 3384b1385e
commit b473c35873
2 changed files with 17 additions and 0 deletions

View File

@ -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
}

View File

@ -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();