diff options
Diffstat (limited to 'src/common/x64/native_clock.h')
| -rw-r--r-- | src/common/x64/native_clock.h | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h index 38ae7a462..334415eff 100644 --- a/src/common/x64/native_clock.h +++ b/src/common/x64/native_clock.h | |||
| @@ -5,51 +5,37 @@ | |||
| 5 | 5 | ||
| 6 | #include "common/wall_clock.h" | 6 | #include "common/wall_clock.h" |
| 7 | 7 | ||
| 8 | namespace Common { | 8 | namespace Common::X64 { |
| 9 | 9 | ||
| 10 | namespace X64 { | ||
| 11 | class NativeClock final : public WallClock { | 10 | class NativeClock final : public WallClock { |
| 12 | public: | 11 | public: |
| 13 | explicit NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_, | 12 | explicit NativeClock(u64 rdtsc_frequency_); |
| 14 | u64 rtsc_frequency_); | ||
| 15 | 13 | ||
| 16 | std::chrono::nanoseconds GetTimeNS() override; | 14 | std::chrono::nanoseconds GetTimeNS() const override; |
| 17 | 15 | ||
| 18 | std::chrono::microseconds GetTimeUS() override; | 16 | std::chrono::microseconds GetTimeUS() const override; |
| 19 | 17 | ||
| 20 | std::chrono::milliseconds GetTimeMS() override; | 18 | std::chrono::milliseconds GetTimeMS() const override; |
| 21 | 19 | ||
| 22 | u64 GetClockCycles() override; | 20 | u64 GetCNTPCT() const override; |
| 23 | 21 | ||
| 24 | u64 GetCPUCycles() override; | 22 | u64 GetGPUTick() const override; |
| 25 | 23 | ||
| 26 | void Pause(bool is_paused) override; | 24 | u64 GetHostTicksNow() const override; |
| 25 | |||
| 26 | u64 GetHostTicksElapsed() const override; | ||
| 27 | |||
| 28 | bool IsNative() const override; | ||
| 27 | 29 | ||
| 28 | private: | 30 | private: |
| 29 | u64 GetRTSC(); | 31 | u64 start_ticks; |
| 30 | 32 | u64 rdtsc_frequency; | |
| 31 | union alignas(16) TimePoint { | 33 | |
| 32 | TimePoint() : pack{} {} | 34 | u64 ns_rdtsc_factor; |
| 33 | u128 pack{}; | 35 | u64 us_rdtsc_factor; |
| 34 | struct Inner { | 36 | u64 ms_rdtsc_factor; |
| 35 | u64 last_measure{}; | 37 | u64 cntpct_rdtsc_factor; |
| 36 | u64 accumulated_ticks{}; | 38 | u64 gputick_rdtsc_factor; |
| 37 | } inner; | ||
| 38 | }; | ||
| 39 | |||
| 40 | TimePoint time_point; | ||
| 41 | |||
| 42 | // factors | ||
| 43 | u64 clock_rtsc_factor{}; | ||
| 44 | u64 cpu_rtsc_factor{}; | ||
| 45 | u64 ns_rtsc_factor{}; | ||
| 46 | u64 us_rtsc_factor{}; | ||
| 47 | u64 ms_rtsc_factor{}; | ||
| 48 | |||
| 49 | u64 rtsc_frequency; | ||
| 50 | }; | 39 | }; |
| 51 | } // namespace X64 | ||
| 52 | |||
| 53 | u64 EstimateRDTSCFrequency(); | ||
| 54 | 40 | ||
| 55 | } // namespace Common | 41 | } // namespace Common::X64 |