diff options
| author | 2021-12-02 16:12:23 -0500 | |
|---|---|---|
| committer | 2021-12-03 19:55:59 -0500 | |
| commit | f919498f8f4e36477d8ea3424f9ecbfae7576340 (patch) | |
| tree | 62352f05a6bd485ee4d67703433294fa86309b9d /src/common/x64 | |
| parent | Merge pull request #7489 from Morph1984/steady-clock (diff) | |
| download | yuzu-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/common/x64')
| -rw-r--r-- | src/common/x64/native_clock.cpp | 36 |
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 @@ | |||
| 15 | namespace Common { | 15 | namespace Common { |
| 16 | 16 | ||
| 17 | u64 EstimateRDTSCFrequency() { | 17 | u64 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 | } |