[+] ICoreLoadSampler::SetNoAggressiveFiltering

[+] ICoreLoadSampler::GetNoAggressiveFiltering
[+] IProcessLoadSampler::SetNoAggressiveFiltering
[+] IProcessLoadSampler::GetNoAggressiveFiltering
[*] load samplers: surly these even filters / averaging of decreasing low condition were written incorrectly

i dont like this logic so much, but from what i recall, it was required to get sane values out of real world use cases.
mathematically accurate? no.
produced some clean output close enough to resource monitors? yes

will need to retest later
This commit is contained in:
Reece Wilson 2024-12-24 18:54:47 +00:00
parent 8e648a4737
commit 70b5b3e367
6 changed files with 69 additions and 9 deletions

View File

@ -23,11 +23,15 @@ namespace Aurora::HWInfo
virtual double GetTotalLoadCached() = 0;
virtual double *GetCoreLoadsCached(AuUInt32 *pOut) = 0;
virtual void SetNoAggressiveFiltering(bool bNoFiltering) = 0;
virtual bool GetNoAggressiveFiltering() = 0;
};
AUKN_SHARED_API(CoreLoadSampler, ICoreLoadSampler,
AuUInt32 uMinSamplePeriodMS = AuSToMS<AuUInt32>(1),
bool bCountKernelUsage = true);
AUKN_SHARED_SOO2_NCM(CoreLoadSampler, ICoreLoadSampler, 128,
((AuUInt32, uMinSamplePeriodMS), (bool, bCountKernelUsage)),
AuUInt32 uMinSamplePeriodMS = AuSToMS<AuUInt32>(1),
bool bCountKernelUsage = true);
AUKN_SYM ICoreLoadSampler *GetDefaultCoreLoadSampler();
}

View File

