[*] 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,22 +75,22 @@ namespace Aurora::Threading::Primitives
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
uCount -= 4;
#else
SMPPause();
loops -= 1;
uCount -= 1;
#endif
}
}
if (gHasThreadLocalTimeout)
{
int loops = (1 << tlsSpinCountLocal);
auto uCount = tlsSpinCountLocal;
#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())
@ -101,7 +101,7 @@ namespace Aurora::Threading::Primitives
else
{
SMPPause();
loops--;
uCount--;
}
}
}
@ -110,12 +110,12 @@ namespace Aurora::Threading::Primitives
}
else
{
int loops = (spin) / 3;
auto uCount = (spin) / 3;
#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())
@ -126,7 +126,7 @@ namespace Aurora::Threading::Primitives
else
{
SMPPause();
loops --;
uCount--;
}
}
}
@ -135,12 +135,12 @@ namespace Aurora::Threading::Primitives
}
else
{
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())
@ -154,10 +154,10 @@ namespace Aurora::Threading::Primitives
SMPPause();
SMPPause();
SMPPause();
loops -= 4;
uCount -= 4;
#else
SMPPause();
loops -= 1;
uCount -= 1;
#endif
}
}
@ -165,13 +165,11 @@ 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())
@ -181,7 +179,7 @@ namespace Aurora::Threading::Primitives
else
{
SMPPause();
loops --;
uCount--;
}
}
}