Skip to content

Commit

Permalink
Merge pull request ceph#14337 from smithfarm/wip-19492
Browse files Browse the repository at this point in the history
common: support s390 and unknown architectures in spin-wait loop

Reviewed-by: Kefu Chai <[email protected]>
Reviewed-by: Brad Hubbard <[email protected]>
  • Loading branch information
smithfarm authored Apr 6, 2017
2 parents 69fe2f2 + 2807d28 commit 3c89ca8
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/common/simple_spin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,42 @@
#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();
}
}

Expand Down

0 comments on commit 3c89ca8

Please sign in to comment.