@ -20,9 +20,12 @@ namespace Aurora::HWInfo
* @return a percentage (0 - 100; as a decimal) of the local process or thread CPU usage between ::GetLoad() calls, with respect to a uMinSamplePeriod averaging period.
*/
virtual double GetLoad() = 0;
virtual void SetNoAggressiveFiltering(bool bNoFiltering) = 0;
virtual bool GetNoAggressiveFiltering() = 0;
};
AUKN_SHARED_SOO2_NCM(ProcessLoadSampler, IProcessLoadSampler, 64,
AUKN_SHARED_SOO2_NCM(ProcessLoadSampler, IProcessLoadSampler, 128,
((AuUInt32, uMinSamplePeriodMS), (bool, bThreadMode), (bool, bCountKernelUsage)),
AuUInt32 uMinSamplePeriodMS = AuSToMS<AuUInt32>(1), // May be zero
bool bThreadMode = false, // False = Sample Process Usage | True = Sample Thread Usage

View File

@ -116,12 +116,25 @@ namespace Aurora::HWInfo
{
dUsage[i] = dDeltaCore[i] / dDeltaSteady;
if (uMinSamplePeriod)
if (this->bNoAggressiveFiltering)
{
// nop
}
else if (uMinSamplePeriod)
{
if (dUsage[i] > AuNumericLimits<double>::epsilon() &&
this->dPrevLoad[i] > AuNumericLimits<double>::epsilon())
{
dUsage[i] = AuMin(dUsage[i], dUsage[i] + this->dPrevLoad[i] / 2.0);
if (dDeltaSteady >= AuMSToNS<AuUInt64>(1000))
{
// slow tick rage: high pass filter
dUsage[i] = AuMin(dUsage[i], (dUsage[i] * 0.75) + (this->dPrevLoad[i] * 0.25));
}
else
{
// fast tick rate: increase in load no faster than the average
dUsage[i] = AuMin(dUsage[i], (dUsage[i] + this->dPrevLoad[i]) / 2.0);
}
}
else
{
@ -214,10 +227,20 @@ namespace Aurora::HWInfo
return this->state.dCurrentLoad;
}
void CoreLoadSamplerImpl::SetNoAggressiveFiltering(bool bNoFiltering)
{
this->state.bNoAggressiveFiltering = bNoFiltering;
}
bool CoreLoadSamplerImpl::GetNoAggressiveFiltering()
{
return this->state.bNoAggressiveFiltering;
}
AUKN_SYM ICoreLoadSampler *CoreLoadSamplerNew(AuUInt32 uMinSamplePeriodMS,
bool bCountKernelUsage)
{
return _new CoreLoadSamplerImpl(uMinSamplePeriodMS, bCountKernelUsage);
return _new CoreLoadSamplerImpl(uMinSamplePeriodMS, bCountKernelUsage);
}
AUKN_SYM void CoreLoadSamplerRelease(ICoreLoadSampler *pSampler)
@ -229,4 +252,6 @@ namespace Aurora::HWInfo
{
return &gDefaultCoreUsageSampler;
}
AUROXTL_INTERFACE_SOO_SRC_EX(AURORA_SYMBOL_EXPORT, CoreLoadSampler, CoreLoadSamplerImpl, (AuUInt32, uMinSamplePeriod), (bool, bCountKernelUsage))
}

View File

@ -22,6 +22,7 @@ namespace Aurora::HWInfo
double dCurrentLoadAll {};
AuUInt64 uCount {};
bool bSet {};
bool bNoAggressiveFiltering {};
};
struct CoreLoadSamplerImpl : ICoreLoadSampler
@ -36,6 +37,8 @@ namespace Aurora::HWInfo
double GetTotalLoadCached() override;
double GetCoreLoadCached(AuUInt8 uCore) override;
double *GetCoreLoadsCached(AuUInt32 *pOut) override;
void SetNoAggressiveFiltering(bool bNoFiltering) override;
bool GetNoAggressiveFiltering() override;
AuUInt32 uMinSamplePeriod {};
bool bCountKernelUsage {};

View File

@ -84,12 +84,24 @@ namespace Aurora::HWInfo
dUsage = dDeltaProcess / dDeltaSteady2;
this->uPrevTimes[1] = now[1];
this->uPrevTimes[0] = now[0];
if (uMinSamplePeriod)
if (this->bNoAggressiveFiltering)
{
// nop
}
else if (uMinSamplePeriod)
{
if (dUsage > AuNumericLimits<double>::epsilon() &&
this->dPrevLoad > AuNumericLimits<double>::epsilon())
{
dUsage = AuMin(dUsage, dUsage + this->dPrevLoad / 2.0);
if (dDeltaSteady >= AuMSToNS<AuUInt64>(1000))
{
dUsage = AuMin(dUsage, (dUsage * 0.75) + (this->dPrevLoad * 0.25));
}
else
{
dUsage = AuMin(dUsage, (dUsage + this->dPrevLoad) / 2.0);
}
}
else
{
@ -164,6 +176,16 @@ namespace Aurora::HWInfo
}
}
void ProcessLoadSamplerImpl::SetNoAggressiveFiltering(bool bNoFiltering)
{
this->processState.bNoAggressiveFiltering = bNoFiltering;
}
bool ProcessLoadSamplerImpl::GetNoAggressiveFiltering()
{
return this->processState.bNoAggressiveFiltering;
}
AUKN_SYM double GetProcessCPUUtilization()
{
return gProcessUsageSampler.GetLoad();

View File

@ -16,6 +16,7 @@ namespace Aurora::HWInfo
AuUInt64 uPrevTimes[2] {};
double dPrevLoad {};
bool bSet {};
bool bNoAggressiveFiltering {};
};
struct ProcessLoadSamplerImpl : IProcessLoadSampler
@ -27,6 +28,8 @@ namespace Aurora::HWInfo
~ProcessLoadSamplerImpl();
double GetLoad() override;
void SetNoAggressiveFiltering(bool bNoFiltering) override;
bool GetNoAggressiveFiltering() override;
AuUInt32 uMinSamplePeriod {};
bool bThreadMode {};