@ -15,26 +15,26 @@
namespace Common {
namespace Common {
u64 EstimateRDTSCFrequency ( ) {
u64 EstimateRDTSCFrequency ( ) {
const auto milli_10 = std : : chrono : : milliseconds { 10 } ;
// Discard the first result measuring the rdtsc.
// get current time
_mm_mfence ( ) ;
_mm_mfence ( ) ;
const u64 tscStart = __rdtsc ( ) ;
__rdtsc ( ) ;
const auto startTime = std : : chrono : : steady_clock : : now ( ) ;
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds { 1 } ) ;
// wait roughly 3 seconds
_mm_mfence ( ) ;
while ( true ) {
__rdtsc ( ) ;
auto milli = std : : chrono : : duration_cast < std : : chrono : : milliseconds > (
std : : chrono : : steady_clock : : now ( ) - startTime ) ;
// Get the current time.
if ( milli . count ( ) > = 3000 )
const auto start_time = std : : chrono : : steady_clock : : now ( ) ;
break ;
_mm_mfence ( ) ;
std : : this_thread : : sleep_for ( milli_10 ) ;
const u64 tsc_start = __rdtsc ( ) ;
}
// Wait for 200 milliseconds.
const auto endTime = std : : chrono : : steady_clock : : now ( ) ;
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds { 200 } ) ;
const auto end_time = std : : chrono : : steady_clock : : now ( ) ;
_mm_mfence ( ) ;
_mm_mfence ( ) ;
const u64 tsc E nd = __rdtsc ( ) ;
const u64 tsc _e nd = __rdtsc ( ) ;
// calculate difference
// Calculate differences.
const u64 timer_diff =
const u64 timer_diff = static_cast < u64 > (
std : : chrono : : duration_cast < std : : chrono : : nanoseconds > ( end Time - startTime ) . count ( ) ;
std : : chrono : : duration_cast < std : : chrono : : nanoseconds > ( end _time - start_time ) . count ( ) ) ;
const u64 tsc_diff = tsc End - tscS tart;
const u64 tsc_diff = tsc _end - tsc_s tart;
const u64 tsc_freq = MultiplyAndDivide64 ( tsc_diff , 1000000000ULL , timer_diff ) ;
const u64 tsc_freq = MultiplyAndDivide64 ( tsc_diff , 1000000000ULL , timer_diff ) ;
return tsc_freq ;
return tsc_freq ;
}
}