summaryrefslogtreecommitdiffstats
path: root/src/common/x64/native_clock.cpp
diff options
context:
space:
mode:
authorFeng Chen <VonChenPlus@gmail.com>2021-12-18 06:57:14 +0100
committerGitHub <noreply@github.com>2021-12-18 06:57:14 +0100
commite49184e6069a9d791d2df3c1958f5c4b1187e124 (patch)
treeb776caf722e0be0e680f67b0ad0842628162ef1c /src/common/x64/native_clock.cpp
parentImplement convert legacy to generic (diff)
parentMerge pull request #7570 from ameerj/favorites-expanded (diff)
downloadyuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.bz2
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.lz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.zst
yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip
Diffstat (limited to 'src/common/x64/native_clock.cpp')
-rw-r--r--src/common/x64/native_clock.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 87de40624..82ee2c8a1 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -15,26 +15,26 @@
namespace Common {
u64 EstimateRDTSCFrequency() {
- const auto milli_10 = std::chrono::milliseconds{10};
- // get current time
+ // Discard the first result measuring the rdtsc.
_mm_mfence();
- const u64 tscStart = __rdtsc();
- const auto startTime = std::chrono::high_resolution_clock::now();
- // wait roughly 3 seconds
- while (true) {
- auto milli = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::high_resolution_clock::now() - startTime);
- if (milli.count() >= 3000)
- break;
- std::this_thread::sleep_for(milli_10);
- }
- const auto endTime = std::chrono::high_resolution_clock::now();
+ __rdtsc();
+ std::this_thread::sleep_for(std::chrono::milliseconds{1});
+ _mm_mfence();
+ __rdtsc();
+
+ // Get the current time.
+ const auto start_time = std::chrono::steady_clock::now();
+ _mm_mfence();
+ const u64 tsc_start = __rdtsc();
+ // Wait for 200 milliseconds.
+ std::this_thread::sleep_for(std::chrono::milliseconds{200});
+ const auto end_time = std::chrono::steady_clock::now();
_mm_mfence();
- const u64 tscEnd = __rdtsc();
- // calculate difference
- const u64 timer_diff =
- std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count();
- const u64 tsc_diff = tscEnd - tscStart;
+ const u64 tsc_end = __rdtsc();
+ // 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;
}