From 8b6f0977a1d5c66e955e7e22b27ff9537cfdac39 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 18 Jul 2019 21:28:43 +0800 Subject: [PATCH] common/obj_bencher: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- src/common/obj_bencher.cc | 212 +++++++++++++++++++------------------- src/common/obj_bencher.h | 4 +- 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index e247aece2c1..3539abfed47 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -17,7 +17,8 @@ */ #include "include/compat.h" #include -#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 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; iinvalidate_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(); } - 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(); } - 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 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; } diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h index 8e41fb5bc1f..f2b6e173d77 100644 --- a/src/common/obj_bencher.h +++ b/src/common/obj_bencher.h @@ -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, -- 2.39.5