aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2023-04-23 00:01:08 -0400
committerMorph <39850852+Morph1984@users.noreply.github.com>2023-06-07 21:44:42 -0400
commit8e56a84566036cfff0aa5c3d80ae1b051d2bd0bf (patch)
tree2bb7be86aafe9986811758b508a7581d2efe8ac4 /src/core/core_timing.cpp
parentbbd502f67adb17b00b33f1b7158cfff2b2fa8a3e (diff)
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 4f2692b05c..9a1d5a69aa 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -16,7 +16,6 @@
#include "common/microprofile.h"
#include "core/core_timing.h"
-#include "core/core_timing_util.h"
#include "core/hardware_properties.h"
namespace Core::Timing {
@@ -45,9 +44,7 @@ struct CoreTiming::Event {
}
};
-CoreTiming::CoreTiming()
- : cpu_clock{Common::CreateBestMatchingClock(Hardware::BASE_CLOCK_RATE, Hardware::CNTFREQ)},
- event_clock{Common::CreateStandardWallClock(Hardware::BASE_CLOCK_RATE, Hardware::CNTFREQ)} {}
+CoreTiming::CoreTiming() : clock{Common::CreateOptimalClock()} {}
CoreTiming::~CoreTiming() {
Reset();
@@ -180,7 +177,7 @@ void CoreTiming::AddTicks(u64 ticks_to_add) {
void CoreTiming::Idle() {
if (!event_queue.empty()) {
const u64 next_event_time = event_queue.front().time;
- const u64 next_ticks = nsToCycles(std::chrono::nanoseconds(next_event_time)) + 10U;
+ const u64 next_ticks = Common::WallClock::NSToCNTPCT(next_event_time) + 10U;
if (next_ticks > ticks) {
ticks = next_ticks;
}
@@ -193,18 +190,11 @@ void CoreTiming::ResetTicks() {
downcount = MAX_SLICE_LENGTH;
}
-u64 CoreTiming::GetCPUTicks() const {
- if (is_multicore) [[likely]] {
- return cpu_clock->GetCPUCycles();
- }
- return ticks;
-}
-
u64 CoreTiming::GetClockTicks() const {
if (is_multicore) [[likely]] {
- return cpu_clock->GetClockCycles();
+ return clock->GetCNTPCT();
}
- return CpuCyclesToClockCycles(ticks);
+ return ticks;
}
std::optional<s64> CoreTiming::Advance() {
@@ -297,9 +287,7 @@ void CoreTiming::ThreadLoop() {
}
paused_set = true;
- event_clock->Pause(true);
pause_event.Wait();
- event_clock->Pause(false);
}
}
@@ -315,25 +303,18 @@ void CoreTiming::Reset() {
has_started = false;
}
-std::chrono::nanoseconds CoreTiming::GetCPUTimeNs() const {
- if (is_multicore) [[likely]] {
- return cpu_clock->GetTimeNS();
- }
- return CyclesToNs(ticks);
-}
-
std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const {
if (is_multicore) [[likely]] {
- return event_clock->GetTimeNS();
+ return clock->GetTimeNS();
}
- return CyclesToNs(ticks);
+ return std::chrono::nanoseconds{Common::WallClock::CNTPCTToNS(ticks)};
}
std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
if (is_multicore) [[likely]] {
- return event_clock->GetTimeUS();
+ return clock->GetTimeUS();
}
- return CyclesToUs(ticks);
+ return std::chrono::microseconds{Common::WallClock::CNTPCTToUS(ticks)};
}
} // namespace Core::Timing