aboutsummaryrefslogtreecommitdiff
path: root/src/common/wall_clock.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-02-01 18:34:31 -0700
committerGitHub <noreply@github.com>2022-02-01 18:34:31 -0700
commit049cb89563333e48fafb3ca9e6c9753bd258d161 (patch)
tree48fc259e944baa16a401e52a25eb4eb6ac236d63 /src/common/wall_clock.cpp
parent617bfe52cd736d461fafe6c160e4adb089deb40e (diff)
parent3605b6f5794f191cc4314c2ceeb28c2402bfd144 (diff)
Merge pull request #7809 from Morph1984/clock-constants
common: wall_clock: Utilize constants for ms, us, and ns ratios
Diffstat (limited to 'src/common/wall_clock.cpp')
-rw-r--r--src/common/wall_clock.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp
index ffa282e888..9acf7551ef 100644
--- a/src/common/wall_clock.cpp
+++ b/src/common/wall_clock.cpp
@@ -65,16 +65,20 @@ private:
#ifdef ARCHITECTURE_x86_64
-std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
- u32 emulated_clock_frequency) {
+std::unique_ptr<WallClock> CreateBestMatchingClock(u64 emulated_cpu_frequency,
+ u64 emulated_clock_frequency) {
const auto& caps = GetCPUCaps();
u64 rtsc_frequency = 0;
if (caps.invariant_tsc) {
rtsc_frequency = EstimateRDTSCFrequency();
}
- // Fallback to StandardWallClock if rtsc period is higher than a nano second
- if (rtsc_frequency <= 1000000000) {
+ // Fallback to StandardWallClock if the hardware TSC does not have the precision greater than:
+ // - A nanosecond
+ // - The emulated CPU frequency
+ // - The emulated clock counter frequency (CNTFRQ)
+ if (rtsc_frequency <= WallClock::NS_RATIO || rtsc_frequency <= emulated_cpu_frequency ||
+ rtsc_frequency <= emulated_clock_frequency) {
return std::make_unique<StandardWallClock>(emulated_cpu_frequency,
emulated_clock_frequency);
} else {
@@ -85,8 +89,8 @@ std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
#else
-std::unique_ptr<WallClock> CreateBestMatchingClock(u32 emulated_cpu_frequency,
- u32 emulated_clock_frequency) {
+std::unique_ptr<WallClock> CreateBestMatchingClock(u64 emulated_cpu_frequency,
+ u64 emulated_clock_frequency) {
return std::make_unique<StandardWallClock>(emulated_cpu_frequency, emulated_clock_frequency);
}