diff options
| author | 2023-03-03 20:54:15 -0500 | |
|---|---|---|
| committer | 2023-03-05 02:36:31 -0500 | |
| commit | 026eaddbeef4d0a4992fb19b40af9242f09c3c6a (patch) | |
| tree | d275b240a3871e5c7aa4ed944a6e8f3f3b3b79c3 /src | |
| parent | general: Target Windows 10 SDK (diff) | |
| download | yuzu-026eaddbeef4d0a4992fb19b40af9242f09c3c6a.tar.gz yuzu-026eaddbeef4d0a4992fb19b40af9242f09c3c6a.tar.xz yuzu-026eaddbeef4d0a4992fb19b40af9242f09c3c6a.zip | |
timer_resolution: Set current process to High QoS
Ensures that this process is treated as a high performance process by the Windows scheduler.
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/windows/timer_resolution.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/windows/timer_resolution.cpp b/src/common/windows/timer_resolution.cpp index 6c2063a4c..29c6e5c7e 100644 --- a/src/common/windows/timer_resolution.cpp +++ b/src/common/windows/timer_resolution.cpp | |||
| @@ -18,6 +18,15 @@ NTSYSAPI LONG NTAPI NtSetTimerResolution(ULONG DesiredResolution, BOOLEAN SetRes | |||
| 18 | NTSYSAPI LONG NTAPI NtDelayExecution(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval); | 18 | NTSYSAPI LONG NTAPI NtDelayExecution(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | // Defines for compatibility with older Windows 10 SDKs. | ||
| 22 | |||
| 23 | #ifndef PROCESS_POWER_THROTTLING_EXECUTION_SPEED | ||
| 24 | #define PROCESS_POWER_THROTTLING_EXECUTION_SPEED 0x1 | ||
| 25 | #endif | ||
| 26 | #ifndef PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION | ||
| 27 | #define PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION 0x4 | ||
| 28 | #endif | ||
| 29 | |||
| 21 | namespace Common::Windows { | 30 | namespace Common::Windows { |
| 22 | 31 | ||
| 23 | namespace { | 32 | namespace { |
| @@ -51,6 +60,18 @@ TimerResolution GetTimerResolution() { | |||
| 51 | }; | 60 | }; |
| 52 | } | 61 | } |
| 53 | 62 | ||
| 63 | void SetHighQoS() { | ||
| 64 | // https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service | ||
| 65 | PROCESS_POWER_THROTTLING_STATE PowerThrottling{ | ||
| 66 | .Version{PROCESS_POWER_THROTTLING_CURRENT_VERSION}, | ||
| 67 | .ControlMask{PROCESS_POWER_THROTTLING_EXECUTION_SPEED | | ||
| 68 | PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION}, | ||
| 69 | .StateMask{}, | ||
| 70 | }; | ||
| 71 | SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottling, | ||
| 72 | sizeof(PROCESS_POWER_THROTTLING_STATE)); | ||
| 73 | } | ||
| 74 | |||
| 54 | } // Anonymous namespace | 75 | } // Anonymous namespace |
| 55 | 76 | ||
| 56 | nanoseconds GetMinimumTimerResolution() { | 77 | nanoseconds GetMinimumTimerResolution() { |
| @@ -74,6 +95,7 @@ nanoseconds SetCurrentTimerResolution(nanoseconds timer_resolution) { | |||
| 74 | } | 95 | } |
| 75 | 96 | ||
| 76 | nanoseconds SetCurrentTimerResolutionToMaximum() { | 97 | nanoseconds SetCurrentTimerResolutionToMaximum() { |
| 98 | SetHighQoS(); | ||
| 77 | return SetCurrentTimerResolution(GetMaximumTimerResolution()); | 99 | return SetCurrentTimerResolution(GetMaximumTimerResolution()); |
| 78 | } | 100 | } |
| 79 | 101 | ||