From 2a33d61e631d8ddb79d9974d71fba6a6c952b1f8 Mon Sep 17 00:00:00 2001 From: Reece Date: Sat, 22 Apr 2023 22:58:20 +0100 Subject: [PATCH] [*] further deprecate high res clock [*] further posix resolution reporting --- Include/Aurora/Time/Time.hpp | 61 ++++++++-------------- Source/IO/AuIOProcessor.cpp | 4 +- Source/IO/Loop/LoopQueue.NT.cpp | 16 +++--- Source/Threading/Primitives/AuSpinLock.cpp | 4 +- Source/Time/AuClock.cpp | 58 +++++++++++++------- 5 files changed, 73 insertions(+), 70 deletions(-) diff --git a/Include/Aurora/Time/Time.hpp b/Include/Aurora/Time/Time.hpp index dda4e6cd..553f5eca 100644 --- a/Include/Aurora/Time/Time.hpp +++ b/Include/Aurora/Time/Time.hpp @@ -85,58 +85,53 @@ namespace Aurora::Time AUKN_SYM AuUInt64 SteadyClockJiffies(); /** - * @brief frequency + * @brief frequency in jiffies per second * @return */ AUKN_SYM AuUInt64 ThreadClockJiffies(); + /** + * @brief time spent in userspace under this context [in jiffies] + * @return + */ AUKN_SYM AuUInt64 ThreadClock(); /** - * @brief time spent in userspace under this context + * @brief time spent in userspace under this context [in nanoseconds] * @return */ AUKN_SYM AuUInt64 ThreadClockNS(); + + /** + * @brief time spent in userspace under this context [in milliseconds] + * @return + */ AUKN_SYM AuUInt64 ThreadClockMS(); /** - * @brief frequency + * @brief frequency in jiffies per second * @return */ AUKN_SYM AuUInt64 ProcessClockJiffies(); /** - * @brief time spent in userspace and in the kernel under this process + * @brief time spent in userspace and in the kernel under this process [in jiffies] * @return */ AUKN_SYM AuUInt64 ProcessClock(); + + /** + * @brief time spent in userspace and in the kernel under this process [in nanoseconds] + * @return + */ AUKN_SYM AuUInt64 ProcessClockNS(); + + /** + * @brief time spent in userspace and in the kernel under this process [in milliseconds] + * @return + */ AUKN_SYM AuUInt64 ProcessClockMS(); - - /** - Returns a high resolution count of jiffies with an undefined epoch from a - high resolution clock. - - These values should be used to drive benchmarks. - These values should not nor can be accurately converted meaningfully - */ - AUKN_SYM AuUInt64 HighResClock(); - AUKN_SYM AuUInt64 HighResClockMS(); - AUKN_SYM AuUInt64 HighResClockNS(); - - /** - Retrieves the freqency of jiffies per second - */ - AUKN_SYM AuUInt64 HighResClockJiffies(); - - /** - Let's say you're fucked and you need a ball park figure. - Enjoy... - */ - AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochMS(AuUInt64 in); - AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochNS(AuUInt64 in); - /** Converts seconds from the Aurora epoch to time_t */ @@ -154,16 +149,6 @@ namespace Aurora::Time AUKN_SYM AuInt64 CTimeToMS(time_t time); - /** - Retrieves the freqency as a fraction of: jiffies per second / 1 * nanoseconds in a second - */ - AUKN_SYM double CPUFrequencyDeltaNS(); - - /** - Retrieves the freqency as a fraction of: jiffies per second / 1 * milliseconds in a second - */ - AUKN_SYM double CPUFrequencyDeltaMS(); - /** * @brief * @return diff --git a/Source/IO/AuIOProcessor.cpp b/Source/IO/AuIOProcessor.cpp index 9c1aec28..8a3f9939 100644 --- a/Source/IO/AuIOProcessor.cpp +++ b/Source/IO/AuIOProcessor.cpp @@ -468,7 +468,7 @@ namespace Aurora::IO if (this->IsTickOnly()) { auto next = this->timers.nbTicker.nextTriggerTime; - auto now = AuTime::HighResClockNS(); + auto now = AuTime::SteadyClockNS(); if (now >= next) { @@ -607,7 +607,7 @@ namespace Aurora::IO if (!this->timers.nbTicker.nextTriggerTime) { - this->timers.nbTicker.nextTriggerTime = AuTime::HighResClockNS() + this->timers.nbTicker.nsTimeStep; + this->timers.nbTicker.nextTriggerTime = AuTime::SteadyClockNS() + this->timers.nbTicker.nsTimeStep; } } diff --git a/Source/IO/Loop/LoopQueue.NT.cpp b/Source/IO/Loop/LoopQueue.NT.cpp index 5a41e4f9..8ae5de1f 100644 --- a/Source/IO/Loop/LoopQueue.NT.cpp +++ b/Source/IO/Loop/LoopQueue.NT.cpp @@ -591,7 +591,7 @@ namespace Aurora::IO::Loop count = this->handleArrayAnd_.size(); - AuUInt64 startTime = AuTime::HighResClockMS(); + AuUInt64 startTime = AuTime::SteadyClockMS(); AuUInt64 endTime = startTime + timeout; for (const auto &source : this->loopSourceExs_) @@ -603,7 +603,7 @@ namespace Aurora::IO::Loop { auto next = AuMin(count - index, AuUInt32(MAXIMUM_WAIT_OBJECTS)); - startTime = AuTime::HighResClockMS(); + startTime = AuTime::SteadyClockMS(); if (timeout) { @@ -729,7 +729,7 @@ namespace Aurora::IO::Loop AuUInt32 ret {}; bool lastItr {}; - AuUInt64 startTime = AuTime::HighResClockMS(); + AuUInt64 startTime = AuTime::SteadyClockNS(); AuUInt64 endTime = timeout ? (startTime + timeout) : AuUInt64(-1); AuUInt32 chuggerIndex {}; @@ -751,7 +751,7 @@ namespace Aurora::IO::Loop { AuList> trigger; - AuUInt64 startTime = AuTime::HighResClockMS(); + AuUInt64 startTime = AuTime::SteadyClockNS(); AuUInt64 endTime = timeout ? (startTime + timeout) : AuUInt64(-1); AuUInt32 chuggerIndex {}; @@ -827,7 +827,7 @@ namespace Aurora::IO::Loop auto sleepMS = this->slowTickMs_; if (internalEndTime && internalEndTime != AuUInt64(-1)) { - auto now = AuTime::HighResClockMS(); + auto now = AuTime::SteadyClockMS(); auto delta = AuInt64(internalEndTime) - AuInt64(now); if (delta <= 0) @@ -920,7 +920,7 @@ namespace Aurora::IO::Loop } else { - auto now = AuTime::HighResClockMS(); + auto now = AuTime::SteadyClockMS(); if (internalEndTime <= now) { return false; @@ -982,7 +982,7 @@ namespace Aurora::IO::Loop { Iterator queueIterator(this); AuSInt indexOffset {}; - auto now = AuTime::HighResClockMS(); + auto now = AuTime::SteadyClockMS(); for (queueIterator.Start(); queueIterator.End() != queueIterator.itr; ) { bool shouldRemove {false}; @@ -1254,7 +1254,7 @@ namespace Aurora::IO::Loop Iterator queueIterator(this); bool bRebuildFromAnd {}; - auto now = AuTime::HighResClockMS(); + auto now = AuTime::SteadyClockMS(); for (queueIterator.Start(); queueIterator.End() != queueIterator.itr; ) { diff --git a/Source/Threading/Primitives/AuSpinLock.cpp b/Source/Threading/Primitives/AuSpinLock.cpp index ddc1d44b..0302b5d1 100644 --- a/Source/Threading/Primitives/AuSpinLock.cpp +++ b/Source/Threading/Primitives/AuSpinLock.cpp @@ -64,7 +64,7 @@ namespace Aurora::Threading::Primitives } else { - AuUInt64 startTime = AuTime::HighResClockNS(); + AuUInt64 startTime = AuTime::SteadyClockNS(); AuUInt64 endTime = startTime + timeout; while (AuAtomicTestAndSet(&this->state_, 0)) @@ -72,7 +72,7 @@ namespace Aurora::Threading::Primitives long count = 0; while (this->state_) { - if (endTime <= AuTime::HighResClockNS()) + if (endTime <= AuTime::SteadyClockNS()) { return false; } diff --git a/Source/Time/AuClock.cpp b/Source/Time/AuClock.cpp index a0f2a77a..684bb259 100644 --- a/Source/Time/AuClock.cpp +++ b/Source/Time/AuClock.cpp @@ -130,6 +130,12 @@ static time_t CalculateTimeT(AuUInt64 in) namespace Aurora::Time { + // removed from public header / deprecating + AUKN_SYM AuUInt64 HighResClock(); + AUKN_SYM AuUInt64 HighResClockNS(); + AUKN_SYM AuUInt64 HighResClockMS(); + AUKN_SYM AuUInt64 HighResClockJiffies(); + AUKN_SYM time_t SToCTime(AuInt64 time) { return CalculateTimeT(time); @@ -262,6 +268,22 @@ namespace Aurora::Time return 1000000000ull / 100u; #endif + #if defined(AURORA_IS_POSIX_DERIVED) + ::timespec spec {}; + if (::clock_getres(CLOCK_THREAD_CPUTIME_ID, &spec) == 0) + { + if (spec.tv_nsec && !spec.tv_sec) + { + return frequency = 1000000000ull / spec.tv_nsec; + } + else + { + SysUnreachable(); + return 0; + } + } + #endif + return HighResClockJiffies(); } @@ -333,6 +355,22 @@ namespace Aurora::Time return 1000000000ull / 100u; #endif + #if defined(AURORA_IS_POSIX_DERIVED) + ::timespec spec {}; + if (::clock_getres(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0) + { + if (spec.tv_nsec && !spec.tv_sec) + { + return frequency = 1000000000ull / spec.tv_nsec; + } + else + { + SysUnreachable(); + return 0; + } + } + #endif + return HighResClockJiffies(); } @@ -380,26 +418,6 @@ namespace Aurora::Time return epochDelta + in; } - AUKN_SYM double CPUFrequencyDeltaNS() - { - static double frequency = 0; - if (frequency != 0) - { - return frequency; - } - return frequency = (static_cast(high_res_clock::period::num) / static_cast(high_res_clock::period::den) * 1'000'000'000.f); - } - - AUKN_SYM double CPUFrequencyDeltaMS() - { - static double frequency = 0; - if (frequency != 0) - { - return frequency; - } - return frequency = (static_cast(high_res_clock::period::num) / static_cast(high_res_clock::period::den) * 1'000.f); - } - AUKN_SYM AuUInt64 SteadyClockJiffies() { static AuUInt64 frequency = 0;