2022-04-23 09:59:50 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-02-09 20:53:22 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#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:
|
2020-11-25 20:21:03 +00:00
|
|
|
explicit NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_,
|
|
|
|
u64 rtsc_frequency_);
|
2020-02-09 20:53:22 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-06-28 21:42:00 +01:00
|
|
|
union alignas(16) TimePoint {
|
|
|
|
TimePoint() : pack{} {}
|
|
|
|
u128 pack{};
|
|
|
|
struct Inner {
|
|
|
|
u64 last_measure{};
|
|
|
|
u64 accumulated_ticks{};
|
|
|
|
} inner;
|
2021-01-02 01:24:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-28 21:42:00 +01:00
|
|
|
TimePoint time_point;
|
|
|
|
|
2021-01-01 22:28:55 +00:00
|
|
|
// factors
|
2021-01-02 01:24:49 +00:00
|
|
|
u64 clock_rtsc_factor{};
|
|
|
|
u64 cpu_rtsc_factor{};
|
2021-01-01 22:28:55 +00:00
|
|
|
u64 ns_rtsc_factor{};
|
|
|
|
u64 us_rtsc_factor{};
|
|
|
|
u64 ms_rtsc_factor{};
|
2021-01-02 01:24:49 +00:00
|
|
|
|
|
|
|
u64 rtsc_frequency;
|
2020-02-09 20:53:22 +00:00
|
|
|
};
|
|
|
|
} // namespace X64
|
|
|
|
|
|
|
|
u64 EstimateRDTSCFrequency();
|
|
|
|
|
|
|
|
} // namespace Common
|