Fix all benchmarks to use yield
authorBrian Demsky <bdemsky@uci.edu>
Thu, 14 Mar 2013 07:10:19 +0000 (00:10 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Thu, 14 Mar 2013 07:10:19 +0000 (00:10 -0700)
All benchmarks now call thrd_yield when appropriate so that they terminate with the -y option.

barrier/barrier.h
bench.sh
dekker-fences/dekker-fences.cc
linuxrwlocks/linuxrwlocks.c
mcs-lock/mcs-lock.h
mpmc-queue/mpmc-queue.h

index 6970816..dd5d39c 100644 (file)
@@ -18,7 +18,7 @@ class spinning_barrier {
                } else {
                        /* Run in circles and scream like a little girl.  */
                        while (step_.load () == step)
-                               ;
+                               thrd_yield();
                        return false;
                }
        }
index c32924b..94d041f 100755 (executable)
--- a/bench.sh
+++ b/bench.sh
@@ -26,7 +26,7 @@ TESTS+=" mpmc-queue/mpmc-1r2w-noinit"
 TESTS+=" mpmc-queue/mpmc-queue-noinit"
 TESTS+=" linuxrwlocks/linuxrwlocks"
 
-MODEL_ARGS="-f 10 -m 2 -e 1"
+MODEL_ARGS="-y -m 2"
 COUNT=0
 
 function run_test {
index 81f6098..eb38d5c 100644 (file)
@@ -27,10 +27,12 @@ void p0(void *arg)
                        flag0.store(false,std::memory_order_relaxed);
                        while (turn.load(std::memory_order_relaxed) != 0)
                        {
+                               thrd_yield();
                        }
                        flag0.store(true,std::memory_order_relaxed);
                        std::atomic_thread_fence(std::memory_order_seq_cst);
-               }
+               } else
+                       thrd_yield();
        }
        std::atomic_thread_fence(std::memory_order_acquire);
 
@@ -54,10 +56,12 @@ void p1(void *arg)
                        flag1.store(false,std::memory_order_relaxed);
                        while (turn.load(std::memory_order_relaxed) != 1)
                        {
+                               thrd_yield();
                        }
                        flag1.store(true,std::memory_order_relaxed);
                        std::atomic_thread_fence(std::memory_order_seq_cst);
-               }
+               } else
+                       thrd_yield();
        }
        std::atomic_thread_fence(std::memory_order_acquire);
 
index 7e317aa..be3550e 100644 (file)
@@ -29,9 +29,9 @@ static inline void read_lock(rwlock_t *rw)
        int priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire);
        while (priorvalue <= 0) {
                atomic_fetch_add_explicit(&rw->lock, 1, memory_order_relaxed);
-               do {
-                       priorvalue = atomic_load_explicit(&rw->lock, memory_order_relaxed);
-               } while (priorvalue <= 0);
+               while (atomic_load_explicit(&rw->lock, memory_order_relaxed) <= 0) {
+                       thrd_yield();
+               }
                priorvalue = atomic_fetch_sub_explicit(&rw->lock, 1, memory_order_acquire);
        }
 }
@@ -41,9 +41,9 @@ static inline void write_lock(rwlock_t *rw)
        int priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire);
        while (priorvalue != RW_LOCK_BIAS) {
                atomic_fetch_add_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_relaxed);
-               do {
-                       priorvalue = atomic_load_explicit(&rw->lock, memory_order_relaxed);
-               } while (priorvalue != RW_LOCK_BIAS);
+               while (atomic_load_explicit(&rw->lock, memory_order_relaxed) != RW_LOCK_BIAS) {
+                       thrd_yield();
+               }
                priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire);
        }
 }
index 2d39f2f..4b808f7 100644 (file)
@@ -57,7 +57,7 @@ public:
                        // wait on predecessor setting my flag -
                        rl::linear_backoff bo;
                        while ( me->gate.load(std::mo_acquire) ) {
-                               bo.yield();
+                               thrd_yield();
                        }
                }
        }
@@ -80,7 +80,7 @@ public:
                                next = me->next.load(std::mo_acquire);
                                if ( next != NULL )
                                        break;
-                               bo.yield();
+                               thrd_yield();
                        }
                }
 
index f73ab99..dc2b561 100644 (file)
@@ -43,7 +43,7 @@ public:
                // (*1)
                rl::backoff bo;
                while ( (m_written.load(mo_acquire) & 0xFFFF) != wr ) {
-                       bo.yield();
+                       thrd_yield();
                }
 
                t_element * p = & ( m_array[ rd % t_size ] );
@@ -74,7 +74,7 @@ public:
                // (*1)
                rl::backoff bo;
                while ( (m_read.load(mo_acquire) & 0xFFFF) != rd ) {
-                       bo.yield();
+                       thrd_yield();
                }
 
                t_element * p = & ( m_array[ wr % t_size ] );