From 2807d28c1adcfbdfa22d9d48766998ffa3e2a495 Mon Sep 17 00:00:00 2001 From: Nathan Cutler Date: Wed, 5 Apr 2017 10:33:02 +0200 Subject: [PATCH] common: support s390 and unknown architectures in spin-wait loop 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 --- src/common/simple_spin.cc | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/common/simple_spin.cc b/src/common/simple_spin.cc index ef41a2b515bb..3e1b3dc048f4 100644 --- a/src/common/simple_spin.cc +++ b/src/common/simple_spin.cc @@ -18,25 +18,42 @@ #include #include -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(); } } -- 2.47.3