[*] NT: further optimizations to solve CPU usage regressions

This commit is contained in:
Reece Wilson 2023-09-02 15:29:42 +01:00
parent 9fbdafea74
commit cc6e0358fa
3 changed files with 26 additions and 10 deletions

View File

@ -20,8 +20,7 @@ namespace Aurora::Async
AuSPtr<ThreadState> GroupState::GetThreadByIndex(ThreadId_t uIndex)
{
AU_LOCK_GUARD(this->workersMutex);
// TODO: deinit mutex
if (AuArraySize(this->wpWorkers) > uIndex)
{
if (auto pState = AuTryLockMemoryType(this->wpWorkers[uIndex]))
@ -30,6 +29,8 @@ namespace Aurora::Async
}
}
AU_LOCK_GUARD(this->workersMutex);
auto itr = this->workers.find(uIndex);
if (itr == this->workers.end())
{

View File

@ -653,7 +653,7 @@ namespace Aurora::IO::Loop
{
if (this->bIsWinLoop_)
{
status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
}
else
{
@ -881,7 +881,7 @@ namespace Aurora::IO::Loop
{
do
{
status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_ALERTABLE);
{
auto temp2 = status;
@ -983,7 +983,7 @@ namespace Aurora::IO::Loop
{
if (this->bIsWinLoop_)
{
temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE);
}
else
{
@ -1032,11 +1032,15 @@ namespace Aurora::IO::Loop
}
else
{
if (!poll &&
TryPumpWin32())
static Aurora::Utility::RateLimiter limit(AuMSToNS<AuUInt64>(24));
if (limit.CheckExchangePass())
{
triggeredCount++;
bTriggerWin32 = true;
if (!poll && TryPumpWin32())
{
triggeredCount++;
bTriggerWin32 = true;
}
}
}

View File

@ -653,8 +653,19 @@ namespace Aurora::Threading::Primitives
if (!gUseFutexRWLock)
{
#if 0
AU_LOCK_GUARD(this->mutex_); /* actually locking this->state_, out of branch. required for the mutually exclusive correctness of the condition. this is a fence. */
bElevation = AuAtomicLoad(&this->writersPending_) > 0;
#else
bElevation = AuAtomicLoad(&this->writersPending_) > 0;
// Do barrier to ensure the sleep count is incremented and therefore validate the condition is in a to-wake state
if (bElevation)
{
this->mutex_.Lock();
this->mutex_.Unlock();
}
#endif
}
else
{
@ -769,8 +780,8 @@ namespace Aurora::Threading::Primitives
if (!gUseFutexRWLock)
{
AU_LOCK_GUARD(this->mutex_);
AuAtomicAdd(&this->writersPending_, 1);
AU_LOCK_GUARD(this->mutex_);
while (this->state_ != 1)
{