*/
#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";
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) {
}
++i;
++cycleSinceChange;
- cond.WaitInterval(bencher->lock, ONE_SECOND);
+ cond.wait_for(locker, ONE_SECOND);
}
if (formatter)
formatter->close_section(); //datas
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;
}
}
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();
}
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);
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
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) {
} 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();
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];
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
goto ERR;
}
name[slot] = newName;
- lock.lock();
+ locker.lock();
++data.started;
++data.in_flight;
if (data.op_size) {
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];
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);
return 0;
ERR:
- lock.lock();
+ locker.lock();
data.done = 1;
- lock.unlock();
+ locker.unlock();
pthread_join(print_thread, NULL);
return r;
}
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);
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
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) {
if (found) {
break;
}
- lc.cond.Wait(lock);
+ lc.cond.wait(locker);
}
// calculate latency here, so memcmp doesn't inflate it
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();
++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
if (r < 0) {
goto ERR;
}
- lock.lock();
+ locker.lock();
++data.started;
++data.in_flight;
- lock.unlock();
+ locker.unlock();
name[slot] = newName;
}
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];
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);
return (errors > 0 ? -EIO : 0);
ERR:
- lock.lock();
+ locker.lock();
data.done = 1;
- lock.unlock();
+ locker.unlock();
pthread_join(print_thread, NULL);
return r;
}
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);
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
slot = 0;
while ((seconds_to_run && mono_clock::now() < finish_time)) {
- lock.lock();
+ locker.lock();
int old_slot = slot;
bool found = false;
while (1) {
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;
}
++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);
if (r < 0) {
goto ERR;
}
- lock.lock();
+ locker.lock();
++data.started;
++data.in_flight;
- lock.unlock();
+ locker.unlock();
name[slot] = newName;
}
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];
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);
return (errors > 0 ? -EIO : 0);
ERR:
- lock.lock();
+ locker.lock();
data.done = 1;
- lock.unlock();
+ locker.unlock();
pthread_join(print_thread, NULL);
return r;
}
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) {
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) {
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
if (r < 0) {
goto ERR;
}
- lock.lock();
+ locker.lock();
++data.started;
++data.in_flight;
- lock.unlock();
+ locker.unlock();
name[slot] = newName;
}
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();
return 0;
ERR:
- lock.lock();
+ locker.lock();
data.done = 1;
- lock.unlock();
+ locker.unlock();
return r;
}
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;
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) {
if (found) {
break;
}
- lc.cond.Wait(lock);
+ lc.cond.wait(locker);
}
- lock.unlock();
+ locker.unlock();
// get more objects if necessary
if (objects.empty()) {
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
if (r < 0) {
goto ERR;
}
- lock.lock();
+ locker.lock();
++data.started;
++data.in_flight;
- lock.unlock();
+ locker.unlock();
name[slot] = newName;
}
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();
return 0;
ERR:
- lock.lock();
+ locker.lock();
data.done = 1;
- lock.unlock();
+ locker.unlock();
return -EIO;
}