diff --git a/src/common/steady_clock.cpp b/src/common/steady_clock.cpp index 9415eed29..771c8a91c 100644 --- a/src/common/steady_clock.cpp +++ b/src/common/steady_clock.cpp @@ -24,6 +24,7 @@ static s64 WindowsQueryPerformanceCounter() { return counter.QuadPart; } +#if (_WIN32_WINNT > _WIN32_WINNT_WIN7) static s64 GetSystemTimeNS() { // GetSystemTimePreciseAsFileTime returns the file time in 100ns units. static constexpr s64 Multiplier = 100; @@ -36,6 +37,7 @@ static s64 GetSystemTimeNS() { static_cast(filetime.dwLowDateTime) - WindowsEpochToUnixEpoch); } #endif +#endif SteadyClock::time_point SteadyClock::Now() noexcept { #if defined(_WIN32) @@ -65,6 +67,7 @@ SteadyClock::time_point SteadyClock::Now() noexcept { #endif } +#if (_WIN32_WINNT > _WIN32_WINNT_WIN7) RealTimeClock::time_point RealTimeClock::Now() noexcept { #if defined(_WIN32) return time_point{duration{GetSystemTimeNS()}}; @@ -76,5 +79,6 @@ RealTimeClock::time_point RealTimeClock::Now() noexcept { return time_point{std::chrono::seconds{ts.tv_sec} + std::chrono::nanoseconds{ts.tv_nsec}}; #endif } +#endif }; // namespace Common diff --git a/src/common/steady_clock.h b/src/common/steady_clock.h index dbd0e2513..95a2b6ebc 100644 --- a/src/common/steady_clock.h +++ b/src/common/steady_clock.h @@ -20,6 +20,7 @@ struct SteadyClock { [[nodiscard]] static time_point Now() noexcept; }; +#if (_WIN32_WINNT > _WIN32_WINNT_WIN7) struct RealTimeClock { using rep = s64; using period = std::nano; @@ -30,5 +31,6 @@ struct RealTimeClock { [[nodiscard]] static time_point Now() noexcept; }; +#endif } // namespace Common diff --git a/src/common/windows/timer_resolution.cpp b/src/common/windows/timer_resolution.cpp index 29c6e5c7e..23d40495a 100644 --- a/src/common/windows/timer_resolution.cpp +++ b/src/common/windows/timer_resolution.cpp @@ -60,6 +60,7 @@ TimerResolution GetTimerResolution() { }; } +#if (_WIN32_WINNT > _WIN32_WINNT_WIN7) void SetHighQoS() { // https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service PROCESS_POWER_THROTTLING_STATE PowerThrottling{ @@ -71,6 +72,7 @@ void SetHighQoS() { SetProcessInformation(GetCurrentProcess(), ProcessPowerThrottling, &PowerThrottling, sizeof(PROCESS_POWER_THROTTLING_STATE)); } +#endif } // Anonymous namespace @@ -95,7 +97,9 @@ nanoseconds SetCurrentTimerResolution(nanoseconds timer_resolution) { } nanoseconds SetCurrentTimerResolutionToMaximum() { +#if (_WIN32_WINNT > _WIN32_WINNT_WIN7) SetHighQoS(); +#endif return SetCurrentTimerResolution(GetMaximumTimerResolution()); } diff --git a/src/common/x64/rdtsc.cpp b/src/common/x64/rdtsc.cpp index 9273274a3..274284e4f 100644 --- a/src/common/x64/rdtsc.cpp +++ b/src/common/x64/rdtsc.cpp @@ -22,11 +22,19 @@ u64 EstimateRDTSCFrequency() { FencedRDTSC(); // Get the current time. +#if (_WIN32_WINNT <= 0x0601) // _WIN32_WINNT_WIN7 + const auto start_time = SteadyClock::Now(); +#else const auto start_time = RealTimeClock::Now(); +#endif const u64 tsc_start = FencedRDTSC(); // Wait for 100 milliseconds. std::this_thread::sleep_for(std::chrono::milliseconds{100}); +#if (_WIN32_WINNT <= 0x0601) // _WIN32_WINNT_WIN7 + const auto end_time = SteadyClock::Now(); +#else const auto end_time = RealTimeClock::Now(); +#endif const u64 tsc_end = FencedRDTSC(); // Calculate differences. const u64 timer_diff = static_cast(