[*] Remove a syscall or two from startup / more accurate startup timings

This commit is contained in:
Reece Wilson 2023-12-18 05:57:37 +00:00
parent 207b8f6f46
commit f40d59802a
3 changed files with 29 additions and 30 deletions

View File

@ -38,6 +38,7 @@
#include "Memory/Cache.hpp"
#include "Threading/Primitives/SMTYield.hpp"
#include <mimalloc.h>
#include "Process/AuProcessStartTime.hpp"
#include "AuProcAddresses.hpp"
#if defined(AURORA_IS_LINUX_DERIVED)
@ -72,8 +73,7 @@ static void Init()
Crypto::InitCrypto();
Aurora::IO::TLS::TLSInit();
(void)AuProcess::GetProcessStartupTimeMS();
(void)AuProcess::GetProcessStartupSteadyTimeNS();
AuProcess::WarmStartupCaches();
Aurora::Threading::InitSleep();
Aurora::Process::InitProcess();

View File

@ -11,26 +11,37 @@
namespace Aurora::Process
{
AUKN_SYM AuUInt64 GetProcessStartupTimeNS()
{
static AuOptional<AuUInt64> optKnownWallTime;
if (optKnownWallTime.has_value())
{
return optKnownWallTime.value();
}
static AuOptional<AuUInt64> gOptKnownStartupWallTime;
static AuOptional<AuUInt64> gOptKnownStartupSteadyTime;
void WarmStartupCaches()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
FILETIME creation, exit, kernel, user;
if (::GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user))
{
optKnownWallTime = AuTime::ConvertTimestampNs(creation);
auto u64 = AuTime::ConvertTimestampNs(creation);
gOptKnownStartupWallTime = u64;
u64 += AuTime::SteadyClockNS() - AuTime::CurrentClockNS();
gOptKnownStartupSteadyTime = u64;
}
#else
optKnownWallTime = AuTime::CurrentClockNS() - AuTime::ThreadClockNS();
auto u64 = AuTime::ThreadClockNS();
gOptKnownStartupWallTime = AuTime::CurrentClockNS() - u64;
gOptKnownStartupSteadyTime = AuTime::SteadyClockNS() - u64;
#endif
}
return optKnownWallTime.value();
AUKN_SYM AuUInt64 GetProcessStartupTimeNS()
{
if (gOptKnownStartupWallTime.has_value())
{
return gOptKnownStartupWallTime.value();
}
WarmStartupCaches();
return gOptKnownStartupWallTime.value();
}
AUKN_SYM AuUInt64 GetProcessStartupTimeMS()
@ -40,25 +51,13 @@ namespace Aurora::Process
AUKN_SYM AuUInt64 GetProcessStartupSteadyTimeNS()
{
static AuOptional<AuUInt64> optKnownTime;
if (optKnownTime.has_value())
if (gOptKnownStartupSteadyTime.has_value())
{
return optKnownTime.value();
return gOptKnownStartupSteadyTime.value();
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
FILETIME creation, exit, kernel, user;
if (::GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user))
{
auto u64 = AuTime::ConvertTimestampNs(creation);
u64 += AuTime::SteadyClockNS() - AuTime::CurrentClockNS();
optKnownTime = u64;
}
#else
optKnownTime = AuTime::SteadyClockNS() - AuTime::ThreadClockNS();
#endif
WarmStartupCaches();
return optKnownTime.value();
return gOptKnownStartupSteadyTime.value();
}
}

View File

@ -9,5 +9,5 @@
namespace Aurora::Process
{
void WarmStartupCaches();
}