diff --git a/Include/Aurora/Async/Async.hpp b/Include/Aurora/Async/Async.hpp index e55a5da2..6fce5074 100644 --- a/Include/Aurora/Async/Async.hpp +++ b/Include/Aurora/Async/Async.hpp @@ -41,13 +41,13 @@ namespace Aurora::Async AUKN_SYM AuSPtr NewTimer(AuUInt64 uPeriodNS, const AuSPtr &pCallback, - AuOptional workerPid, - AuOptional uStartTime); + AuOptional workerPid = {}, + AuOptional uStartTime = {}); AUKN_SYM AuSPtr NewTimer(AuUInt64 uPeriodNS, const AuSupplierConsumer &callback, - AuOptional workerPid, - AuOptional uStartTime); + AuOptional workerPid = {}, + AuOptional uStartTime = {}); static inline AuSPtr DispatchOn(const WorkerPId_t &worker, AuVoidFunc func) { diff --git a/Source/HWInfo/AuCpuLoadSampler.cpp b/Source/HWInfo/AuCpuLoadSampler.cpp index 403db5dc..487d4a8e 100644 --- a/Source/HWInfo/AuCpuLoadSampler.cpp +++ b/Source/HWInfo/AuCpuLoadSampler.cpp @@ -58,46 +58,93 @@ namespace Aurora::HWInfo double dDeltaProcess = now[1] - this->uPrevTimes[1]; double dUsage = 0; double dMinSamplePeriod = double(AuMSToNS(uMinSamplePeriod)); + double dDeltaSteady2; + double dThreads = 1.0; + + if (bThread) + { + dThreads = GetCPUInfo().uThreads; + dDeltaSteady2 = dDeltaSteady * dThreads; + } + else + { + dDeltaSteady2 = dDeltaSteady; + } if (!bool(this->uPrevTimes[0])) { - this->uPrevTimes[1] = now[1]; this->uPrevTimes[0] = now[0]; + this->uPrevTimes[1] = now[1]; return 0; } if (!uMinSamplePeriod || - dDeltaSteady >= dMinSamplePeriod) + (dDeltaSteady >= dMinSamplePeriod)) { - dUsage = dDeltaProcess / dDeltaSteady; + dUsage = dDeltaProcess / dDeltaSteady2; this->uPrevTimes[1] = now[1]; this->uPrevTimes[0] = now[0]; - #if 1 - if (uMinSamplePeriod && - this->dPrevLoad) dUsage = AuMin(dUsage, dUsage + this->dPrevLoad / 2.0); - #endif + if (uMinSamplePeriod) + { + if (dUsage > AuNumericLimits::epsilon() && + this->dPrevLoad > AuNumericLimits::epsilon()) + { + dUsage = AuMin(dUsage, dUsage + this->dPrevLoad / 2.0); + } + else + { + dUsage = AuMax(this->dPrevLoad / 2.0, 0.0001); + } + } + else if (!dUsage) + { + dUsage = AuMax(this->dPrevLoad / 2.0, 0.0001); + } this->dPrevLoad = dUsage; + this->bSet = true; } - else + else if (!dDeltaProcess && + !this->bSet) { - dUsage = dDeltaProcess / dDeltaSteady; + // well, we obviously have some uptime. but how much? + auto uDeltaNS = AuMin(dDeltaSteady, dMinSamplePeriod); + + if (uDeltaNS > AuMSToNS(1000 / 250)) + { + uDeltaNS = 100; + } + + dUsage = uDeltaNS / dDeltaSteady2; + } + else if (dDeltaProcess && + !this->bSet) + { + dUsage = dDeltaProcess / dDeltaSteady2; + } + else if (dDeltaProcess) + { + dUsage = dDeltaProcess / dDeltaSteady2; #if 0 - dUsage *= dDeltaSteady / double(dMinSamplePeriod); + dUsage *= dDeltaSteady2 / double(dMinSamplePeriod); if (this->dPrevLoad) dUsage = dUsage + this->dPrevLoad / 2.0; #else if (this->dPrevLoad) { - double dFrameDelta = dDeltaSteady / double(dMinSamplePeriod); - double dFrameDeltaInverse = 1.0 - dFrameDelta; + auto dFrameDelta = dDeltaSteady / dMinSamplePeriod; + auto dFrameDeltaInverse = 1.0 - dFrameDelta; dUsage *= dFrameDelta; dUsage += this->dPrevLoad * dFrameDeltaInverse; } else { - dUsage *= dDeltaSteady / double(dMinSamplePeriod); + dUsage *= dDeltaSteady / dMinSamplePeriod; } #endif } + else + { + dUsage = this->dPrevLoad; + } { dUsage = dUsage * 100.0; diff --git a/Source/HWInfo/AuCpuLoadSampler.hpp b/Source/HWInfo/AuCpuLoadSampler.hpp index cb5b1b02..12722166 100644 --- a/Source/HWInfo/AuCpuLoadSampler.hpp +++ b/Source/HWInfo/AuCpuLoadSampler.hpp @@ -15,6 +15,7 @@ namespace Aurora::HWInfo AuUInt64 uPrevTimes[2] {}; double dPrevLoad {}; + bool bSet {}; }; struct CpuLoadSamplerImpl : ICpuLoadSampler diff --git a/Source/Threading/Primitives/AuConditionVariable.NT.cpp b/Source/Threading/Primitives/AuConditionVariable.NT.cpp index 67d7b7ae..2361bc62 100644 --- a/Source/Threading/Primitives/AuConditionVariable.NT.cpp +++ b/Source/Threading/Primitives/AuConditionVariable.NT.cpp @@ -254,6 +254,9 @@ namespace Aurora::Threading::Primitives bool ConditionVariableNT::CheckOutNoSpin() { + #if defined(AURORA_FORCE_SRW_LOCKS) + return false; + #else auto uSignalNow = this->signalCount; if (uSignalNow == 0) @@ -285,6 +288,7 @@ namespace Aurora::Threading::Primitives } return true; + #endif } bool ConditionVariableNT::CheckOut()