summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Morph2021-12-02 16:12:23 -0500
committerGravatar Morph2021-12-03 19:55:59 -0500
commitf919498f8f4e36477d8ea3424f9ecbfae7576340 (patch)
tree62352f05a6bd485ee4d67703433294fa86309b9d /src
parentMerge pull request #7489 from Morph1984/steady-clock (diff)
downloadyuzu-f919498f8f4e36477d8ea3424f9ecbfae7576340.tar.gz
yuzu-f919498f8f4e36477d8ea3424f9ecbfae7576340.tar.xz
yuzu-f919498f8f4e36477d8ea3424f9ecbfae7576340.zip
native_clock: Wait for less time in EstimateRDTSCFrequency
In my testing, waiting for 200ms provided the same level of precision as the previous implementation when estimating the RDTSC frequency. This significantly improves the yuzu executable launch times since we reduced the wait time from 3 seconds to 200 milliseconds.
Diffstat (limited to 'src')
-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 28f834443..82ee2c8a1 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -15,26 +15,26 @@
15namespace Common { 15namespace Common {
16 16
17u64 EstimateRDTSCFrequency() { 17u64 EstimateRDTSCFrequency() {
18 const auto milli_10 = std::chrono::milliseconds{10}; 18 // Discard the first result measuring the rdtsc.
19 // get current time
20 _mm_mfence(); 19 _mm_mfence();
21 const u64 tscStart = __rdtsc(); 20 __rdtsc();
22 const auto startTime = std::chrono::steady_clock::now(); 21 std::this_thread::sleep_for(std::chrono::milliseconds{1});
23 // wait roughly 3 seconds 22 _mm_mfence();
24 while (true) { 23 __rdtsc();
25 auto milli = std::chrono::duration_cast<std::chrono::milliseconds>( 24
26 std::chrono::steady_clock::now() - startTime); 25 // Get the current time.
27 if (milli.count() >= 3000) 26 const auto start_time = std::chrono::steady_clock::now();
28 break; 27 _mm_mfence();
29 std::this_thread::sleep_for(milli_10); 28 const u64 tsc_start = __rdtsc();
30 } 29 // Wait for 200 milliseconds.
31 const auto endTime = std::chrono::steady_clock::now(); 30 std::this_thread::sleep_for(std::chrono::milliseconds{200});
31 const auto end_time = std::chrono::steady_clock::now();
32 _mm_mfence(); 32 _mm_mfence();
33 const u64 tscEnd = __rdtsc(); 33 const u64 tsc_end = __rdtsc();
34 // calculate difference 34 // Calculate differences.
35 const u64 timer_diff = 35 const u64 timer_diff = static_cast<u64>(
36 std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count(); 36 std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
37 const u64 tsc_diff = tscEnd - tscStart; 37 const u64 tsc_diff = tsc_end - tsc_start;
38 const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff); 38 const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff);
39 return tsc_freq; 39 return tsc_freq;
40} 40}