From fc08e8351d361c35e166a99e825d2fcd36d36bf0 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Thu, 3 Aug 2023 23:51:27 +0100 Subject: [PATCH] [+] Begin work on a POSIX 2001 based clock implementation as opposed to the retarded stinking free-shit glibc toddlers hacked together alongside linux vdso. Once again, a POSIX spec from 2001 and NT kernel releases from 2 decades ago are much better than whatever the hell Linux toddlers are up to in the 2020s. Fuck your 1998 POSIX1.b UNIX ass interface with extensions that dont even provide the functionality of POSIX 2001. Much like how UWP is forcing us to support Windows XP, Linux retardation is pushing us towards legacy POSIX support (the deprecation of AuProcesses pidfd requirements, now this) Alongside this, https://gitea.reece.sx/AuroraSupport/AuroraRuntime/issues/60, this is yet another monthly reminder that the Linux kernel maintainers are the most useless incompetent boomers gluing forced-source drivers into a monolithic mess. PS: if i wasnt malding before, i am now after trying to unearth the context of this disaster. https://nextcloud.reece.sx/index.php/s/jx82SsygJYWSir6/preview https://nextcloud.reece.sx/index.php/s/RpRpNbnBixyMT5G/preview https://nextcloud.reece.sx/index.php/s/NfMfDCcxL6sfXCf/preview https://nextcloud.reece.sx/index.php/s/7A4t5JNzzFctPT6/preview https://nextcloud.reece.sx/index.php/s/cyYwm8GPLKiLFqS/preview Bills peen company had this figured out before < LINUX 2.2 1999 EVEN HAD CLOCK APIs. ARE YOU FUCKING KIDDING? LINUXs MAIN CLOCK IMPLEMENTATION WASNT EVEN DONE UNTIL 2002 BY ONE GEORGE BECAUSE PATHER DIDNT FUCK IT UP ENOUGH? Freetards should get the wall. I don't know how these braindead fuckers could've ever eaten a bowl of cereal without choking on the milk and dying. * 2002-10-15 Posix Clocks & timers by George Anzinger [...] These are all the functions necessary to implement POSIX clocks & timers Meanwhile at Microsoft in 1997, ... I just cant anymore. Why the fuck are we even paying lip service to Linshit? --- Source/Time/AuClock.cpp | 85 ++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/Source/Time/AuClock.cpp b/Source/Time/AuClock.cpp index 3d9c4fa4..ab622743 100644 --- a/Source/Time/AuClock.cpp +++ b/Source/Time/AuClock.cpp @@ -209,9 +209,68 @@ namespace Aurora::Time return std::chrono::duration_cast(NormalizeEpoch(std::chrono::nanoseconds(time))).count(); } +#if defined(AURORA_IS_POSIX_DERIVED) + + enum class EPseudoPosixClock + { + eUser, + eKernel, + eAll + }; + + static AuUInt64 GetPOSIXTimeEx(struct rusage *usage, EPseudoPosixClock e) + { + struct timeval *tv {}; + + switch (e) + { + case EPseudoPosixClock::eAll: + { + return GetPOSIXTimeEx(usage, EPseudoPosixClock::eKernel) + + GetPOSIXTimeEx(usage, EPseudoPosixClock::eUser); + } + case EPseudoPosixClock::eUser: + { + tv = &usage->ru_utime; + break; + } + case EPseudoPosixClock::eKernel: + { + tv = &usage->ru_stime; + break; + } + }; + + auto uMS = AuSToMS(tv->tv_sec); + auto uNS = AuMSToNS(uMS) + + tv->tv_usec * 1'000ull; + + return uNS; + } + + static AuUInt64 GetPOSIXTime(bool bThread, EPseudoPosixClock e) + { + struct rusage usage; + + getrusage(bThread ? RUSAGE_THREAD : RUSAGE_SELF, + &usage); + + return GetPOSIXTimeEx(&usage, e); + } + + #if !defined(CLOCK_THREAD_CPUTIME_ID) + #define CLOCK_THREAD_CPUTIME_ID 0 + #endif + + #if !defined(CLOCK_PROCESS_CPUTIME_ID) + #define CLOCK_PROCESS_CPUTIME_ID 0 + #endif + +#endif + #if defined(AURORA_IS_MODERNNT_DERIVED) -#define ADD_CLOCK_FAMILY(fn, type, expr, posixId) \ +#define ADD_CLOCK_FAMILY(fn, type, expr, posixId, posixCall) \ AUKN_SYM AuUInt64 fn ## ClockJiffies(); \ \ AUKN_SYM AuUInt64 fn ## ClockMS() \ @@ -270,14 +329,14 @@ namespace Aurora::Time #elif defined(AURORA_IS_POSIX_DERIVED) -#define ADD_CLOCK_FAMILY(fn, type, expr, posixId) \ +#define ADD_CLOCK_FAMILY(fn, type, expr, posixId, posixCall) \ AUKN_SYM AuUInt64 fn ## ClockJiffies(); \ \ AUKN_SYM AuUInt64 fn ## ClockMS() \ { \ if (!posixId) \ { \ - return {}; \ + return AuNSToMS(GetPOSIXTime AU_WHAT(posixCall)); \ } \ return AuNSToMS(fn ## ClockNS()); \ } \ @@ -286,7 +345,7 @@ namespace Aurora::Time { \ if (!posixId) \ { \ - return {}; \ + return GetPOSIXTime AU_WHAT(posixCall); \ } \ ::timespec spec {}; \ if (::clock_gettime(posixId, &spec) == 0) \ @@ -300,7 +359,7 @@ namespace Aurora::Time { \ if (!posixId) \ { \ - return {}; \ + return fn ##ClockNS() / 1000ull; \ } \ return fn ##ClockNS() / (1000000000ull / fn ## ClockJiffies()); \ } \ @@ -309,7 +368,7 @@ namespace Aurora::Time { \ if (!posixId) \ { \ - return {}; \ + return 1'000'000ull; \ } \ static AuUInt64 frequency = 0; \ if (frequency != 0) \ @@ -357,13 +416,13 @@ namespace Aurora::Time } #endif - - ADD_CLOCK_FAMILY(Process, Process, (ullUser.QuadPart + ullKernel.QuadPart), CLOCK_PROCESS_CPUTIME_ID); - ADD_CLOCK_FAMILY(ProcessKernel, Process, (ullKernel.QuadPart), 0); - ADD_CLOCK_FAMILY(ProcessUser, Process, (ullUser.QuadPart), CLOCK_PROCESS_CPUTIME_ID); - ADD_CLOCK_FAMILY(Thread, Thread, (ullUser.QuadPart + ullKernel.QuadPart), CLOCK_THREAD_CPUTIME_ID); - ADD_CLOCK_FAMILY(ThreadKernel, Thread, (ullKernel.QuadPart), 0); - ADD_CLOCK_FAMILY(ThreadUser, Thread, (ullUser.QuadPart), CLOCK_THREAD_CPUTIME_ID); + + ADD_CLOCK_FAMILY(Process, Process, (ullUser.QuadPart + ullKernel.QuadPart), CLOCK_PROCESS_CPUTIME_ID, (false, EPseudoPosixClock::eAll)); + ADD_CLOCK_FAMILY(ProcessKernel, Process, (ullKernel.QuadPart), 0, (false, EPseudoPosixClock::eKernel)); + ADD_CLOCK_FAMILY(ProcessUser, Process, (ullUser.QuadPart), CLOCK_PROCESS_CPUTIME_ID, (false, EPseudoPosixClock::eUser)); + ADD_CLOCK_FAMILY(Thread, Thread, (ullUser.QuadPart + ullKernel.QuadPart), CLOCK_THREAD_CPUTIME_ID, (true, EPseudoPosixClock::eAll)); + ADD_CLOCK_FAMILY(ThreadKernel, Thread, (ullKernel.QuadPart), 0, (true, EPseudoPosixClock::eKernel)); + ADD_CLOCK_FAMILY(ThreadUser, Thread, (ullUser.QuadPart), CLOCK_THREAD_CPUTIME_ID, (true, EPseudoPosixClock::eUser)); AUKN_SYM AuInt64 ConvertAuroraToUnixMS(AuInt64 in) {