2020-02-09 20:53:22 +00:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include "common/spin_lock.h"
|
|
|
|
#include "common/wall_clock.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
namespace X64 {
|
2020-09-29 20:19:37 +01:00
|
|
|
class NativeClock final : public WallClock {
|
2020-02-09 20:53:22 +00:00
|
|
|
public:
|
|
|
|
NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency);
|
|
|
|
|
|
|
|
std::chrono::nanoseconds GetTimeNS() override;
|
|
|
|
|
|
|
|
std::chrono::microseconds GetTimeUS() override;
|
|
|
|
|
|
|
|
std::chrono::milliseconds GetTimeMS() override;
|
|
|
|
|
|
|
|
u64 GetClockCycles() override;
|
|
|
|
|
|
|
|
u64 GetCPUCycles() override;
|
|
|
|
|
2020-02-25 16:28:55 +00:00
|
|
|
void Pause(bool is_paused) override;
|
|
|
|
|
2020-02-09 20:53:22 +00:00
|
|
|
private:
|
|
|
|
u64 GetRTSC();
|
|
|
|
|
2020-03-21 16:23:13 +00:00
|
|
|
/// value used to reduce the native clocks accuracy as some apss rely on
|
|
|
|
/// undefined behavior where the level of accuracy in the clock shouldn't
|
|
|
|
/// be higher.
|
2020-10-30 19:02:02 +00:00
|
|
|
static constexpr u64 inaccuracy_mask = ~(UINT64_C(0x400) - 1);
|
2020-03-21 16:23:13 +00:00
|
|
|
|
2020-02-09 20:53:22 +00:00
|
|
|
SpinLock rtsc_serialize{};
|
|
|
|
u64 last_measure{};
|
|
|
|
u64 accumulated_ticks{};
|
|
|
|
u64 rtsc_frequency;
|
|
|
|
};
|
|
|
|
} // namespace X64
|
|
|
|
|
|
|
|
u64 EstimateRDTSCFrequency();
|
|
|
|
|
|
|
|
} // namespace Common
|