Revert "InitializeTimerResolution fix slowdown on Windows 10, drop obsolete workaround for Windows NT"

This reverts commit 4e5fd41be7.
This commit is contained in:
Adam Honse 2025-05-08 18:50:27 -05:00
parent 14d0388a65
commit aa66814c43

View file

@ -43,25 +43,30 @@ using namespace std::chrono_literals;
* *
\******************************************************************************************/
#ifdef _WIN32
typedef unsigned int NTSTATUS;
typedef NTSTATUS (*NTSETTIMERRESOLUTION)(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
void InitializeTimerResolution()
{
HMODULE ntdll = LoadLibrary("ntdll.dll");
if(ntdll != NULL)
{
typedef LONG (*NTSETTIMERRESOLUTION)(ULONG DesiredResolution, BOOLEAN SetResolution, PULONG CurrentResolution);
ULONG CurrentResolution;
NTSETTIMERRESOLUTION NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(ntdll, "NtSetTimerResolution");
if(NtSetTimerResolution != NULL)
{
NtSetTimerResolution(1000, TRUE, &CurrentResolution);
}
}
NTSETTIMERRESOLUTION NtSetTimerResolution;
HMODULE NtDllHandle;
ULONG CurrentResolution;
// PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION = 4, isn't defined in Win10 headers
PROCESS_POWER_THROTTLING_STATE PowerThrottlingState { PROCESS_POWER_THROTTLING_CURRENT_VERSION, 4, 0 };
// take care of the slowdown on Windows 11
SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottlingState, sizeof(PowerThrottlingState));
NtDllHandle = LoadLibrary("ntdll.dll");
NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(NtDllHandle, "NtSetTimerResolution");
NtSetTimerResolution(5000, TRUE, &CurrentResolution);
}
void InitializeTimerResolutionThreadFunction()
{
while(1)
{
InitializeTimerResolution();
std::this_thread::sleep_for(500ms);
}
}
#endif
@ -176,7 +181,9 @@ int main(int argc, char* argv[])
/*---------------------------------------------------------*\
| Windows only - Start timer resolution correction thread |
\*---------------------------------------------------------*/
InitializeTimerResolution();
std::thread * InitializeTimerResolutionThread;
InitializeTimerResolutionThread = new std::thread(InitializeTimerResolutionThreadFunction);
InitializeTimerResolutionThread->detach();
/*---------------------------------------------------------*\
| Windows only - Install SMBus Driver WinRing0 |