]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/obj_bencher: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Thu, 18 Jul 2019 13:28:43 +0000 (21:28 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/obj_bencher.cc
src/common/obj_bencher.h

index e247aece2c144b244c0023506b96520f14ec2a46..3539abfed47819182a6d010b4484d2dd24319558 100644 (file)
@@ -17,7 +17,8 @@
  */
 #include "include/compat.h"
 #include <pthread.h>
-#include "common/Cond.h"
+#include "common/ceph_mutex.h"
+#include "common/Clock.h"
 #include "obj_bencher.h"
 
 const std::string BENCH_LASTRUN_METADATA = "benchmark_last_metadata";
@@ -91,14 +92,14 @@ void *ObjBencher::status_printer(void *_bencher) {
   bench_data& data = bencher->data;
   Formatter *formatter = bencher->formatter;
   ostream *outstream = bencher->outstream;
-  Cond cond;
+  ceph::condition_variable cond;
   int i = 0;
   int previous_writes = 0;
   int cycleSinceChange = 0;
   double bandwidth;
   int iops = 0;
   mono_clock::duration ONE_SECOND = std::chrono::seconds(1);
-  bencher->lock.lock();
+  std::unique_lock locker{bencher->lock};
   if (formatter)
     formatter->open_array_section("datas");
   while(!data.done) {
@@ -221,7 +222,7 @@ void *ObjBencher::status_printer(void *_bencher) {
     }
     ++i;
     ++cycleSinceChange;
-    cond.WaitInterval(bencher->lock, ONE_SECOND);
+    cond.wait_for(locker, ONE_SECOND);
   }
   if (formatter)
     formatter->close_section(); //datas
@@ -229,7 +230,6 @@ void *ObjBencher::status_printer(void *_bencher) {
     std::chrono::duration<double> runtime = mono_clock::now() - data.start_time;
     data.idata.min_iops = data.idata.max_iops = data.finished / runtime.count();
   }
-  bencher->lock.unlock();
   return NULL;
 }
 
@@ -339,15 +339,15 @@ int ObjBencher::aio_bench(
 }
 
 struct lock_cond {
-  explicit lock_cond(Mutex *_lock) : lock(_lock) {}
-  Mutex *lock;
-  Cond cond;
+  explicit lock_cond(ceph::mutex *_lock) : lock(_lock) {}
+  ceph::mutex *lock;
+  ceph::condition_variable cond;
 };
 
 void _aio_cb(void *cb, void *arg) {
   struct lock_cond *lc = (struct lock_cond *)arg;
   lc->lock->lock();
-  lc->cond.Signal();
+  lc->cond.notify_all();
   lc->lock->unlock();
 }
 
@@ -436,10 +436,10 @@ int ObjBencher::write_bench(int secondsToRun,
 
   pthread_create(&print_thread, NULL, ObjBencher::status_printer, (void *)this);
   ceph_pthread_setname(print_thread, "write_stat");
-  lock.lock();
+  std::unique_lock locker{lock};
   data.finished = 0;
   data.start_time = mono_clock::now();
-  lock.unlock();
+  locker.unlock();
   for (int i = 0; i<concurrentios; ++i) {
     start_times[i] = mono_clock::now();
     r = create_completion(i, _aio_cb, (void *)&lc);
@@ -450,10 +450,10 @@ int ObjBencher::write_bench(int secondsToRun,
     if (r < 0) {
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
   }
 
   //keep on adding new writes as old ones complete until we've passed minimum time
@@ -464,7 +464,7 @@ int ObjBencher::write_bench(int secondsToRun,
 
   stopTime = data.start_time + std::chrono::seconds(secondsToRun);
   slot = 0;
-  lock.lock();
+  locker.lock();
   while (secondsToRun && mono_clock::now() < stopTime) {
     bool found = false;
     while (1) {
@@ -481,9 +481,9 @@ int ObjBencher::write_bench(int secondsToRun,
       } while (slot != old_slot);
       if (found)
         break;
-      lc.cond.Wait(lock);
+      lc.cond.wait(locker);
     }
-    lock.unlock();
+    locker.unlock();
     //create new contents and name on the heap, and fill them
     newName = generate_object_name_fast(data.started / writes_per_object);
     newContents = contents[slot].get();
@@ -492,10 +492,10 @@ int ObjBencher::write_bench(int secondsToRun,
     newContents->invalidate_crc();
 
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0) {
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     data.cur_latency = mono_clock::now() - start_times[slot];
@@ -509,7 +509,7 @@ int ObjBencher::write_bench(int secondsToRun,
     data.avg_latency = total_latency / data.finished;
     data.latency_diff_sum += delta * (data.cur_latency.count() - data.avg_latency);
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     release_completion(slot);
 
     //write new stuff to backend
@@ -523,7 +523,7 @@ int ObjBencher::write_bench(int secondsToRun,
       goto ERR;
     }
     name[slot] = newName;
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
     if (data.op_size) {
@@ -533,15 +533,15 @@ int ObjBencher::write_bench(int secondsToRun,
         break;
     }
   }
-  lock.unlock();
+  locker.unlock();
 
   while (data.finished < data.started) {
     slot = data.finished % concurrentios;
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0) {
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     data.cur_latency = mono_clock::now() - start_times[slot];
@@ -555,14 +555,14 @@ int ObjBencher::write_bench(int secondsToRun,
     data.avg_latency = total_latency / data.finished;
     data.latency_diff_sum += delta * (data.cur_latency.count() - data.avg_latency);
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     release_completion(slot);
   }
 
   timePassed = mono_clock::now() - data.start_time;
-  lock.lock();
+  locker.lock();
   data.done = true;
-  lock.unlock();
+  locker.unlock();
 
   pthread_join(print_thread, NULL);
 
@@ -640,9 +640,9 @@ int ObjBencher::write_bench(int secondsToRun,
   return 0;
 
  ERR:
-  lock.lock();
+  locker.lock();
   data.done = 1;
-  lock.unlock();
+  locker.unlock();
   pthread_join(print_thread, NULL);
   return r;
 }
@@ -680,10 +680,10 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
     contents[i] = std::make_unique<bufferlist>();
   }
 
-  lock.lock();
+  std::unique_lock locker{lock};
   data.finished = 0;
   data.start_time = mono_clock::now();
-  lock.unlock();
+  locker.unlock();
 
   pthread_t print_thread;
   pthread_create(&print_thread, NULL, status_printer, (void *)this);
@@ -701,10 +701,10 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
       cerr << "r = " << r << std::endl;
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
   }
 
   //keep on adding new reads as old ones complete
@@ -714,7 +714,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
   slot = 0;
   while ((seconds_to_run && mono_clock::now() < finish_time) &&
         num_objects > data.started) {
-    lock.lock();
+    locker.lock();
     int old_slot = slot;
     bool found = false;
     while (1) {
@@ -731,7 +731,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
       if (found) {
         break;
       }
-      lc.cond.Wait(lock);
+      lc.cond.wait(locker);
     }
 
     // calculate latency here, so memcmp doesn't inflate it
@@ -754,13 +754,13 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
 
     newName = generate_object_name_fast(data.started / reads_per_object, pid);
     index[slot] = data.started;
-    lock.unlock();
+    locker.unlock();
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r < 0) {
       cerr << "read got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     total_latency += data.cur_latency.count();
@@ -771,7 +771,7 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
     ++data.finished;
     data.avg_latency = total_latency / data.finished;
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     release_completion(slot);
 
     //start new read and check data if requested
@@ -782,10 +782,10 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
     if (r < 0) {
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
     name[slot] = newName;
   }
 
@@ -793,11 +793,11 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
   while (data.finished < data.started) {
     slot = data.finished % concurrentios;
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r < 0) {
       cerr << "read got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     data.cur_latency = mono_clock::now() - start_times[slot];
@@ -812,21 +812,21 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
     release_completion(slot);
     if (!no_verify) {
       snprintf(data.object_contents, data.op_size, "I'm the %16dth op!", index[slot]);
-      lock.unlock();
+      locker.unlock();
       if ((contents[slot]->length() != data.op_size) || 
          (memcmp(data.object_contents, contents[slot]->c_str(), data.op_size) != 0)) {
         cerr << name[slot] << " is not correct!" << std::endl;
         ++errors;
       }
     } else {
-        lock.unlock();
+        locker.unlock();
     }
   }
 
   timePassed = mono_clock::now() - data.start_time;
-  lock.lock();
+  locker.lock();
   data.done = true;
-  lock.unlock();
+  locker.unlock();
 
   pthread_join(print_thread, NULL);
 
@@ -874,9 +874,9 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre
   return (errors > 0 ? -EIO : 0);
 
  ERR:
-  lock.lock();
+  locker.lock();
   data.done = 1;
-  lock.unlock();
+  locker.unlock();
   pthread_join(print_thread, NULL);
   return r;
 }
@@ -917,10 +917,10 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
     contents[i] = std::make_unique<bufferlist>();
   }
 
-  lock.lock();
+  unique_lock locker{lock};
   data.finished = 0;
   data.start_time = mono_clock::now();
-  lock.unlock();
+  locker.unlock();
 
   pthread_t print_thread;
   pthread_create(&print_thread, NULL, status_printer, (void *)this);
@@ -938,10 +938,10 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
       cerr << "r = " << r << std::endl;
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
   }
 
   //keep on adding new reads as old ones complete
@@ -951,7 +951,7 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
 
   slot = 0;
   while ((seconds_to_run && mono_clock::now() < finish_time)) {
-    lock.lock();
+    locker.lock();
     int old_slot = slot;
     bool found = false;
     while (1) {
@@ -968,22 +968,22 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
       if (found) {
         break;
       }
-      lc.cond.Wait(lock);
+      lc.cond.wait(locker);
     }
 
     // calculate latency here, so memcmp doesn't inflate it
     data.cur_latency = mono_clock::now() - start_times[slot];
 
-    lock.unlock();
+    locker.unlock();
 
     int current_index = index[slot];
     cur_contents = contents[slot].get();
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r < 0) {
       cerr << "read got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
 
@@ -995,7 +995,7 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
     ++data.finished;
     data.avg_latency = total_latency / data.finished;
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     
     if (!no_verify) {
       snprintf(data.object_contents, data.op_size, "I'm the %16dth op!", current_index);
@@ -1022,10 +1022,10 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
     if (r < 0) {
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
     name[slot] = newName;
   }
 
@@ -1034,11 +1034,11 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
   while (data.finished < data.started) {
     slot = data.finished % concurrentios;
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r < 0) {
       cerr << "read got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     data.cur_latency = mono_clock::now() - start_times[slot];
@@ -1053,21 +1053,21 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
     release_completion(slot);
     if (!no_verify) {
       snprintf(data.object_contents, data.op_size, "I'm the %16dth op!", index[slot]);
-      lock.unlock();
+      locker.unlock();
       if ((contents[slot]->length() != data.op_size) || 
           (memcmp(data.object_contents, contents[slot]->c_str(), data.op_size) != 0)) {
         cerr << name[slot] << " is not correct!" << std::endl;
         ++errors;
       }
     } else {
-        lock.unlock();
+        locker.unlock();
     }
   }
 
   timePassed = mono_clock::now() - data.start_time;
-  lock.lock();
+  locker.lock();
   data.done = true;
-  lock.unlock();
+  locker.unlock();
 
   pthread_join(print_thread, NULL);
 
@@ -1114,9 +1114,9 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr
   return (errors > 0 ? -EIO : 0);
 
  ERR:
-  lock.lock();
+  locker.lock();
   data.done = 1;
-  lock.unlock();
+  locker.unlock();
   pthread_join(print_thread, NULL);
   return r;
 }
@@ -1197,12 +1197,12 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
   int r = 0;
   int slot = 0;
 
-  lock.lock();
+  unique_lock locker{lock};
   data.done = false;
   data.in_flight = 0;
   data.started = 0;
   data.finished = 0;
-  lock.unlock();
+  locker.unlock();
 
   // don't start more completions than files
   if (num_objects == 0) {
@@ -1228,15 +1228,15 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
       cerr << "r = " << r << std::endl;
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
   }
 
   //keep on adding new removes as old ones complete
   while (data.started < num_objects) {
-    lock.lock();
+    locker.lock();
     int old_slot = slot;
     bool found = false;
     while (1) {
@@ -1253,21 +1253,21 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
       if (found) {
         break;
       }
-      lc.cond.Wait(lock);
+      lc.cond.wait(locker);
     }
-    lock.unlock();
+    locker.unlock();
     newName = generate_object_name_fast(data.started, prevPid);
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0 && r != -ENOENT) { // file does not exist
       cerr << "remove got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     ++data.finished;
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     release_completion(slot);
 
     //start new remove and check data if requested
@@ -1276,10 +1276,10 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
     if (r < 0) {
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
     name[slot] = newName;
   }
 
@@ -1287,22 +1287,22 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
   while (data.finished < data.started) {
     slot = data.finished % concurrentios;
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0 && r != -ENOENT) { // file does not exist
       cerr << "remove got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     ++data.finished;
     --data.in_flight;
     release_completion(slot);
-    lock.unlock();
+    locker.unlock();
   }
 
-  lock.lock();
+  locker.lock();
   data.done = true;
-  lock.unlock();
+  locker.unlock();
 
   completions_done();
 
@@ -1311,9 +1311,9 @@ int ObjBencher::clean_up(int num_objects, int prevPid, int concurrentios) {
   return 0;
 
  ERR:
-  lock.lock();
+  locker.lock();
   data.done = 1;
-  lock.unlock();
+  locker.unlock();
   return r;
 }
 
@@ -1363,12 +1363,12 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
   std::list<Object> objects;
   bool objects_remain = true;
 
-  lock.lock();
+  std::unique_lock locker{lock};
   data.done = false;
   data.in_flight = 0;
   data.started = 0;
   data.finished = 0;
-  lock.unlock();
+  locker.unlock();
 
   out(cout) << "Warning: using slow linear search" << std::endl;
 
@@ -1401,15 +1401,15 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
       cerr << "r = " << r << std::endl;
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
   }
 
   //keep on adding new removes as old ones complete
   while (objects_remain) {
-    lock.lock();
+    locker.lock();
     int old_slot = slot;
     bool found = false;
     while (1) {
@@ -1426,9 +1426,9 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
       if (found) {
         break;
       }
-      lc.cond.Wait(lock);
+      lc.cond.wait(locker);
     }
-    lock.unlock();
+    locker.unlock();
 
     // get more objects if necessary
     if (objects.empty()) {
@@ -1444,16 +1444,16 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
     objects.pop_front();
 
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0 && r != -ENOENT) { // file does not exist
       cerr << "remove got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     ++data.finished;
     --data.in_flight;
-    lock.unlock();
+    locker.unlock();
     release_completion(slot);
 
     //start new remove and check data if requested
@@ -1463,10 +1463,10 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
     if (r < 0) {
       goto ERR;
     }
-    lock.lock();
+    locker.lock();
     ++data.started;
     ++data.in_flight;
-    lock.unlock();
+    locker.unlock();
     name[slot] = newName;
   }
 
@@ -1474,22 +1474,22 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
   while (data.finished < data.started) {
     slot = data.finished % concurrentios;
     completion_wait(slot);
-    lock.lock();
+    locker.lock();
     r = completion_ret(slot);
     if (r != 0 && r != -ENOENT) { // file does not exist
       cerr << "remove got " << r << std::endl;
-      lock.unlock();
+      locker.unlock();
       goto ERR;
     }
     ++data.finished;
     --data.in_flight;
     release_completion(slot);
-    lock.unlock();
+    locker.unlock();
   }
 
-  lock.lock();
+  locker.lock();
   data.done = true;
-  lock.unlock();
+  locker.unlock();
 
   completions_done();
 
@@ -1498,8 +1498,8 @@ int ObjBencher::clean_up_slow(const std::string& prefix, int concurrentios) {
   return 0;
 
  ERR:
-  lock.lock();
+  locker.lock();
   data.done = 1;
-  lock.unlock();
+  locker.unlock();
   return -EIO;
 }
index 8e41fb5bc1fbb2faa2c9282835f067f58e176990..f2b6e173d777494b0a8377d38972ec0f4d2d76b8 100644 (file)
@@ -68,7 +68,7 @@ class ObjBencher {
 public:
   CephContext *cct;
 protected:
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("ObjBencher::lock");
 
   static void *status_printer(void *bencher);
 
@@ -107,7 +107,7 @@ protected:
   ostream& out(ostream& os);
   ostream& out(ostream& os, utime_t& t);
 public:
-  explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), lock("ObjBencher::lock"), data() {}
+  explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), data() {}
   virtual ~ObjBencher() {}
   int aio_bench(
     int operation, int secondsToRun,