HostTiming: Pause the hardware clock on pause.
This commit is contained in:
parent
6bf137a0e8
commit
18dcb09342
|
@ -53,6 +53,10 @@ public:
|
||||||
return Common::Divide128On32(temporary, 1000000000).first;
|
return Common::Divide128On32(temporary, 1000000000).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Pause(bool is_paused) override {
|
||||||
|
// Do nothing in this clock type.
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
base_time_point start_time;
|
base_time_point start_time;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,8 @@ public:
|
||||||
/// Returns current wall time in emulated cpu cycles
|
/// Returns current wall time in emulated cpu cycles
|
||||||
virtual u64 GetCPUCycles() = 0;
|
virtual u64 GetCPUCycles() = 0;
|
||||||
|
|
||||||
|
virtual void Pause(bool is_paused) = 0;
|
||||||
|
|
||||||
/// Tells if the wall clock, uses the host CPU's hardware clock
|
/// Tells if the wall clock, uses the host CPU's hardware clock
|
||||||
bool IsNative() const {
|
bool IsNative() const {
|
||||||
return is_native;
|
return is_native;
|
||||||
|
|
|
@ -65,6 +65,13 @@ u64 NativeClock::GetRTSC() {
|
||||||
return accumulated_ticks;
|
return accumulated_ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeClock::Pause(bool is_paused) {
|
||||||
|
if (!is_paused) {
|
||||||
|
_mm_mfence();
|
||||||
|
last_measure = __rdtsc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::chrono::nanoseconds NativeClock::GetTimeNS() {
|
std::chrono::nanoseconds NativeClock::GetTimeNS() {
|
||||||
const u64 rtsc_value = GetRTSC();
|
const u64 rtsc_value = GetRTSC();
|
||||||
return std::chrono::nanoseconds{MultiplyAndDivide64(rtsc_value, 1000000000, rtsc_frequency)};
|
return std::chrono::nanoseconds{MultiplyAndDivide64(rtsc_value, 1000000000, rtsc_frequency)};
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
|
|
||||||
u64 GetCPUCycles() override;
|
u64 GetCPUCycles() override;
|
||||||
|
|
||||||
|
void Pause(bool is_paused) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u64 GetRTSC();
|
u64 GetRTSC();
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,8 @@ struct System::Impl {
|
||||||
ResultStatus Pause() {
|
ResultStatus Pause() {
|
||||||
status = ResultStatus::Success;
|
status = ResultStatus::Success;
|
||||||
|
|
||||||
kernel.Suspend(true);
|
|
||||||
core_timing.SyncPause(true);
|
core_timing.SyncPause(true);
|
||||||
|
kernel.Suspend(true);
|
||||||
cpu_manager.Pause(true);
|
cpu_manager.Pause(true);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -77,6 +77,9 @@ void CoreTiming::SyncPause(bool is_paused) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pause(is_paused);
|
Pause(is_paused);
|
||||||
|
if (!is_paused) {
|
||||||
|
pause_event.Set();
|
||||||
|
}
|
||||||
event.Set();
|
event.Set();
|
||||||
while (paused_set != is_paused)
|
while (paused_set != is_paused)
|
||||||
;
|
;
|
||||||
|
@ -197,6 +200,9 @@ void CoreTiming::ThreadLoop() {
|
||||||
wait_set = false;
|
wait_set = false;
|
||||||
}
|
}
|
||||||
paused_set = true;
|
paused_set = true;
|
||||||
|
clock->Pause(true);
|
||||||
|
pause_event.Wait();
|
||||||
|
clock->Pause(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<EventType> ev_lost;
|
std::shared_ptr<EventType> ev_lost;
|
||||||
Common::Event event{};
|
Common::Event event{};
|
||||||
|
Common::Event pause_event{};
|
||||||
Common::SpinLock basic_lock{};
|
Common::SpinLock basic_lock{};
|
||||||
Common::SpinLock advance_lock{};
|
Common::SpinLock advance_lock{};
|
||||||
std::unique_ptr<std::thread> timer_thread;
|
std::unique_ptr<std::thread> timer_thread;
|
||||||
|
|
Loading…
Reference in New Issue