diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-03-04 03:02:24 +0100 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-03-05 08:36:31 +0100 |
commit | 376a414f5bc6d27e5e0fbda323caf5520436bf39 (patch) | |
tree | ef26607ff1d0fcc4c9d1040a79f018c03ec98c3e /src | |
parent | timer_resolution: Set current process to High QoS (diff) | |
download | yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar.gz yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar.bz2 yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar.lz yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar.xz yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.tar.zst yuzu-376a414f5bc6d27e5e0fbda323caf5520436bf39.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/x64/native_clock.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp index 8b08332ab..bc1a973b0 100644 --- a/src/common/x64/native_clock.cpp +++ b/src/common/x64/native_clock.cpp @@ -6,6 +6,7 @@ #include <thread> #include "common/atomic_ops.h" +#include "common/steady_clock.h" #include "common/uint128.h" #include "common/x64/native_clock.h" @@ -39,6 +40,12 @@ static u64 FencedRDTSC() { } #endif +template <u64 Nearest> +static u64 RoundToNearest(u64 value) { + const auto mod = value % Nearest; + return mod >= (Nearest / 2) ? (value - mod + Nearest) : (value - mod); +} + u64 EstimateRDTSCFrequency() { // Discard the first result measuring the rdtsc. FencedRDTSC(); @@ -46,18 +53,18 @@ u64 EstimateRDTSCFrequency() { FencedRDTSC(); // Get the current time. - const auto start_time = std::chrono::steady_clock::now(); + const auto start_time = Common::SteadyClock::Now(); const u64 tsc_start = FencedRDTSC(); - // Wait for 200 milliseconds. - std::this_thread::sleep_for(std::chrono::milliseconds{200}); - const auto end_time = std::chrono::steady_clock::now(); + // Wait for 250 milliseconds. + std::this_thread::sleep_for(std::chrono::milliseconds{250}); + const auto end_time = Common::SteadyClock::Now(); const u64 tsc_end = FencedRDTSC(); // Calculate differences. const u64 timer_diff = static_cast<u64>( std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count()); const u64 tsc_diff = tsc_end - tsc_start; const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff); - return tsc_freq; + return RoundToNearest<1000>(tsc_freq); } namespace X64 { |