summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar Morph2023-04-23 00:01:08 -0400
committerGravatar Morph2023-06-07 21:44:42 -0400
commit8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf (patch)
tree2bb7be86aafe9986811758b508a7581d2efe8ac4 /src/core/core_timing.cpp
parentnvnflinger: Acquire lock prior to signaling the vsync variable (diff)
downloadyuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.tar.gz
yuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.tar.xz
yuzu-8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf.zip
core_timing: Use CNTPCT as the guest CPU tick
Previously, we were mixing the raw CPU frequency and CNTFRQ. The raw CPU frequency (1020 MHz) should've never been used as CNTPCT (whose frequency is CNTFRQ) is the only counter available.
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 4f2692b05..9a1d5a69a 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -16,7 +16,6 @@
16 16
17#include "common/microprofile.h" 17#include "common/microprofile.h"
18#include "core/core_timing.h" 18#include "core/core_timing.h"
19#include "core/core_timing_util.h"
20#include "core/hardware_properties.h" 19#include "core/hardware_properties.h"
21 20
22namespace Core::Timing { 21namespace Core::Timing {
@@ -45,9 +44,7 @@ struct CoreTiming::Event {
45 } 44 }
46}; 45};
47 46
48CoreTiming::CoreTiming() 47CoreTiming::CoreTiming() : clock{Common::CreateOptimalClock()} {}
49 : cpu_clock{Common::CreateBestMatchingClock(Hardware::BASE_CLOCK_RATE, Hardware::CNTFREQ)},
50 event_clock{Common::CreateStandardWallClock(Hardware::BASE_CLOCK_RATE, Hardware::CNTFREQ)} {}
51 48
52CoreTiming::~CoreTiming() { 49CoreTiming::~CoreTiming() {
53 Reset(); 50 Reset();
@@ -180,7 +177,7 @@ void CoreTiming::AddTicks(u64 ticks_to_add) {
180void CoreTiming::Idle() { 177void CoreTiming::Idle() {
181 if (!event_queue.empty()) { 178 if (!event_queue.empty()) {
182 const u64 next_event_time = event_queue.front().time; 179 const u64 next_event_time = event_queue.front().time;
183 const u64 next_ticks = nsToCycles(std::chrono::nanoseconds(next_event_time)) + 10U; 180 const u64 next_ticks = Common::WallClock::NSToCNTPCT(next_event_time) + 10U;
184 if (next_ticks > ticks) { 181 if (next_ticks > ticks) {
185 ticks = next_ticks; 182 ticks = next_ticks;
186 } 183 }
@@ -193,18 +190,11 @@ void CoreTiming::ResetTicks() {
193 downcount = MAX_SLICE_LENGTH; 190 downcount = MAX_SLICE_LENGTH;
194} 191}
195 192
196u64 CoreTiming::GetCPUTicks() const {
197 if (is_multicore) [[likely]] {
198 return cpu_clock->GetCPUCycles();
199 }
200 return ticks;
201}
202
203u64 CoreTiming::GetClockTicks() const { 193u64 CoreTiming::GetClockTicks() const {
204 if (is_multicore) [[likely]] { 194 if (is_multicore) [[likely]] {
205 return cpu_clock->GetClockCycles(); 195 return clock->GetCNTPCT();
206 } 196 }
207 return CpuCyclesToClockCycles(ticks); 197 return ticks;
208} 198}
209 199
210std::optional<s64> CoreTiming::Advance() { 200std::optional<s64> CoreTiming::Advance() {
@@ -297,9 +287,7 @@ void CoreTiming::ThreadLoop() {
297 } 287 }
298 288
299 paused_set = true; 289 paused_set = true;
300 event_clock->Pause(true);
301 pause_event.Wait(); 290 pause_event.Wait();
302 event_clock->Pause(false);
303 } 291 }
304} 292}
305 293
@@ -315,25 +303,18 @@ void CoreTiming::Reset() {
315 has_started = false; 303 has_started = false;
316} 304}
317 305
318std::chrono::nanoseconds CoreTiming::GetCPUTimeNs() const {
319 if (is_multicore) [[likely]] {
320 return cpu_clock->GetTimeNS();
321 }
322 return CyclesToNs(ticks);
323}
324
325std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const { 306std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const {
326 if (is_multicore) [[likely]] { 307 if (is_multicore) [[likely]] {
327 return event_clock->GetTimeNS(); 308 return clock->GetTimeNS();
328 } 309 }
329 return CyclesToNs(ticks); 310 return std::chrono::nanoseconds{Common::WallClock::CNTPCTToNS(ticks)};
330} 311}
331 312
332std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { 313std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
333 if (is_multicore) [[likely]] { 314 if (is_multicore) [[likely]] {
334 return event_clock->GetTimeUS(); 315 return clock->GetTimeUS();
335 } 316 }
336 return CyclesToUs(ticks); 317 return std::chrono::microseconds{Common::WallClock::CNTPCTToUS(ticks)};
337} 318}
338 319
339} // namespace Core::Timing 320} // namespace Core::Timing