]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Make spinlock delay more conventional 14248/head
authorBrad Hubbard <bhubbard@redhat.com>
Thu, 30 Mar 2017 06:50:32 +0000 (16:50 +1000)
committerBrad Hubbard <bhubbard@redhat.com>
Fri, 31 Mar 2017 04:33:32 +0000 (14:33 +1000)
The accepted method of implementing a spinlock delay is the "pause"
instruction.

Signed-off-by: Brad Hubbard <bhubbard@redhat.com>
src/common/simple_spin.cc

index fc4ac633deaf113316744f7e3f6208a45795b5c7..2d875365e0560fbe1567c826b325655b063a188b 100644 (file)
@@ -18,9 +18,6 @@
 #include <stdint.h>
 #include <pthread.h>
 
-static uint32_t bar = 13;
-static uint32_t *foo = &bar;
 void simple_spin_lock(simple_spinlock_t *lock)
 {
   while(1) {
@@ -31,9 +28,15 @@ void simple_spin_lock(simple_spinlock_t *lock)
        return;
     }
     // delay
-    for (int i = 0; i < 100000; i++) {
-      *foo = (*foo * 33) + 17;
-    }
+#if defined(__i386__) || defined(__x86_64__)
+    asm volatile("pause");
+#elif defined(__arm__) || defined(__aarch64__)
+    asm volatile("yield");
+#elif defined(__ppc64__)
+    asm volatile("or 27,27,27");
+#else
+#error "Unknown architecture"
+#endif
   }
 }