From 3d8dd991e0afc961a0480a2b4461bed45fb6ab23 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Wed, 6 Sep 2023 16:08:41 +0100 Subject: [PATCH] [*] Adjust non-AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX futexes --- .../Aurora/Threading/Waitables/FutexCondWaitable.hpp | 12 ++++++++++++ .../Threading/Waitables/FutexSemaphoreWaitable.hpp | 12 ++++++++++++ Include/Aurora/Threading/Waitables/FutexWaitable.hpp | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Include/Aurora/Threading/Waitables/FutexCondWaitable.hpp b/Include/Aurora/Threading/Waitables/FutexCondWaitable.hpp index b6202d7b..5ea91e26 100644 --- a/Include/Aurora/Threading/Waitables/FutexCondWaitable.hpp +++ b/Include/Aurora/Threading/Waitables/FutexCondWaitable.hpp @@ -186,9 +186,21 @@ namespace Aurora::Threading::Waitables #if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX) AuUInt uCount(GetTotalSpinCountTimeout()); + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) + auto uPerfCounter = __rdtsc() + uCount; + while (__rdtsc() < uPerfCounter) + #else for (AU_ITERATE_N(i, uCount)) + #endif { + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) _mm_pause(); + _mm_pause(); + _mm_pause(); + _mm_pause(); + #else + // TBD + #endif if (TryLock3()) { diff --git a/Include/Aurora/Threading/Waitables/FutexSemaphoreWaitable.hpp b/Include/Aurora/Threading/Waitables/FutexSemaphoreWaitable.hpp index db956f63..35057c3c 100644 --- a/Include/Aurora/Threading/Waitables/FutexSemaphoreWaitable.hpp +++ b/Include/Aurora/Threading/Waitables/FutexSemaphoreWaitable.hpp @@ -34,9 +34,21 @@ namespace Aurora::Threading::Waitables #if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX) AuUInt uCount(GetTotalSpinCountTimeout()); + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) + auto uPerfCounter = __rdtsc() + uCount; + while (__rdtsc() < uPerfCounter) + #else for (AU_ITERATE_N(i, uCount)) + #endif { + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) _mm_pause(); + _mm_pause(); + _mm_pause(); + _mm_pause(); + #else + // TBD + #endif if (TryLockNoSpin()) { diff --git a/Include/Aurora/Threading/Waitables/FutexWaitable.hpp b/Include/Aurora/Threading/Waitables/FutexWaitable.hpp index f2c7069f..f60db790 100644 --- a/Include/Aurora/Threading/Waitables/FutexWaitable.hpp +++ b/Include/Aurora/Threading/Waitables/FutexWaitable.hpp @@ -33,9 +33,21 @@ namespace Aurora::Threading::Waitables #if (defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64)) && !defined(AURORA_RUNTIME_FORCE_ADAPTIVE_FUTEX) AuUInt uCount(GetTotalSpinCountTimeout()); + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) + auto uPerfCounter = __rdtsc() + uCount; + while (__rdtsc() < uPerfCounter) + #else for (AU_ITERATE_N(i, uCount)) + #endif { + #if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86) _mm_pause(); + _mm_pause(); + _mm_pause(); + _mm_pause(); + #else + // TBD + #endif if (TryLockNoSpin()) {