diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index 2a088bc8..a6052185 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -346,10 +346,10 @@ namespace Aurora bool bNoThreadNames { false }; 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. // 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 bEnableAgrSchedulingRatelimit : 1 { true }; AuUInt64 bPreferNt51XpMutexesOver8 : 1 { false }; @@ -358,7 +358,7 @@ namespace Aurora AuUInt64 bPreferNtCondvarOlderWinSpin : 1 { true }; AuUInt64 bPreferNtSemaphoreSpinTryLock : 1 { true }; AuUInt64 bPreferNtMutexSpinTryLock : 1 { true }; - AuUInt64 bPreferNtCondMutexSpinTryLock : 1 { true }; + AuUInt64 bPreferNtCondMutexSpinTryLock : 1 { false }; AuUInt64 bPreferLinuxSemaphoreSpinTryLock : 1 { true }; AuUInt64 bPreferLinuxMutexSpinTryLock : 1 { true }; AuUInt64 bPreferLinuxCondMutexSpinTryLock : 1 { true }; @@ -369,6 +369,8 @@ namespace Aurora AuUInt64 uUWPNanosecondEmulationMaxYields : 7 { 12 }; AuUInt64 bForceEnableAdaptiveSpin : 1 { false }; AuUInt64 bPreferLinuxAdaptiveSpin : 1 { true }; + AuUInt64 bPreferOldWin32AdaptiveSpin : 1 { true }; + AuUInt64 bPreferNewWin32AdaptiveSpin : 1 { true }; AuUInt64 uAdaptiveSpinCUCnt0 : 4 { 0 }; AuUInt64 uAdaptiveSpinCUCnt4 : 4 { 2 }; AuUInt64 uAdaptiveSpinCUCnt8 : 4 { 3 }; diff --git a/Source/Threading/Primitives/SMTYield.cpp b/Source/Threading/Primitives/SMTYield.cpp index c509c0d4..13c9726b 100644 --- a/Source/Threading/Primitives/SMTYield.cpp +++ b/Source/Threading/Primitives/SMTYield.cpp @@ -35,7 +35,7 @@ namespace Aurora::Threading return 16; } - uCount = 1u << AuUInt32(gRuntimeConfig.threadingConfig.uSpinLoopPowerA); + uCount = AuUInt32(gRuntimeConfig.threadingConfig.uSpinLoopPowerA); if (gHasThreadLocalTimeout) { uCount += 1u << AuUInt32(tlsSpinCountLocal); @@ -70,7 +70,6 @@ namespace Aurora::Threading::Primitives { auto uCores = AuHwInfo::GetCPUInfo().uThreads; - gSpinLinearPart = gRuntimeConfig.threadingConfig.uSpinLoopLinearBit; gUseFutexRWLock = gRuntimeConfig.threadingConfig.bPreferFutexRWLock && IsWaitOnRecommended(); @@ -121,7 +120,11 @@ namespace Aurora::Threading::Primitives #else if (AuSwInfo::IsWindows10OrGreater()) { - gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = true; + gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = gRuntimeConfig.threadingConfig.bPreferNewWin32AdaptiveSpin; + } + else + { + gRuntimeConfig.threadingConfig.bForceEnableAdaptiveSpin = gRuntimeConfig.threadingConfig.bPreferOldWin32AdaptiveSpin; } #endif } diff --git a/Source/Threading/Primitives/SMTYield.hpp b/Source/Threading/Primitives/SMTYield.hpp index 37e804b4..02c9e410 100644 --- a/Source/Threading/Primitives/SMTYield.hpp +++ b/Source/Threading/Primitives/SMTYield.hpp @@ -17,7 +17,6 @@ namespace Aurora::Threading::Primitives { inline AuUInt32 gSpinAdaptiveThreshold {}; inline AuUInt32 gSpinAdaptiveCurrentCount {}; - inline AuUInt32 gSpinLinearPart {}; inline AuUInt32 gUseFutexRWLock {}; @@ -54,15 +53,9 @@ namespace Aurora::Threading::Primitives if (uNow <= gSpinAdaptiveThreshold) { - int loops = (1 << spin); - auto uLinear = gSpinLinearPart; + int loops = spin; while (loops > 0) { - for (AU_ITERATE_N(i, uLinear)) - { - SMPPause(); - } - loops -= 1; if (callback()) @@ -95,7 +88,7 @@ namespace Aurora::Threading::Primitives } else { - int loops = (1 << spin) / 3; + int loops = (spin) / 3; while (loops > 0) { SMPPause(); @@ -114,15 +107,9 @@ namespace Aurora::Threading::Primitives } else { - int loops = (1 << spin); - auto uLinear = gSpinLinearPart; + int loops = spin; while (loops > 0) { - for (AU_ITERATE_N(i, uLinear)) - { - SMPPause(); - } - loops -= 1; if (callback())