From 847112669633e6970c55d5b0f387f07620defdeb Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 23 Apr 2023 07:29:08 +0300 Subject: [PATCH] Change "GetMillisecondsSinceClassCreation" to "GetNanosecondsSinceClassCreation" --- Core/Time/HighPrecisionEventTimer.cpp | 7 +++++-- Core/Time/TimeStampCounter.cpp | 2 +- Core/Time/Timer.cpp | 6 +++--- include/time.hpp | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Core/Time/HighPrecisionEventTimer.cpp b/Core/Time/HighPrecisionEventTimer.cpp index 440d7e3..6b0e576 100644 --- a/Core/Time/HighPrecisionEventTimer.cpp +++ b/Core/Time/HighPrecisionEventTimer.cpp @@ -55,10 +55,13 @@ namespace Time #endif } - uint64_t HighPrecisionEventTimer::GetMillisecondsSinceClassCreation() + uint64_t HighPrecisionEventTimer::GetNanosecondsSinceClassCreation() { #if defined(a86) - return (this->GetCounter() - this->ClassCreationTime) / (this->clk / this->ConvertUnit(Units::Milliseconds)); + uint64_t Subtraction = this->GetCounter() - this->ClassCreationTime; + if (Subtraction <= 0 || this->clk <= 0) + return 0; + return Subtraction / (this->clk / ConvertUnit(Units::Nanoseconds)); #endif } diff --git a/Core/Time/TimeStampCounter.cpp b/Core/Time/TimeStampCounter.cpp index 6b7e5b0..61ab3af 100644 --- a/Core/Time/TimeStampCounter.cpp +++ b/Core/Time/TimeStampCounter.cpp @@ -55,7 +55,7 @@ namespace Time #endif } - uint64_t TimeStampCounter::GetMillisecondsSinceClassCreation() + uint64_t TimeStampCounter::GetNanosecondsSinceClassCreation() { #if defined(a86) return (this->GetCounter() - this->ClassCreationTime) / this->clk; diff --git a/Core/Time/Timer.cpp b/Core/Time/Timer.cpp index 6fd9801..a0f5b54 100644 --- a/Core/Time/Timer.cpp +++ b/Core/Time/Timer.cpp @@ -118,7 +118,7 @@ namespace Time } } - uint64_t time::GetMillisecondsSinceClassCreation() + uint64_t time::GetNanosecondsSinceClassCreation() { switch (ActiveTimer) { @@ -132,7 +132,7 @@ namespace Time fixme("PIT sleep not implemented"); return false; case HPET: - return this->hpet->GetMillisecondsSinceClassCreation(); + return this->hpet->GetNanosecondsSinceClassCreation(); case ACPI: fixme("ACPI sleep not implemented"); return false; @@ -140,7 +140,7 @@ namespace Time fixme("APIC sleep not implemented"); return false; case TSC: - return this->tsc->GetMillisecondsSinceClassCreation(); + return this->tsc->GetNanosecondsSinceClassCreation(); default: error("Unknown timer"); return false; diff --git a/include/time.hpp b/include/time.hpp index f342c6c..da06ee5 100644 --- a/include/time.hpp +++ b/include/time.hpp @@ -103,7 +103,7 @@ namespace Time bool Sleep(uint64_t Duration, Units Unit); uint64_t GetCounter(); uint64_t CalculateTarget(uint64_t Target, Units Unit); - uint64_t GetMillisecondsSinceClassCreation(); + uint64_t GetNanosecondsSinceClassCreation(); HighPrecisionEventTimer(void *hpet); ~HighPrecisionEventTimer(); @@ -151,7 +151,7 @@ namespace Time bool Sleep(uint64_t Duration, Units Unit); uint64_t GetCounter(); uint64_t CalculateTarget(uint64_t Target, Units Unit); - uint64_t GetMillisecondsSinceClassCreation(); + uint64_t GetNanosecondsSinceClassCreation(); TimeStampCounter(); ~TimeStampCounter(); @@ -192,7 +192,7 @@ namespace Time bool Sleep(uint64_t Duration, Units Unit); uint64_t GetCounter(); uint64_t CalculateTarget(uint64_t Target, Units Unit); - uint64_t GetMillisecondsSinceClassCreation(); + uint64_t GetNanosecondsSinceClassCreation(); void FindTimers(void *acpi); time(); ~time();