diff options
Diffstat (limited to 'src/common/x64/native_clock.h')
| -rw-r--r-- | src/common/x64/native_clock.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h new file mode 100644 index 000000000..891a3bbfd --- /dev/null +++ b/src/common/x64/native_clock.h | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <optional> | ||
| 8 | |||
| 9 | #include "common/spin_lock.h" | ||
| 10 | #include "common/wall_clock.h" | ||
| 11 | |||
| 12 | namespace Common { | ||
| 13 | |||
| 14 | namespace X64 { | ||
| 15 | class NativeClock : public WallClock { | ||
| 16 | public: | ||
| 17 | NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency); | ||
| 18 | |||
| 19 | std::chrono::nanoseconds GetTimeNS() override; | ||
| 20 | |||
| 21 | std::chrono::microseconds GetTimeUS() override; | ||
| 22 | |||
| 23 | std::chrono::milliseconds GetTimeMS() override; | ||
| 24 | |||
| 25 | u64 GetClockCycles() override; | ||
| 26 | |||
| 27 | u64 GetCPUCycles() override; | ||
| 28 | |||
| 29 | void Pause(bool is_paused) override; | ||
| 30 | |||
| 31 | private: | ||
| 32 | u64 GetRTSC(); | ||
| 33 | |||
| 34 | /// value used to reduce the native clocks accuracy as some apss rely on | ||
| 35 | /// undefined behavior where the level of accuracy in the clock shouldn't | ||
| 36 | /// be higher. | ||
| 37 | static constexpr u64 inaccuracy_mask = ~(0x400 - 1); | ||
| 38 | |||
| 39 | SpinLock rtsc_serialize{}; | ||
| 40 | u64 last_measure{}; | ||
| 41 | u64 accumulated_ticks{}; | ||
| 42 | u64 rtsc_frequency; | ||
| 43 | }; | ||
| 44 | } // namespace X64 | ||
| 45 | |||
| 46 | u64 EstimateRDTSCFrequency(); | ||
| 47 | |||
| 48 | } // namespace Common | ||