diff options
Diffstat (limited to 'src/core/core_timing.cpp')
| -rw-r--r-- | src/core/core_timing.cpp | 35 |
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 | ||
| 22 | namespace Core::Timing { | 21 | namespace Core::Timing { |
| @@ -45,9 +44,7 @@ struct CoreTiming::Event { | |||
| 45 | } | 44 | } |
| 46 | }; | 45 | }; |
| 47 | 46 | ||
| 48 | CoreTiming::CoreTiming() | 47 | CoreTiming::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 | ||
| 52 | CoreTiming::~CoreTiming() { | 49 | CoreTiming::~CoreTiming() { |
| 53 | Reset(); | 50 | Reset(); |
| @@ -180,7 +177,7 @@ void CoreTiming::AddTicks(u64 ticks_to_add) { | |||
| 180 | void CoreTiming::Idle() { | 177 | void 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 | ||
| 196 | u64 CoreTiming::GetCPUTicks() const { | ||
| 197 | if (is_multicore) [[likely]] { | ||
| 198 | return cpu_clock->GetCPUCycles(); | ||
| 199 | } | ||
| 200 | return ticks; | ||
| 201 | } | ||
| 202 | |||
| 203 | u64 CoreTiming::GetClockTicks() const { | 193 | u64 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 | ||
| 210 | std::optional<s64> CoreTiming::Advance() { | 200 | std::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 | ||
| 318 | std::chrono::nanoseconds CoreTiming::GetCPUTimeNs() const { | ||
| 319 | if (is_multicore) [[likely]] { | ||
| 320 | return cpu_clock->GetTimeNS(); | ||
| 321 | } | ||
| 322 | return CyclesToNs(ticks); | ||
| 323 | } | ||
| 324 | |||
| 325 | std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const { | 306 | std::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 | ||
| 332 | std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { | 313 | std::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 |