From 62cc3cfbf358e7951e99523eb13644c3c9ad36ba Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Sun, 9 Aug 2009 18:38:10 +0000 Subject: [PATCH] Workaround a problem with thread affinities. Should fix some slowness issues, mainly on AMD cpus. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1614 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/x86/ix86/ix86_cpudetect.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pcsx2/x86/ix86/ix86_cpudetect.cpp b/pcsx2/x86/ix86/ix86_cpudetect.cpp index 409f3cf64d..70bad69230 100644 --- a/pcsx2/x86/ix86/ix86_cpudetect.cpp +++ b/pcsx2/x86/ix86/ix86_cpudetect.cpp @@ -216,6 +216,19 @@ static void SetSingleAffinity() #endif } +static void UnSetSingleAffinity() +{ +#ifdef _WINDOWS_ + HANDLE s_threadId = GetCurrentThread(); + s_oldmask = SetThreadAffinityMask( s_threadId, 0xFFFFFFFF ); + + if( s_oldmask == ERROR_INVALID_PARAMETER ) + { + Console::Notice("CpuDetect: UnSetThreadAffinityMask failed..."); + } +#endif +} + ////////////////////////////////////////////////////////////////////////////////////////// // s64 CPUSpeedHz( u64 time ) @@ -489,5 +502,9 @@ void cpudetectInit() // This will assign values into cpuinfo.LogicalCores and PhysicalCores Threading::CountLogicalCores( LogicalCoresPerPhysicalCPU, PhysicalCoresPerPhysicalCPU ); + + // Undo previous SetSingleAffinity() here, so the host OS can handle load distribution + // (up to 25% faster on athlonx2, about 5% faster on core2) + UnSetSingleAffinity(); }