Fixes deque benchmarks (should have initial push)
authorPeizhao Ou <peizhaoo@uci.edu>
Sat, 17 Feb 2018 02:00:46 +0000 (18:00 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Sat, 17 Feb 2018 02:00:46 +0000 (18:00 -0800)
test/stress/misc/CMakeLists.txt
test/stress/misc/deque_driver.cpp

index 8d15dd9..d12a6e8 100644 (file)
@@ -2,8 +2,8 @@ set(PACKAGE_NAME stress-misc)
 
 set(CDSSTRESS_STACK_SOURCES
     ../main.cpp
-    spinlock_driver.cpp
     deque_driver.cpp
+    spinlock_driver.cpp
     barrier_driver.cpp
     seqlock_driver.cpp
     rwlock_driver.cpp
index e7d7896..f5eb10c 100644 (file)
@@ -12,13 +12,15 @@ using namespace std;
 namespace {
 
 typedef cds_others::ChaseLevDeque Deque;
+static size_t s_nDequePushPercentage = 70;
 static size_t s_nDequeStealerThreadCount = 3;
 static size_t s_nDequeMainPassCount = 100000000;
+static size_t s_nInitialDequePushPassCount = 10000;
 
 class ChaseLevDequeTest : public cds_test::stress_fixture {
 protected:
   static Deque *deque;
-  static atomic_int terminate_stealer;
+  static atomic_bool pusher_done;
   static ullong *sums;
   static ullong *succ_counts;
   static ullong push_sum;
@@ -26,12 +28,14 @@ protected:
 
   static void SetUpTestCase() {
     cds_test::config const &cfg = get_config("Misc");
+    GetConfig(DequePushPercentage);
     GetConfig(DequeStealerThreadCount);
     GetConfig(DequeMainPassCount);
+    GetConfig(InitialDequePushPassCount);
   }
 
   static void StealerThread(int index) {
-    while (!terminate_stealer.load(memory_order_acquire)) {
+    while (!pusher_done.load(memory_order_acquire)) {
       while (true) {
         int res = deque->steal();
         if (res != EMPTY && res != ABORT) {
@@ -45,9 +49,17 @@ protected:
   }
 
   static void MainThread(int index, int push_percentage) {
-    for (ullong i = 0; i < s_nDequeMainPassCount; i++) {
-      if ((::rand() % 100) < push_percentage) {
-        int item = ::rand() % 100;
+    for (size_t i = 0; i < s_nInitialDequePushPassCount; i++) {
+      deque->push(i + 1);
+      push_sum += i + 1;
+      push_count++;
+    }
+    for (size_t i = 0; i < s_nDequeMainPassCount; i++) {
+      if (rand(100) < push_percentage) {
+        int item = rand(s_nDequeMainPassCount);
+        if (item == EMPTY || item == ABORT) {
+          item = 1;
+        }
         deque->push(item);
         push_sum += item;
         push_count++;
@@ -59,6 +71,7 @@ protected:
         }
       }
     }
+    // Try take() until we don't can't take any more.
     while (true) {
       int res = deque->take();
       if (res != EMPTY) {
@@ -71,7 +84,7 @@ protected:
   }
 };
 
-atomic_int ChaseLevDequeTest::terminate_stealer;
+atomic_bool ChaseLevDequeTest::pusher_done;
 ullong *ChaseLevDequeTest::sums;
 ullong *ChaseLevDequeTest::succ_counts;
 ullong ChaseLevDequeTest::push_count;
@@ -84,7 +97,6 @@ TEST_F(ChaseLevDequeTest, DequePushPopTake) {
   sums = (ullong *)calloc(1, sizeof(ullong) * (s_nDequeStealerThreadCount + 1));
   succ_counts =
       (ullong *)calloc(1, sizeof(ullong) * (s_nDequeStealerThreadCount + 1));
-  srand(time(NULL));
 
   // Stealer threads
   std::unique_ptr<std::thread[]> threads(
@@ -93,11 +105,9 @@ TEST_F(ChaseLevDequeTest, DequePushPopTake) {
     threads[i] = std::thread(StealerThread, i);
   }
 
-  for (int i = 90; i > 0; i -= 10) {
-    MainThread(s_nDequeStealerThreadCount, i);
-  }
+  MainThread(s_nDequeStealerThreadCount, s_nDequePushPercentage);
+  pusher_done.store(true, memory_order_release);
 
-  terminate_stealer.store(1, memory_order_release);
   for (ullong i = 0; i < s_nDequeStealerThreadCount; i++) {
     threads[i].join();
   }
@@ -116,6 +126,10 @@ TEST_F(ChaseLevDequeTest, DequePushPopTake) {
     cout << "Push count=" << push_count << "\n";
     cout << "Received count:" << overall_count << "\n";
   }
+
+  free(sums);
+  free(succ_counts);
+  delete deque;
 }
 
 } // namespace