]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: support s390 and unknown architectures in spin-wait loop 14337/head
authorNathan Cutler <ncutler@suse.com>
Wed, 5 Apr 2017 08:33:02 +0000 (10:33 +0200)
committerNathan Cutler <ncutler@suse.com>
Thu, 6 Apr 2017 08:41:37 +0000 (10:41 +0200)
This fixes the s390 build which was broken by 34481768cbce0991bfba1d511dad81893a9004a9

It also reinstates the previous architecture-independent for-loop
implementation as a catch-all for "unknown" (not-explicitly-supported)
architectures.

Fixes: http://tracker.ceph.com/issues/19492
Signed-off-by: Nathan Cutler <ncutler@suse.com>
src/common/simple_spin.cc

index ef41a2b515bbbd601cb91b212c9e3cc50e19322d..3e1b3dc048f4a0728f23f14a0f4e5de7aa60d87b 100644 (file)
 #include <stdint.h>
 #include <pthread.h>
 
-void simple_spin_lock(simple_spinlock_t *lock)
+namespace {
+
+#if !defined(__i386__) && !defined(__x86_64__) && !defined(__arm__) && !defined(__aarch64__) && !defined(__powerpc__) && !defined(__ppc__) && !defined(__s390__) && !defined(__s390x__)
+static uint32_t bar = 13;
+static uint32_t *foo = &bar;
+#endif
+
+void cpu_relax()
 {
-  while(1) {
-    __sync_synchronize();
-    uint32_t oldval = *lock;
-    if (oldval == 0) {
-      if (__sync_bool_compare_and_swap(lock, 0, 1))
-       return;
-    }
-    // delay
 #if defined(__i386__) || defined(__x86_64__)
     asm volatile("pause");
 #elif defined(__arm__) || defined(__aarch64__)
     asm volatile("yield");
 #elif defined(__powerpc__) || defined(__ppc__)
     asm volatile("or 27,27,27");
+#elif defined(__s390__) || defined(__s390x__)
+    asm volatile("": : :"memory");
 #else
-#error "Unknown architecture"
+    for (int i = 0; i < 100000; i++) {
+      *foo = (*foo * 33) + 17;
+    }
 #endif
+}
+
+} // namespace
+
+void simple_spin_lock(simple_spinlock_t *lock)
+{
+  while (1) {
+    __sync_synchronize();
+    uint32_t oldval = *lock;
+    if (oldval == 0) {
+      if (__sync_bool_compare_and_swap(lock, 0, 1))
+       return;
+    }
+    cpu_relax();
   }
 }