summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Morph2023-03-03 20:54:15 -0500
committerGravatar Morph2023-03-05 02:36:31 -0500
commit026eaddbeef4d0a4992fb19b40af9242f09c3c6a (patch)
treed275b240a3871e5c7aa4ed944a6e8f3f3b3b79c3 /src
parentgeneral: Target Windows 10 SDK (diff)
downloadyuzu-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.cpp22
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
18NTSYSAPI LONG NTAPI NtDelayExecution(BOOLEAN Alertable, PLARGE_INTEGER DelayInterval); 18NTSYSAPI 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
21namespace Common::Windows { 30namespace Common::Windows {
22 31
23namespace { 32namespace {
@@ -51,6 +60,18 @@ TimerResolution GetTimerResolution() {
51 }; 60 };
52} 61}
53 62
63void 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
56nanoseconds GetMinimumTimerResolution() { 77nanoseconds GetMinimumTimerResolution() {
@@ -74,6 +95,7 @@ nanoseconds SetCurrentTimerResolution(nanoseconds timer_resolution) {
74} 95}
75 96
76nanoseconds SetCurrentTimerResolutionToMaximum() { 97nanoseconds SetCurrentTimerResolutionToMaximum() {
98 SetHighQoS();
77 return SetCurrentTimerResolution(GetMaximumTimerResolution()); 99 return SetCurrentTimerResolution(GetMaximumTimerResolution());
78} 100}
79 101