diff options
author | bunnei <bunneidev@gmail.com> | 2021-01-15 23:01:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 23:01:42 -0800 |
commit | a7fd61fcce4634b8e849ab65a732080e77fad902 (patch) | |
tree | 843fb62264d5acf24a243d564de7492be660fa2e /src/common/x64/native_clock.h | |
parent | 8def504d737f8dc7b8e2139b6b6d8d3d85b62858 (diff) | |
parent | 53d92318b82cd4a9e08f814fcb8aab624d795c6c (diff) |
Merge pull request #5275 from FernandoS27/fast-native-clock
X86/NativeClock: Improve performance of clock calculations on hot path.
Diffstat (limited to 'src/common/x64/native_clock.h')
-rw-r--r-- | src/common/x64/native_clock.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h index 6d1e32ac8..7cbd400d2 100644 --- a/src/common/x64/native_clock.h +++ b/src/common/x64/native_clock.h @@ -6,7 +6,6 @@ #include <optional> -#include "common/spin_lock.h" #include "common/wall_clock.h" namespace Common { @@ -32,14 +31,28 @@ public: private: u64 GetRTSC(); + union alignas(16) TimePoint { + TimePoint() : pack{} {} + u128 pack{}; + struct Inner { + u64 last_measure{}; + u64 accumulated_ticks{}; + } inner; + }; + /// value used to reduce the native clocks accuracy as some apss rely on /// undefined behavior where the level of accuracy in the clock shouldn't /// be higher. static constexpr u64 inaccuracy_mask = ~(UINT64_C(0x400) - 1); - SpinLock rtsc_serialize{}; - u64 last_measure{}; - u64 accumulated_ticks{}; + TimePoint time_point; + // factors + u64 clock_rtsc_factor{}; + u64 cpu_rtsc_factor{}; + u64 ns_rtsc_factor{}; + u64 us_rtsc_factor{}; + u64 ms_rtsc_factor{}; + u64 rtsc_frequency; }; } // namespace X64 |