[Bf-blender-cvs] [dfed7c48ac6] blender-v2.79a-release: Fix T53068: AMD Threadripper not working well with Blender

Sergey Sharybin noreply at git.blender.org
Mon Jan 8 16:55:50 CET 2018


Commit: dfed7c48ac6bd829af1141e2b5aa093e082b6f1f
Author: Sergey Sharybin
Date:   Tue Nov 14 12:21:15 2017 +0100
Branches: blender-v2.79a-release
https://developer.blender.org/rBdfed7c48ac6bd829af1141e2b5aa093e082b6f1f

Fix T53068: AMD Threadripper not working well with Blender

The issue was caused by SpinLock implementation in old pthreads we ar eusing on
Windows. Using newer one (2.10-rc) demonstrates same exact behavior. But likely
using own atomics and memory barrier based implementation solves the issue.

A bit annoying that we need to change such a core part of Blender just to make
specific CPU happy, but it's better to have artists happy on all computers.

There is no expected downsides of this change, but it is so called "works for
me" category. Let's see how it all goes.

===================================================================

M	source/blender/blenlib/BLI_threads.h
M	source/blender/blenlib/intern/threads.c

===================================================================

diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h
index 0b1b4d8ee8c..9d672b1ce88 100644
--- a/source/blender/blenlib/BLI_threads.h
+++ b/source/blender/blenlib/BLI_threads.h
@@ -111,8 +111,10 @@ void BLI_mutex_unlock(ThreadMutex *mutex);
 
 /* Spin Lock */
 
-#ifdef __APPLE__
-typedef OSSpinLock SpinLock;
+#if defined(__APPLE__)
+typedef OSSpinLock ;
+#elif defined(_MSC_VER)
+typedef volatile int SpinLock;
 #else
 typedef pthread_spinlock_t SpinLock;
 #endif
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index abf611d1245..fbb64f3ece2 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -472,8 +472,10 @@ void BLI_mutex_free(ThreadMutex *mutex)
 
 void BLI_spin_init(SpinLock *spin)
 {
-#ifdef __APPLE__
+#if defined(__APPLE__)
 	*spin = OS_SPINLOCK_INIT;
+#elif defined(_MSC_VER)
+	*spin = 0;
 #else
 	pthread_spin_init(spin, 0);
 #endif
@@ -481,8 +483,14 @@ void BLI_spin_init(SpinLock *spin)
 
 void BLI_spin_lock(SpinLock *spin)
 {
-#ifdef __APPLE__
+#if defined(__APPLE__)
 	OSSpinLockLock(spin);
+#elif defined(_MSC_VER)
+	while (InterlockedExchangeAcquire(spin, 1)) {
+		while (*spin) {
+			/* pass */
+		}
+	}
 #else
 	pthread_spin_lock(spin);
 #endif
@@ -490,23 +498,24 @@ void BLI_spin_lock(SpinLock *spin)
 
 void BLI_spin_unlock(SpinLock *spin)
 {
-#ifdef __APPLE__
+#if defined(__APPLE__)
 	OSSpinLockUnlock(spin);
+#elif defined(_MSC_VER)
+	_ReadWriteBarrier();
+	*spin = 0;
 #else
 	pthread_spin_unlock(spin);
 #endif
 }
 
-#ifndef __APPLE__
 void BLI_spin_end(SpinLock *spin)
 {
-	pthread_spin_destroy(spin);
-}
+#if defined(__APPLE__)
+#elif defined(_MSC_VER)
 #else
-void BLI_spin_end(SpinLock *UNUSED(spin))
-{
-}
+	pthread_spin_destroy(spin);
 #endif
+}
 
 /* Read/Write Mutex Lock */



More information about the Bf-blender-cvs mailing list