From 34481768cbce0991bfba1d511dad81893a9004a9 Mon Sep 17 00:00:00 2001 From: Brad Hubbard Date: Thu, 30 Mar 2017 16:50:32 +1000 Subject: [PATCH] common: Make spinlock delay more conventional The accepted method of implementing a spinlock delay is the "pause" instruction. Signed-off-by: Brad Hubbard --- src/common/simple_spin.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/simple_spin.cc b/src/common/simple_spin.cc index fc4ac633deaf1..2d875365e0560 100644 --- a/src/common/simple_spin.cc +++ b/src/common/simple_spin.cc @@ -18,9 +18,6 @@ #include #include -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 } } -- 2.39.5