summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.h
diff options
context:
space:
mode:
authorGravatar Morph2023-04-22 23:08:28 -0400
committerGravatar Morph2023-06-07 21:44:42 -0400
commit1492a65454d6a03f641b136cc61e68870be00218 (patch)
tree5442ef0505fb075ee329a1a3cbb1be831987295e /src/common/wall_clock.h
parentx64: Deduplicate RDTSC usage (diff)
downloadyuzu-1492a65454d6a03f641b136cc61e68870be00218.tar.gz
yuzu-1492a65454d6a03f641b136cc61e68870be00218.tar.xz
yuzu-1492a65454d6a03f641b136cc61e68870be00218.zip
(wall, native)_clock: Rework NativeClock
Diffstat (limited to '')
-rw-r--r--src/common/wall_clock.h54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
index 157ec5eae..a73e6e644 100644
--- a/src/common/wall_clock.h
+++ b/src/common/wall_clock.h
@@ -5,6 +5,7 @@
5 5
6#include <chrono> 6#include <chrono>
7#include <memory> 7#include <memory>
8#include <ratio>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
10 11
@@ -12,50 +13,43 @@ namespace Common {
12 13
13class WallClock { 14class WallClock {
14public: 15public:
15 static constexpr u64 NS_RATIO = 1'000'000'000; 16 static constexpr u64 CNTFRQ = 19'200'000; // CNTPCT_EL0 Frequency = 19.2 MHz
16 static constexpr u64 US_RATIO = 1'000'000;
17 static constexpr u64 MS_RATIO = 1'000;
18 17
19 virtual ~WallClock() = default; 18 virtual ~WallClock() = default;
20 19
21 /// Returns current wall time in nanoseconds 20 /// @returns The time in nanoseconds since the construction of this clock.
22 [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; 21 virtual std::chrono::nanoseconds GetTimeNS() const = 0;
23 22
24 /// Returns current wall time in microseconds 23 /// @returns The time in microseconds since the construction of this clock.
25 [[nodiscard]] virtual std::chrono::microseconds GetTimeUS() = 0; 24 virtual std::chrono::microseconds GetTimeUS() const = 0;
26 25
27 /// Returns current wall time in milliseconds 26 /// @returns The time in milliseconds since the construction of this clock.
28 [[nodiscard]] virtual std::chrono::milliseconds GetTimeMS() = 0; 27 virtual std::chrono::milliseconds GetTimeMS() const = 0;
29 28
30 /// Returns current wall time in emulated clock cycles 29 /// @returns The guest CNTPCT ticks since the construction of this clock.
31 [[nodiscard]] virtual u64 GetClockCycles() = 0; 30 virtual u64 GetCNTPCT() const = 0;
32 31
33 /// Returns current wall time in emulated cpu cycles 32 /// @returns The raw host timer ticks since an indeterminate epoch.
34 [[nodiscard]] virtual u64 GetCPUCycles() = 0; 33 virtual u64 GetHostTicksNow() const = 0;
35 34
36 virtual void Pause(bool is_paused) = 0; 35 /// @returns The raw host timer ticks since the construction of this clock.
36 virtual u64 GetHostTicksElapsed() const = 0;
37 37
38 /// Tells if the wall clock, uses the host CPU's hardware clock 38 /// @returns Whether the clock directly uses the host's hardware clock.
39 [[nodiscard]] bool IsNative() const { 39 virtual bool IsNative() const = 0;
40 return is_native;
41 }
42 40
43protected: 41protected:
44 explicit WallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_, bool is_native_) 42 using NsRatio = std::nano;
45 : emulated_cpu_frequency{emulated_cpu_frequency_}, 43 using UsRatio = std::micro;
46 emulated_clock_frequency{emulated_clock_frequency_}, is_native{is_native_} {} 44 using MsRatio = std::milli;
47 45
48 u64 emulated_cpu_frequency; 46 using NsToUsRatio = std::ratio_divide<std::nano, std::micro>;
49 u64 emulated_clock_frequency; 47 using NsToMsRatio = std::ratio_divide<std::nano, std::milli>;
50 48 using NsToCNTPCTRatio = std::ratio<CNTFRQ, std::nano::den>;
51private:
52 bool is_native;
53}; 49};
54 50
55[[nodiscard]] std::unique_ptr<WallClock> CreateBestMatchingClock(u64 emulated_cpu_frequency, 51std::unique_ptr<WallClock> CreateOptimalClock();
56 u64 emulated_clock_frequency);
57 52
58[[nodiscard]] std::unique_ptr<WallClock> CreateStandardWallClock(u64 emulated_cpu_frequency, 53std::unique_ptr<WallClock> CreateStandardWallClock();
59 u64 emulated_clock_frequency);
60 54
61} // namespace Common 55} // namespace Common