[*] Tweak default thread config

[*] Fix regressions
This commit is contained in:
Reece Wilson 2023-08-27 21:27:49 +01:00
parent b2e1df8f72
commit 55c02d4aa0
3 changed files with 41 additions and 30 deletions

View File

@ -344,12 +344,11 @@ namespace Aurora
{ {
// WARN: these values are not final // WARN: these values are not final
bool bNoThreadNames { false }; bool bNoThreadNames { false };
bool bPlatformIsSMPProcessorOptimized { true }; // Whether to attempt to using mm_pause or similar before yielding into the kernel bool bPlatformIsSMPProcessorOptimized { true }; // Whether to attempt to using mm_pause or similar instruction before yielding into the kernel
AuUInt8 uSpinLoopPowerA { 80 }; // Nudgable spinloop power. This is our local userland niceness factor AuUInt16 uSpinLoopPowerA { 128 }; // Nudgable spinloop power. This is our local userland niceness factor
// This is comparable to Win32's SetCriticalSectionSpinCount applied across every single AuThreadPrimitives try-lock and lock. // This is comparable to Win32's SetCriticalSectionSpinCount applied across every single AuThreadPrimitives try-lock and lock.
// Adjust this value to compensate for longer critical sections when context switching isn't preferrable. // Adjust this value to compensate for longer critical sections when context switching isn't preferrable.
AuUInt8 uSpinLoopLinearBit { 1 };
AuUInt64 bEnableAggressiveScheduling : 1 { false }; AuUInt64 bEnableAggressiveScheduling : 1 { false };
AuUInt64 bEnableAgrSchedulingRatelimit : 1 { true }; AuUInt64 bEnableAgrSchedulingRatelimit : 1 { true };
AuUInt64 bPreferNt51XpMutexesOver8 : 1 { false }; AuUInt64 bPreferNt51XpMutexesOver8 : 1 { false };
@ -366,10 +365,10 @@ namespace Aurora
AuUInt64 bPreferWaitOnAddressAlwaysSpin : 1 { true }; // ..., if emulated! if double-spinning under higher level locks, disable me. AuUInt64 bPreferWaitOnAddressAlwaysSpin : 1 { true }; // ..., if emulated! if double-spinning under higher level locks, disable me.
AuUInt64 bPreferRWLockReadLockSpin : 1 { true }; AuUInt64 bPreferRWLockReadLockSpin : 1 { true };
AuUInt64 bUWPNanosecondEmulationCheckFirst : 1 { false }; AuUInt64 bUWPNanosecondEmulationCheckFirst : 1 { false };
AuUInt64 bForceEnableAdaptiveSpin : 1 { false }; AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 };
AuUInt64 bPreferEnableAdaptiveSpin : 1 { true }; AuUInt64 bForceEnableAdaptiveSpin : 1 { false }; // ||
AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 }; AuUInt64 bPreferEnableAdaptiveSpin : 1 { true }; // &&
AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true }; AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true }; // &&
AuUInt64 bPreferOldWin32AdaptiveSpin : 1 { false }; AuUInt64 bPreferOldWin32AdaptiveSpin : 1 { false };
AuUInt64 bPreferNewWin32AdaptiveSpin : 1 { true }; AuUInt64 bPreferNewWin32AdaptiveSpin : 1 { true };
AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 }; AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 };

View File

@ -485,7 +485,6 @@ namespace Aurora::Async
{ {
if (InRunnerMode()) if (InRunnerMode())
{ {
if ((this->uAtomicCounter == 0) && if ((this->uAtomicCounter == 0) &&
this->IsDepleted()) this->IsDepleted())
{ {

View File

@ -56,31 +56,36 @@ namespace Aurora::Threading::Primitives
int loops = spin; int loops = spin;
while (loops > 0) while (loops > 0)
{ {
loops -= 1;
if (callback()) if (callback())
{ {
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true; return true;
} }
else
{
SMPPause();
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
}
} }
if (gHasThreadLocalTimeout) if (gHasThreadLocalTimeout)
{ {
auto uCount = tlsSpinCountLocal; int loops = (1 << tlsSpinCountLocal);
int loops = (1 << uCount);
while (loops > 0) while (loops > 0)
{ {
SMPPause();
loops -= 1;
if (callback()) if (callback())
{ {
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true; return true;
} }
else
{
SMPPause();
loops--;
}
} }
} }
@ -91,15 +96,16 @@ namespace Aurora::Threading::Primitives
int loops = (spin) / 3; int loops = (spin) / 3;
while (loops > 0) while (loops > 0)
{ {
SMPPause();
loops -= 1;
if (callback()) if (callback())
{ {
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u); AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true; return true;
} }
else
{
SMPPause();
loops --;
}
} }
} }
@ -110,12 +116,18 @@ namespace Aurora::Threading::Primitives
int loops = spin; int loops = spin;
while (loops > 0) while (loops > 0)
{ {
loops -= 1;
if (callback()) if (callback())
{ {
return true; return true;
} }
else
{
SMPPause();
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
}
} }
if (gHasThreadLocalTimeout) if (gHasThreadLocalTimeout)
@ -125,14 +137,15 @@ namespace Aurora::Threading::Primitives
int loops = (1 << uCount); int loops = (1 << uCount);
while (loops > 0) while (loops > 0)
{ {
SMPPause();
loops -= 1;
if (callback()) if (callback())
{ {
return true; return true;
} }
else
{
SMPPause();
loops --;
}
} }
} }
} }