aboutsummaryrefslogtreecommitdiff
path: root/src/common/cpu_features.cpp
diff options
context:
space:
mode:
authorDjihads <76681596+Djihads80@users.noreply.github.com>2026-10-30 11:33:03 +0100
committerGitHub <noreply@github.com>2026-10-30 11:33:03 +0100
commit9560dec549134cf50a7bcde3f86f87ed7658b25f (patch)
tree75493cfac29ed9d1dc350658e17c366f7e10a3c4 /src/common/cpu_features.cpp
parent666d2447639594c7cd2b184acf2117b38766ac22 (diff)
parent937bb4dd30401a339a062386c121b9714e33e38d (diff)
Merge pull request #26 from Djihads80/nx2-experimental
Nx2 experimental
Diffstat (limited to 'src/common/cpu_features.cpp')
-rw-r--r--src/common/cpu_features.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/common/cpu_features.cpp b/src/common/cpu_features.cpp
index 52fd003c44..93eecb1dc5 100644
--- a/src/common/cpu_features.cpp
+++ b/src/common/cpu_features.cpp
@@ -278,8 +278,16 @@ std::chrono::milliseconds WallClock::GetTimeMS() const {
s64 WallClock::GetCNTPCT() const {
if (!invariant)
- return GetUptime() * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
- return MultiplyHigh(GetUptime(), cntpct_rdtsc_factor);
+ return MultiplyAndDivide64(GetUptime(), GetGuestCNTFRQ(), NsRatio::den);
+ return MultiplyHigh(GetUptime(), cntpct_rdtsc_factor.load(std::memory_order_relaxed));
+}
+
+void WallClock::SetGuestCNTFRQ(u64 frequency) {
+ guest_cntfrq.store(frequency, std::memory_order_relaxed);
+ if (invariant) {
+ cntpct_rdtsc_factor.store(GetFixedPoint64Factor(frequency, rdtsc_frequency),
+ std::memory_order_relaxed);
+ }
}
s64 WallClock::GetGPUTick() const {
@@ -336,7 +344,7 @@ namespace {
} // namespace
WallClock::WallClock(bool invariant_, u64 rdtsc_frequency_) noexcept {
- const u64 host_cntfrq = std::max<u64>(GetHostCNTFRQ(), 1);
+ host_cntfrq = std::max<u64>(GetHostCNTFRQ(), 1);
ns_cntfrq_factor = GetFixedPointFactor(NsRatio::den, host_cntfrq);
us_cntfrq_factor = GetFixedPointFactor(UsRatio::den, host_cntfrq);
ms_cntfrq_factor = GetFixedPointFactor(MsRatio::den, host_cntfrq);
@@ -361,6 +369,11 @@ s64 WallClock::GetCNTPCT() const {
return MultiplyHigh(GetUptime(), guest_cntfrq_factor);
}
+void WallClock::SetGuestCNTFRQ(u64 frequency) {
+ guest_cntfrq.store(frequency, std::memory_order_relaxed);
+ guest_cntfrq_factor = GetFixedPointFactor(frequency, host_cntfrq);
+}
+
s64 WallClock::GetGPUTick() const {
return MultiplyHigh(GetUptime(), gputick_cntfrq_factor);
}
@@ -399,7 +412,11 @@ std::chrono::milliseconds WallClock::GetTimeMS() const {
}
s64 WallClock::GetCNTPCT() const {
- return GetUptime() * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
+ return MultiplyAndDivide64(GetUptime(), GetGuestCNTFRQ(), NsRatio::den);
+}
+
+void WallClock::SetGuestCNTFRQ(u64 frequency) {
+ guest_cntfrq.store(frequency, std::memory_order_relaxed);
}
s64 WallClock::GetGPUTick() const {
@@ -419,9 +436,13 @@ u64 WallClock::NsToTicks(std::chrono::nanoseconds ns) const {
}
#endif
+u64 WallClock::CPUTickToGuestCNTPCT(u64 cpu_tick) const {
+ return MultiplyAndDivide64(cpu_tick, GetGuestCNTFRQ(), CPUTickFreq);
+}
+
// Wall clock MUST be initialized AFTER g_cpu_caps
// C++ only guarantees ctor init in the order they appear in TU
-const WallClock g_wall_clock = [] {
+WallClock g_wall_clock = [] {
#if defined(ARCHITECTURE_x86_64)
auto const& caps = Common::g_cpu_caps;
return WallClock(caps.invariant_tsc && caps.tsc_frequency > std::nano::den, caps.tsc_frequency);