[*] Cleanup/formatting of SMT yields

This commit is contained in:
Reece Wilson 2023-09-06 16:24:43 +01:00
parent 3d8dd991e0
commit 36a72228db
6 changed files with 40 additions and 40 deletions

View File

@ -14,12 +14,10 @@ namespace Aurora
namespace Aurora::Threading
{
// Note: the following APIs are in powers of 2!
AUKN_SYM void SetSpinCountTimeout(AuUInt8 uTimeout);
AUKN_SYM AuUInt8 GetSpinCountTimeout();
AUKN_SYM void SetThreadLocalAdditionalSpinCountTimeout(AuUInt8 uTimeout);
AUKN_SYM AuUInt32 GetTotalSpinCountTimeout();
AUKN_SYM void SetSpinCountTimeout(AuUInt32 uTimeout);
AUKN_SYM AuUInt32 GetSpinCountTimeout();
AUKN_SYM void SetThreadLocalAdditionalSpinCountTimeout(AuUInt32 uTimeout);
AUKN_SYM AuUInt32 GetTotalSpinCountTime();
AUKN_SYM const ThreadingConfig *GetThreadingConfig();
AUKN_SYM void SetThreadingConfig(const ThreadingConfig *pUpdateConfig);

View File

@ -185,7 +185,7 @@ namespace Aurora::Threading::Waitables
}
#if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX)
AuUInt uCount(GetTotalSpinCountTimeout());
AuUInt uCount(GetTotalSpinCountTime());
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto uPerfCounter = __rdtsc() + uCount;
while (__rdtsc() < uPerfCounter)

View File

@ -33,7 +33,7 @@ namespace Aurora::Threading::Waitables
}
#if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX)
AuUInt uCount(GetTotalSpinCountTimeout());
AuUInt uCount(GetTotalSpinCountTime());
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto uPerfCounter = __rdtsc() + uCount;
while (__rdtsc() < uPerfCounter)

View File

@ -32,7 +32,7 @@ namespace Aurora::Threading::Waitables
}
#if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX)
AuUInt uCount(GetTotalSpinCountTimeout());
AuUInt uCount(GetTotalSpinCountTime());
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto uPerfCounter = __rdtsc() + uCount;
while (__rdtsc() < uPerfCounter)

View File

@ -10,37 +10,41 @@
namespace Aurora::Threading
{
AUKN_SYM void SetSpinCountTimeout(AuUInt8 uTimeout)
AUKN_SYM void SetSpinCountTimeout(AuUInt32 uTimeout)
{
gRuntimeConfig.threadingConfig.uSpinLoopPowerA = uTimeout;
}
AUKN_SYM AuUInt8 GetSpinCountTimeout()
AUKN_SYM AuUInt32 GetSpinCountTimeout()
{
return gRuntimeConfig.threadingConfig.uSpinLoopPowerA;
}
AUKN_SYM void SetThreadLocalAdditionalSpinCountTimeout(AuUInt8 uTimeout)
AUKN_SYM void SetThreadLocalAdditionalSpinCountTimeout(AuUInt32 uTimeout)
{
gHasThreadLocalTimeout = 1;
tlsSpinCountLocal = uTimeout;
}
AUKN_SYM AuUInt32 GetTotalSpinCountTimeout()
AUKN_SYM AuUInt32 GetTotalSpinCountTime()
{
AuUInt32 uCount {};
if (!gRuntimeConfig.threadingConfig.bPlatformIsSMPProcessorOptimized)
{
return 16;
return 0;
}
uCount = AuUInt32(gRuntimeConfig.threadingConfig.uSpinLoopPowerA);
if (gHasThreadLocalTimeout)
{
uCount += 1u << AuUInt32(tlsSpinCountLocal);
uCount += tlsSpinCountLocal;
}
//#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
// uCount *= 4;
//#endif
// well, i guess not because intel recommends going by rdtsc ticks, and not to assume eventual uop sleep of an unspecified period
return uCount;
}

View File

@ -10,7 +10,7 @@
namespace Aurora::Threading
{
inline AuUInt32 gHasThreadLocalTimeout {};
inline thread_local AuUInt8 tlsSpinCountLocal {};
inline thread_local AuUInt32 tlsSpinCountLocal {};
}
#define SPIN_FOUR 1
@ -55,12 +55,12 @@ namespace Aurora::Threading::Primitives
if (uNow <= gSpinAdaptiveThreshold)
{
int loops = spin;
auto uCount = spin;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + spin;
auto perfCounter = __rdtsc() + uCount;
while (__rdtsc() < perfCounter)
#else
while (loops > 0)
while (uCount > 0)
#endif
{
if (callback())
@ -75,89 +75,10 @@ namespace Aurora::Threading::Primitives
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
uCount -= 4;
#else
SMPPause();
loops -= 1;
#endif
}
}
if (gHasThreadLocalTimeout)
{
int loops = (1 << tlsSpinCountLocal);
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + loops;
while (__rdtsc() < perfCounter)
#else
while (loops > 0)
#endif
{
if (callback())
{
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true;
}
else
{
SMPPause();
loops--;
}
}
}
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
}
else
{
int loops = (spin) / 3;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + loops;
while (__rdtsc() < perfCounter)
#else
while (loops > 0)
#endif
{
if (callback())
{
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true;
}
else
{
SMPPause();
loops --;
}
}
}
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
}
else
{
int loops = spin;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + spin;
while (__rdtsc() < perfCounter)
#else
while (loops > 0)
#endif
{
if (callback())
{
return true;
}
else
{
#if defined(SPIN_FOUR) && SPIN_FOUR == 1
SMPPause();
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
#else
SMPPause();
loops -= 1;
uCount -= 1;
#endif
}
}
@ -165,13 +86,90 @@ namespace Aurora::Threading::Primitives
if (gHasThreadLocalTimeout)
{
auto uCount = tlsSpinCountLocal;
int loops = (1 << uCount);
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + loops;
auto perfCounter = __rdtsc() + uCount;
while (__rdtsc() < perfCounter)
#else
while (loops > 0)
while (uCount > 0)
#endif
{
if (callback())
{
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true;
}
else
{
SMPPause();
uCount--;
}
}
}
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
}
else
{
auto uCount = (spin) / 3;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + uCount;
while (__rdtsc() < perfCounter)
#else
while (uCount > 0)
#endif
{
if (callback())
{
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
return true;
}
else
{
SMPPause();
uCount--;
}
}
}
AuAtomicSub(&gSpinAdaptiveCurrentCount, 1u);
}
else
{
auto uCount = spin;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + uCount;
while (__rdtsc() < perfCounter)
#else
while (uCount > 0)
#endif
{
if (callback())
{
return true;
}
else
{
#if defined(SPIN_FOUR) && SPIN_FOUR == 1
SMPPause();
SMPPause();
SMPPause();
SMPPause();
uCount -= 4;
#else
SMPPause();
uCount -= 1;
#endif
}
}
if (gHasThreadLocalTimeout)
{
auto uCount = tlsSpinCountLocal;
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
auto perfCounter = __rdtsc() + uCount;
while (__rdtsc() < perfCounter)
#else
while (uCount > 0)
#endif
{
if (callback())
@ -181,7 +179,7 @@ namespace Aurora::Threading::Primitives
else
{
SMPPause();
loops --;
uCount--;
}
}
}