[*] Rework SMT yielding
This commit is contained in:
parent
6a3b278ea0
commit
8fe2619673
@ -346,10 +346,10 @@ namespace Aurora
|
|||||||
|
|
||||||
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 before yielding into the kernel
|
||||||
AuUInt8 uSpinLoopPowerA { 3 }; // Nudgable spinloop power. This is our local userland niceness factor; where 1 << n is the amount of smt-yield instructions to stall for
|
AuUInt8 uSpinLoopPowerA { 40 }; // 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 { 6 };
|
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 };
|
||||||
@ -358,7 +358,7 @@ namespace Aurora
|
|||||||
AuUInt64 bPreferNtCondvarOlderWinSpin : 1 { true };
|
AuUInt64 bPreferNtCondvarOlderWinSpin : 1 { true };
|
||||||
AuUInt64 bPreferNtSemaphoreSpinTryLock : 1 { true };
|
AuUInt64 bPreferNtSemaphoreSpinTryLock : 1 { true };
|
||||||
AuUInt64 bPreferNtMutexSpinTryLock : 1 { true };
|
AuUInt64 bPreferNtMutexSpinTryLock : 1 { true };
|
||||||
AuUInt64 bPreferNtCondMutexSpinTryLock : 1 { true };
|
AuUInt64 bPreferNtCondMutexSpinTryLock : 1 { false };
|
||||||
AuUInt64 bPreferLinuxSemaphoreSpinTryLock : 1 { true };
|
AuUInt64 bPreferLinuxSemaphoreSpinTryLock : 1 { true };
|
||||||
AuUInt64 bPreferLinuxMutexSpinTryLock : 1 { true };
|
AuUInt64 bPreferLinuxMutexSpinTryLock : 1 { true };
|
||||||
AuUInt64 bPreferLinuxCondMutexSpinTryLock : 1 { true };
|
AuUInt64 bPreferLinuxCondMutexSpinTryLock : 1 { true };
|
||||||
@ -369,6 +369,8 @@ namespace Aurora
|
|||||||
AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 };
|
AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 };
|
||||||
AuUInt64 bForceEnableAdaptiveSpin : 1 { false };
|
AuUInt64 bForceEnableAdaptiveSpin : 1 { false };
|
||||||
AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true };
|
AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true };
|
||||||
|
AuUInt64 bPreferOldWin32AdaptiveSpin : 1 { true };
|
||||||
|
AuUInt64 bPreferNewWin32AdaptiveSpin : 1 { true };
|
||||||
AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 };
|
AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 };
|
||||||
AuUInt64 uAdaptiveSpinCUCnt4 : 4 { 2 };
|
AuUInt64 uAdaptiveSpinCUCnt4 : 4 { 2 };
|
||||||
AuUInt64 uAdaptiveSpinCUCnt8 : 4 { 3 };
|
AuUInt64 uAdaptiveSpinCUCnt8 : 4 { 3 };
|
||||||
|
@ -35,7 +35,7 @@ namespace Aurora::Threading
|
|||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
uCount = 1u << AuUInt32(gRuntimeConfig.threadingConfig.uSpinLoopPowerA);
|
uCount = AuUInt32(gRuntimeConfig.threadingConfig.uSpinLoopPowerA);
|
||||||
if (gHasThreadLocalTimeout)
|
if (gHasThreadLocalTimeout)
|
||||||
{
|
{
|
||||||
uCount += 1u << AuUInt32(tlsSpinCountLocal);
|
uCount += 1u << AuUInt32(tlsSpinCountLocal);
|
||||||
@ -70,7 +70,6 @@ namespace Aurora::Threading::Primitives
|
|||||||
{
|
{
|
||||||
auto uCores = AuHwInfo::GetCPUInfo().uThreads;
|
auto uCores = AuHwInfo::GetCPUInfo().uThreads;
|
||||||
|
|
||||||
gSpinLinearPart = gRuntimeConfig.threadingConfig.uSpinLoopLinearBit;
|
|
||||||
gUseFutexRWLock = gRuntimeConfig.threadingConfig.bPreferFutexRWLock &&
|
gUseFutexRWLock = gRuntimeConfig.threadingConfig.bPreferFutexRWLock &&
|
||||||
IsWaitOnRecommended();
|
IsWaitOnRecommended();
|
||||||
|
|
||||||
@ -121,7 +120,11 @@ namespace Aurora::Threading::Primitives
|
|||||||
#else
|
#else
|
||||||
if (AuSwInfo::IsWindows10OrGreater())
|
if (AuSwInfo::IsWindows10OrGreater())
|
||||||
{
|
{
|
||||||
gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = true;
|
gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = gRuntimeConfig.threadingConfig.bPreferNewWin32AdaptiveSpin;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = gRuntimeConfig.threadingConfig.bPreferOldWin32AdaptiveSpin;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ namespace Aurora::Threading::Primitives
|
|||||||
{
|
{
|
||||||
inline AuUInt32 gSpinAdaptiveThreshold {};
|
inline AuUInt32 gSpinAdaptiveThreshold {};
|
||||||
inline AuUInt32 gSpinAdaptiveCurrentCount {};
|
inline AuUInt32 gSpinAdaptiveCurrentCount {};
|
||||||
inline AuUInt32 gSpinLinearPart {};
|
|
||||||
|
|
||||||
inline AuUInt32 gUseFutexRWLock {};
|
inline AuUInt32 gUseFutexRWLock {};
|
||||||
|
|
||||||
@ -54,15 +53,9 @@ namespace Aurora::Threading::Primitives
|
|||||||
|
|
||||||
if (uNow <= gSpinAdaptiveThreshold)
|
if (uNow <= gSpinAdaptiveThreshold)
|
||||||
{
|
{
|
||||||
int loops = (1 << spin);
|
int loops = spin;
|
||||||
auto uLinear = gSpinLinearPart;
|
|
||||||
while (loops > 0)
|
while (loops > 0)
|
||||||
{
|
{
|
||||||
for (AU_ITERATE_N(i, uLinear))
|
|
||||||
{
|
|
||||||
SMPPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
loops -= 1;
|
loops -= 1;
|
||||||
|
|
||||||
if (callback())
|
if (callback())
|
||||||
@ -95,7 +88,7 @@ namespace Aurora::Threading::Primitives
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int loops = (1 << spin) / 3;
|
int loops = (spin) / 3;
|
||||||
while (loops > 0)
|
while (loops > 0)
|
||||||
{
|
{
|
||||||
SMPPause();
|
SMPPause();
|
||||||
@ -114,15 +107,9 @@ namespace Aurora::Threading::Primitives
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int loops = (1 << spin);
|
int loops = spin;
|
||||||
auto uLinear = gSpinLinearPart;
|
|
||||||
while (loops > 0)
|
while (loops > 0)
|
||||||
{
|
{
|
||||||
for (AU_ITERATE_N(i, uLinear))
|
|
||||||
{
|
|
||||||
SMPPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
loops -= 1;
|
loops -= 1;
|
||||||
|
|
||||||
if (callback())
|
if (callback())
|
||||||
|
Loading…
Reference in New Issue
Block a user