summaryrefslogtreecommitdiff
path: root/src/common/x64/native_clock.cpp
diff options
context:
space:
mode:
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 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}