[*] Improve WakeOnAddress by hash binning by kDefaultWaitPerProcess instead the previous iteration before BST or HashTree lookup

This commit is contained in:
Reece Wilson 2023-07-30 09:34:39 +01:00
parent 3ff5d8a74e
commit c306c12763
2 changed files with 44 additions and 9 deletions

View File

@ -183,11 +183,18 @@ namespace Aurora::Threading
bool WaitEntry::TryWakeNoLockNoReallyNoLock(const void *pAddress)
{
#if 0
if (AuReinterpretCast<const char *>(this->pAddress) > AuReinterpretCast<const char *>(pAddress) ||
AuReinterpretCast<const char *>(this->pAddress) + this->uSize <= AuReinterpretCast<const char *>(pAddress))
{
return false;
}
#else
if (this->pAddress != pAddress)
{
return false;
}
#endif
this->uAtomic = 0;
this->variable.Signal();
@ -196,11 +203,18 @@ namespace Aurora::Threading
bool WaitEntry::TryWakeNoLock(const void *pAddress)
{
#if 0
if (AuReinterpretCast<const char *>(this->pAddress) > AuReinterpretCast<const char *>(pAddress) ||
AuReinterpretCast<const char *>(this->pAddress) + this->uSize <= AuReinterpretCast<const char *>(pAddress))
{
return false;
}
#else
if (this->pAddress != pAddress)
{
return false;
}
#endif
AU_LOCK_GUARD(this->mutex);
this->uAtomic = 0;
@ -238,7 +252,7 @@ namespace Aurora::Threading
}
}
WaitEntry *ProcessWaitContainer::WaitBufferFrom(void *pAddress, AuUInt8 uSize)
WaitEntry *ProcessWaitNodeContainer::WaitBufferFrom(void *pAddress, AuUInt8 uSize)
{
#if defined(HACK_NO_INVALID_ACCESS_LEAK_SHARED_REF_ON_DESTROYED_THREAD)
auto pReturn = tlsWaitEntry.get();
@ -271,7 +285,7 @@ namespace Aurora::Threading
}
template <typename T>
bool ProcessWaitContainer::IterateWake(T callback)
bool ProcessWaitNodeContainer::IterateWake(T callback)
{
bool bRetStatus { true };
@ -324,16 +338,27 @@ namespace Aurora::Threading
return bRetStatus;
}
void ProcessWaitContainer::Lock()
void ProcessWaitNodeContainer::Lock()
{
DoSpinLockOnVar(&this->uAtomic);
}
void ProcessWaitContainer::Unlock()
void ProcessWaitNodeContainer::Unlock()
{
this->uAtomic = 0;
}
WaitEntry *ProcessWaitContainer::WaitBufferFrom(void *pAddress, AuUInt8 uSize)
{
return this->list[AuHashCode(pAddress) % AuArraySize(this->list)].WaitBufferFrom(pAddress, uSize);
}
template <typename T>
bool ProcessWaitContainer::IterateWake(void *pAddress, T callback)
{
return this->list[AuHashCode(pAddress) % AuArraySize(this->list)].IterateWake(callback);
}
AUKN_SYM bool IsWaitOnRecommended()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
@ -810,7 +835,7 @@ namespace Aurora::Threading
}
else
{
(void)gProcessWaitables.IterateWake([&](WaitEntry &entry) -> AuPair<bool, bool>
(void)gProcessWaitables.IterateWake(pTargetAddress, [&](WaitEntry &entry) -> AuPair<bool, bool>
{
if (!uNMaximumThreads)
{
@ -843,7 +868,7 @@ namespace Aurora::Threading
}
else
{
(void)gProcessWaitables.IterateWake([&](WaitEntry &entry) -> AuPair<bool, bool>
(void)gProcessWaitables.IterateWake(pTargetAddress, [&](WaitEntry &entry) -> AuPair<bool, bool>
{
return AuMakePair(true, entry.TryWakeNoLockNoReallyNoLock(pTargetAddress));
});

View File

@ -12,7 +12,7 @@
namespace Aurora::Threading
{
static const auto kDefaultWaitPerProcess = 12;
static const auto kDefaultWaitPerProcess = 64;
struct WaitState;
@ -71,7 +71,7 @@ namespace Aurora::Threading
WaitEntry *pTail {};
};
struct ProcessWaitContainer
struct ProcessWaitNodeContainer
{
AuUInt32 uAtomic {};
#if defined(WOA_ENABLE_OLD_SHORT_LIST)
@ -88,4 +88,14 @@ namespace Aurora::Threading
void Unlock();
};
struct ProcessWaitContainer
{
ProcessWaitNodeContainer list[kDefaultWaitPerProcess];
WaitEntry *WaitBufferFrom(void *pAddress, AuUInt8 uSize);
template <typename T>
bool IterateWake(void *pAddress, T callback);
};
}