summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-25 12:28:55 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:35:10 -0400
commit18dcb0934217628711c5b1d22fd6d7635e683e3f (patch)
tree426f78eb11aa79e0d1c7470b966fbae8ea8e3e6d /src
parentAudioCore: Use nanoseconds instead of cycles for buffer time. (diff)
downloadyuzu-18dcb0934217628711c5b1d22fd6d7635e683e3f.tar.gz
yuzu-18dcb0934217628711c5b1d22fd6d7635e683e3f.tar.xz
yuzu-18dcb0934217628711c5b1d22fd6d7635e683e3f.zip
HostTiming: Pause the hardware clock on pause.
Diffstat (limited to 'src')
-rw-r--r--src/common/wall_clock.cpp4
-rw-r--r--src/common/wall_clock.h2
-rw-r--r--src/common/x64/native_clock.cpp7
-rw-r--r--src/common/x64/native_clock.h2
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/core_timing.cpp6
-rw-r--r--src/core/core_timing.h1
7 files changed, 23 insertions, 1 deletions
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp
index d4d35f4e7..a46db6bbf 100644
--- a/src/common/wall_clock.cpp
+++ b/src/common/wall_clock.cpp
@@ -53,6 +53,10 @@ public:
53 return Common::Divide128On32(temporary, 1000000000).first; 53 return Common::Divide128On32(temporary, 1000000000).first;
54 } 54 }
55 55
56 void Pause(bool is_paused) override {
57 // Do nothing in this clock type.
58 }
59
56private: 60private:
57 base_time_point start_time; 61 base_time_point start_time;
58}; 62};
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
index ed284cf50..367d72134 100644
--- a/src/common/wall_clock.h
+++ b/src/common/wall_clock.h
@@ -28,6 +28,8 @@ public:
28 /// Returns current wall time in emulated cpu cycles 28 /// Returns current wall time in emulated cpu cycles
29 virtual u64 GetCPUCycles() = 0; 29 virtual u64 GetCPUCycles() = 0;
30 30
31 virtual void Pause(bool is_paused) = 0;
32
31 /// Tells if the wall clock, uses the host CPU's hardware clock 33 /// Tells if the wall clock, uses the host CPU's hardware clock
32 bool IsNative() const { 34 bool IsNative() const {
33 return is_native; 35 return is_native;
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 26d4d0ba6..926f92ff8 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -65,6 +65,13 @@ u64 NativeClock::GetRTSC() {
65 return accumulated_ticks; 65 return accumulated_ticks;
66} 66}
67 67
68void NativeClock::Pause(bool is_paused) {
69 if (!is_paused) {
70 _mm_mfence();
71 last_measure = __rdtsc();
72 }
73}
74
68std::chrono::nanoseconds NativeClock::GetTimeNS() { 75std::chrono::nanoseconds NativeClock::GetTimeNS() {
69 const u64 rtsc_value = GetRTSC(); 76 const u64 rtsc_value = GetRTSC();
70 return std::chrono::nanoseconds{MultiplyAndDivide64(rtsc_value, 1000000000, rtsc_frequency)}; 77 return std::chrono::nanoseconds{MultiplyAndDivide64(rtsc_value, 1000000000, rtsc_frequency)};
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h
index b58cf9f5a..3851f8fc2 100644
--- a/src/common/x64/native_clock.h
+++ b/src/common/x64/native_clock.h
@@ -26,6 +26,8 @@ public:
26 26
27 u64 GetCPUCycles() override; 27 u64 GetCPUCycles() override;
28 28
29 void Pause(bool is_paused) override;
30
29private: 31private:
30 u64 GetRTSC(); 32 u64 GetRTSC();
31 33
diff --git a/src/core/core.cpp b/src/core/core.cpp
index e8936b09d..1d6179a80 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -137,8 +137,8 @@ struct System::Impl {
137 ResultStatus Pause() { 137 ResultStatus Pause() {
138 status = ResultStatus::Success; 138 status = ResultStatus::Success;
139 139
140 kernel.Suspend(true);
141 core_timing.SyncPause(true); 140 core_timing.SyncPause(true);
141 kernel.Suspend(true);
142 cpu_manager.Pause(true); 142 cpu_manager.Pause(true);
143 143
144 return status; 144 return status;
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index cc32a853b..5a7abcfca 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -77,6 +77,9 @@ void CoreTiming::SyncPause(bool is_paused) {
77 return; 77 return;
78 } 78 }
79 Pause(is_paused); 79 Pause(is_paused);
80 if (!is_paused) {
81 pause_event.Set();
82 }
80 event.Set(); 83 event.Set();
81 while (paused_set != is_paused) 84 while (paused_set != is_paused)
82 ; 85 ;
@@ -197,6 +200,9 @@ void CoreTiming::ThreadLoop() {
197 wait_set = false; 200 wait_set = false;
198 } 201 }
199 paused_set = true; 202 paused_set = true;
203 clock->Pause(true);
204 pause_event.Wait();
205 clock->Pause(false);
200 } 206 }
201} 207}
202 208
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index 707c8ef0c..c70b605c8 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -136,6 +136,7 @@ private:
136 136
137 std::shared_ptr<EventType> ev_lost; 137 std::shared_ptr<EventType> ev_lost;
138 Common::Event event{}; 138 Common::Event event{};
139 Common::Event pause_event{};
139 Common::SpinLock basic_lock{}; 140 Common::SpinLock basic_lock{};
140 Common::SpinLock advance_lock{}; 141 Common::SpinLock advance_lock{};
141 std::unique_ptr<std::thread> timer_thread; 142 std::unique_ptr<std::thread> timer_thread;