}
TestIoCtxImpl::~TestIoCtxImpl() {
- assert(m_pending_ops.read() == 0);
+ assert(m_pending_ops == 0);
}
void TestObjectOperationImpl::get() {
- m_refcount.inc();
+ m_refcount++;
}
void TestObjectOperationImpl::put() {
- if (m_refcount.dec() == 0) {
+ if (--m_refcount == 0) {
ANNOTATE_HAPPENS_AFTER(&m_refcount);
ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&m_refcount);
delete this;
}
void TestIoCtxImpl::get() {
- m_refcount.inc();
+ m_refcount++;
}
void TestIoCtxImpl::put() {
- if (m_refcount.dec() == 0) {
+ if (--m_refcount == 0) {
m_client->put();
delete this;
}
void TestIoCtxImpl::aio_notify(const std::string& oid, AioCompletionImpl *c,
bufferlist& bl, uint64_t timeout_ms,
bufferlist *pbl) {
- m_pending_ops.inc();
+ m_pending_ops++;
c->get();
C_AioNotify *ctx = new C_AioNotify(this, c);
m_client->get_watch_notify()->aio_notify(m_client, oid, bl, timeout_ms, pbl,
int flags) {
// TODO flags for now
ops.get();
- m_pending_ops.inc();
+ m_pending_ops++;
m_client->add_aio_operation(oid, true, boost::bind(
&TestIoCtxImpl::execute_aio_operations, this, oid, &ops,
reinterpret_cast<bufferlist*>(0),
bufferlist *pbl) {
// TODO ignoring flags for now
ops.get();
- m_pending_ops.inc();
+ m_pending_ops++;
m_client->add_aio_operation(oid, true, boost::bind(
&TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl, m_snapc), c);
return 0;
int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c,
uint64_t *handle, librados::WatchCtx2 *watch_ctx) {
- m_pending_ops.inc();
+ m_pending_ops++;
c->get();
C_AioNotify *ctx = new C_AioNotify(this, c);
if (m_client->is_blacklisted()) {
}
int TestIoCtxImpl::aio_unwatch(uint64_t handle, AioCompletionImpl *c) {
- m_pending_ops.inc();
+ m_pending_ops++;
c->get();
C_AioNotify *ctx = new C_AioNotify(this, c);
if (m_client->is_blacklisted()) {
AioCompletionImpl *comp = new AioCompletionImpl();
ops.get();
- m_pending_ops.inc();
+ m_pending_ops++;
m_client->add_aio_operation(oid, false, boost::bind(
&TestIoCtxImpl::execute_aio_operations, this, oid, &ops,
reinterpret_cast<bufferlist*>(0), m_snapc), comp);
AioCompletionImpl *comp = new AioCompletionImpl();
ops.get();
- m_pending_ops.inc();
+ m_pending_ops++;
m_client->add_aio_operation(oid, false, boost::bind(
&TestIoCtxImpl::execute_aio_operations, this, oid, &ops, pbl,
m_snapc), comp);
}
}
}
- m_pending_ops.dec();
+ m_pending_ops--;
ops->put();
return ret;
}
void TestIoCtxImpl::handle_aio_notify_complete(AioCompletionImpl *c, int r) {
- m_pending_ops.dec();
+ m_pending_ops--;
m_client->finish_aio_completion(c, r);
}
#ifndef CEPH_TEST_IO_CTX_IMPL_H
#define CEPH_TEST_IO_CTX_IMPL_H
+#include <list>
+#include <atomic>
+
+#include <boost/function.hpp>
+
#include "include/rados/librados.hpp"
-#include "include/atomic.h"
#include "include/Context.h"
#include "common/snap_types.h"
-#include <boost/function.hpp>
-#include <list>
namespace librados {
ObjectOperations ops;
private:
- atomic_t m_refcount;
+ std::atomic<uint64_t> m_refcount = { 0 };
};
class TestIoCtxImpl {
std::string m_pool_name;
snap_t m_snap_seq;
SnapContext m_snapc;
- atomic_t m_refcount;
- atomic_t m_pending_ops;
+ std::atomic<uint64_t> m_refcount = { 0 };
+ std::atomic<uint64_t> m_pending_ops = { 0 };
void handle_aio_notify_complete(AioCompletionImpl *aio_comp, int r);
};
#include <boost/thread.hpp>
#include <errno.h>
+#include <atomic>
+
static int get_concurrency() {
int concurrency = 0;
char *env = getenv("LIBRADOS_CONCURRENCY");
}
void TestRadosClient::get() {
- m_refcount.inc();
+ m_refcount++;
}
void TestRadosClient::put() {
- if (m_refcount.dec() == 0) {
+ if (--m_refcount == 0) {
shutdown();
delete this;
}
struct WaitForFlush {
int flushed() {
- if (count.dec() == 0) {
+ if (--count == 0) {
aio_finisher->queue(new FunctionContext(boost::bind(
&finish_aio_completion, c, 0)));
delete this;
return 0;
}
- atomic_t count;
+ std::atomic<int64_t> count = { 0 };
Finisher *aio_finisher;
AioCompletionImpl *c;
};
c->get();
WaitForFlush *wait_for_flush = new WaitForFlush();
- wait_for_flush->count.set(m_finishers.size());
+ wait_for_flush->count = m_finishers.size();
wait_for_flush->aio_finisher = m_aio_finisher;
wait_for_flush->c = c;
#ifndef CEPH_TEST_RADOS_CLIENT_H
#define CEPH_TEST_RADOS_CLIENT_H
+#include <map>
+#include <list>
+#include <string>
+#include <vector>
+#include <atomic>
+
+#include <boost/function.hpp>
+#include <boost/functional/hash.hpp>
+
#include "include/rados/librados.hpp"
#include "common/config.h"
-#include "include/atomic.h"
#include "include/buffer_fwd.h"
#include "test/librados_test_stub/TestWatchNotify.h"
-#include <boost/function.hpp>
-#include <boost/functional/hash.hpp>
-#include <list>
-#include <map>
-#include <string>
-#include <vector>
class Finisher;
private:
CephContext *m_cct;
- atomic_t m_refcount;
+ std::atomic<uint64_t> m_refcount = { 0 };
TestWatchNotify *m_watch_notify;
using namespace std;
-#include "include/atomic.h"
#include "common/ceph_argparse.h"
#include "common/debug.h"
#include "common/Cycles.h"
#include "msg/Messenger.h"
#include "messages/MOSDOp.h"
+#include <atomic>
+
class MessengerClient {
class ClientThread;
class ClientDispatcher : public Dispatcher {
Messenger *msgr;
int concurrent;
ConnectionRef conn;
- atomic_t client_inc;
+ std::atomic<unsigned> client_inc = { 0 };
object_t oid;
object_locator_t oloc;
pg_t pgid;
uint64_t inflight;
ClientThread(Messenger *m, int c, ConnectionRef con, int len, int ops, int think_time_us):
- msgr(m), concurrent(c), conn(con), client_inc(0), oid("object-name"), oloc(1, 1), msg_len(len), ops(ops),
+ msgr(m), concurrent(c), conn(con), oid("object-name"), oloc(1, 1), msg_len(len), ops(ops),
dispatcher(think_time_us, this), lock("MessengerBenchmark::ClientThread::lock") {
m->add_dispatcher_head(&dispatcher);
bufferptr ptr(msg_len);
hobject_t hobj(oid, oloc.key, CEPH_NOSNAP, pgid.ps(), pgid.pool(),
oloc.nspace);
spg_t spgid(pgid);
- MOSDOp *m = new MOSDOp(client_inc.read(), 0, hobj, spgid, 0, 0, 0);
+ MOSDOp *m = new MOSDOp(client_inc, 0, hobj, spgid, 0, 0, 0);
m->write(0, msg_len, data);
inflight++;
conn->send_message(m);
using namespace std;
-#include "include/atomic.h"
#include "common/ceph_argparse.h"
#include "common/debug.h"
#include "global/global_init.h"
#include <stdint.h>
#include <arpa/inet.h>
#include "include/Context.h"
-#include "include/atomic.h"
#include "common/Mutex.h"
#include "common/Cond.h"
#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include "msg/async/Event.h"
+#include <atomic>
+
// We use epoll, kqueue, evport, select in descending order by performance.
#if defined(__linux__)
#define HAVE_EPOLL 1
};
class CountEvent: public EventCallback {
- atomic_t *count;
+ std::atomic<unsigned> *count;
Mutex *lock;
Cond *cond;
public:
- CountEvent(atomic_t *atomic, Mutex *l, Cond *c): count(atomic), lock(l), cond(c) {}
+ CountEvent(std::atomic<unsigned> *atomic, Mutex *l, Cond *c): count(atomic), lock(l), cond(c) {}
void do_request(int id) override {
lock->Lock();
- count->dec();
+ (*count)--;
cond->Signal();
lock->Unlock();
}
TEST(EventCenterTest, DispatchTest) {
Worker worker1(g_ceph_context, 1), worker2(g_ceph_context, 2);
- atomic_t count(0);
+ std::atomic<unsigned> count = { 0 };
Mutex lock("DispatchTest::lock");
Cond cond;
worker1.create("worker_1");
worker2.create("worker_2");
for (int i = 0; i < 10000; ++i) {
- count.inc();
+ count++;
worker1.center.dispatch_event_external(EventCallbackRef(new CountEvent(&count, &lock, &cond)));
- count.inc();
+ count++;
worker2.center.dispatch_event_external(EventCallbackRef(new CountEvent(&count, &lock, &cond)));
Mutex::Locker l(lock);
- while (count.read())
+ while (count)
cond.Wait(lock);
}
worker1.stop();
set<ConnectionRef> conns;
bool last_mark;
public:
- atomic_t count;
+ std::atomic<int64_t> count = { 0 };
explicit MarkdownDispatcher(bool s): Dispatcher(g_ceph_context), lock("MarkdownDispatcher::lock"),
- last_mark(false), count(0) {}
+ last_mark(false) {}
bool ms_can_fast_dispatch_any() const override { return false; }
bool ms_can_fast_dispatch(const Message *m) const override {
switch (m->get_type()) {
bool ms_dispatch(Message *m) override {
lderr(g_ceph_context) << __func__ << " conn: " << m->get_connection() << dendl;
Mutex::Locker l(lock);
- count.inc();
+ count++;
conns.insert(m->get_connection());
if (conns.size() < 2 && !last_mark) {
m->put();
ASSERT_EQ(conn1->send_message(m), 0);
m = new MPing();
ASSERT_EQ(conn2->send_message(m), 0);
- CHECK_AND_WAIT_TRUE(srv_dispatcher.count.read() > last + 1);
- if (srv_dispatcher.count.read() == last) {
+ CHECK_AND_WAIT_TRUE(srv_dispatcher.count > last + 1);
+ if (srv_dispatcher.count == last) {
lderr(g_ceph_context) << __func__ << " last is " << last << dendl;
equal = true;
equal_count++;
equal = false;
equal_count = 0;
}
- last = srv_dispatcher.count.read();
+ last = srv_dispatcher.count;
if (equal_count)
usleep(1000*500);
ASSERT_FALSE(equal && equal_count > 3);
m_collections_ids.push_back(coll_id);
m_next_coll_nr++;
}
- dout(5) << "init has " << m_in_flight.read() << "in-flight transactions" << dendl;
+ dout(5) << "init has " << m_in_flight.load() << "in-flight transactions" << dendl;
wait_for_done();
dout(5) << "init finished" << dendl;
}
int m_num_objects;
int m_max_in_flight;
- atomic_t m_in_flight;
+ std::atomic<int> m_in_flight = { 0 };
Mutex m_finished_lock;
Cond m_finished_cond;
void wait_for_ready() {
Mutex::Locker locker(m_finished_lock);
- while ((m_max_in_flight > 0) && ((int)m_in_flight.read() >= m_max_in_flight))
+ while ((m_max_in_flight > 0) && (m_in_flight >= m_max_in_flight))
m_finished_cond.Wait(m_finished_lock);
}
void wait_for_done() {
Mutex::Locker locker(m_finished_lock);
- while (m_in_flight.read())
+ while (m_in_flight)
m_finished_cond.Wait(m_finished_lock);
}
explicit TestObjectStoreState(ObjectStore *store) :
m_next_coll_nr(0), m_num_objs_per_coll(10), m_num_objects(0),
m_max_in_flight(0), m_finished_lock("Finished Lock"), m_next_pool(1) {
- m_in_flight.set(0);
m_store.reset(store);
}
~TestObjectStoreState() {
}
int inc_in_flight() {
- return ((int) m_in_flight.inc());
+ return ++m_in_flight;
}
int dec_in_flight() {
- return ((int) m_in_flight.dec());
+ return --m_in_flight;
}
coll_entry_t *coll_create(int id);
{
int err = 0;
- m_nr_runs.set(0);
+ m_nr_runs = 0;
init_args(args);
dout(0) << "data = " << g_conf->osd_data << dendl;
coll_entry_t *entry,
C_StatState *stat)
{
- m_nr_runs.set(0);
+ m_nr_runs = 0;
entry->m_osr.flush();
vector<ghobject_t> ls;
m_store->collection_list(entry->m_coll, ghobject_t(), ghobject_t::get_max(),
dout(5) << __func__
<< " m_finished_lock is-locked: " << m_finished_lock.is_locked()
- << " in-flight: " << m_in_flight.read()
+ << " in-flight: " << m_in_flight.load()
<< dendl;
wait_for_ready();
} while (true);
dout(2) << __func__ << " waiting for "
- << m_in_flight.read() << " in-flight transactions" << dendl;
+ << m_in_flight.load() << " in-flight transactions" << dendl;
wait_for_done();
#include <boost/scoped_ptr.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
-#include <map>
#include <sys/time.h>
#include "TestObjectStoreState.h"
+#include <map>
+#include <atomic>
+
typedef boost::mt11213b rngen_t;
class WorkloadGenerator : public TestObjectStoreState {
int m_max_in_flight;
int m_num_ops;
int m_destroy_coll_every_nr_runs;
- atomic_t m_nr_runs;
+ std::atomic<int> m_nr_runs = { 0 };
int m_num_colls;
bool should_destroy_collection() {
return ((m_destroy_coll_every_nr_runs > 0) &&
- ((int)m_nr_runs.read() >= m_destroy_coll_every_nr_runs));
+ (m_nr_runs >= m_destroy_coll_every_nr_runs));
}
void do_destroy_collection(ObjectStore::Transaction *t, coll_entry_t *entry,
C_StatState *stat);
void finish(int r) override
{
TestObjectStoreState::C_OnFinished::finish(r);
- wrkldgen_state->m_nr_runs.inc();
+ wrkldgen_state->m_nr_runs++;
}
};
C_Delay *wrapper = new C_Delay(m_cct, oncommit, m_lock, off, NULL,
m_delay_ns);
m_finisher->queue(wrapper, 0);
- return m_tid.inc();
+ return ++m_tid;
}
bool FakeWriteback::may_copy_on_write(const object_t&, uint64_t, uint64_t,
#ifndef CEPH_TEST_OSDC_FAKEWRITEBACK_H
#define CEPH_TEST_OSDC_FAKEWRITEBACK_H
-#include "include/atomic.h"
#include "include/Context.h"
#include "include/types.h"
#include "osd/osd_types.h"
#include "osdc/WritebackHandler.h"
+#include <atomic>
+
class Finisher;
class Mutex;
CephContext *m_cct;
Mutex *m_lock;
uint64_t m_delay_ns;
- atomic_t m_tid;
+ std::atomic<unsigned> m_tid = { 0 };
Finisher *m_finisher;
};
C_DelayWrite *wrapper = new C_DelayWrite(this, m_cct, oncommit, m_lock, oid,
off, len, bl, m_delay_ns);
m_finisher->queue(wrapper, 0);
- return m_tid.inc();
+ return ++m_tid;
}
void MemWriteback::write_object_data(const object_t& oid, uint64_t off, uint64_t len,
#ifndef CEPH_TEST_OSDC_MEMWRITEBACK_H
#define CEPH_TEST_OSDC_MEMWRITEBACK_H
-#include "include/atomic.h"
#include "include/Context.h"
#include "include/types.h"
#include "osd/osd_types.h"
#include "osdc/WritebackHandler.h"
+#include <atomic>
+
class Finisher;
class Mutex;
CephContext *m_cct;
Mutex *m_lock;
uint64_t m_delay_ns;
- atomic_t m_tid;
+ std::atomic<unsigned> m_tid = { 0 };
Finisher *m_finisher;
};
#include "common/Mutex.h"
#include "common/snap_types.h"
#include "global/global_init.h"
-#include "include/atomic.h"
#include "include/buffer.h"
#include "include/Context.h"
#include "include/stringify.h"
#include "FakeWriteback.h"
#include "MemWriteback.h"
+#include <atomic>
+
// XXX: Only tests default namespace
struct op_data {
op_data(std::string oid, uint64_t offset, uint64_t len, bool read)
ObjectExtent extent;
bool is_read;
ceph::bufferlist result;
- atomic_t done;
+ std::atomic<unsigned> done = { 0 };
};
class C_Count : public Context {
op_data *m_op;
- atomic_t *m_outstanding;
+ std::atomic<unsigned> *m_outstanding = nullptr;
public:
- C_Count(op_data *op, atomic_t *outstanding)
+ C_Count(op_data *op, std::atomic<unsigned> *outstanding)
: m_op(op), m_outstanding(outstanding) {}
void finish(int r) override {
- m_op->done.inc();
- assert(m_outstanding->read() > 0);
- m_outstanding->dec();
+ m_op->done++;
+ assert(m_outstanding > 0);
+ *m_outstanding--;
}
};
true);
obc.start();
- atomic_t outstanding_reads;
+ std::atomic<unsigned> outstanding_reads = { 0 };
vector<ceph::shared_ptr<op_data> > ops;
ObjectCacher::ObjectSet object_set(NULL, 0, 0);
SnapContext snapc;
if (op->is_read) {
ObjectCacher::OSDRead *rd = obc.prepare_read(CEPH_NOSNAP, &op->result, 0);
rd->extents.push_back(op->extent);
- outstanding_reads.inc();
+ outstanding_reads++;
Context *completion = new C_Count(op.get(), &outstanding_reads);
lock.Lock();
int r = obc.readx(rd, &object_set, completion);
std::cout << "waiting for read " << i << ops[i]->extent << std::endl;
uint64_t done = 0;
while (done == 0) {
- done = ops[i]->done.read();
+ done = ops[i]->done;
if (!done) {
usleep(500);
}
#include <xmmintrin.h>
#endif
-#include "include/atomic.h"
#include "include/buffer.h"
#include "include/encoding.h"
#include "include/ceph_hash.h"
#include "test/perf_helper.h"
+#include <atomic>
+
using namespace ceph;
/**
// Test functions start here
//----------------------------------------------------------------------
-// Measure the cost of atomic_t::compare_and_swap
+// Measure the cost of atomic compare-and-swap
double atomic_int_cmp()
{
int count = 1000000;
- atomic_t value(11);
- int test = 11;
+ std::atomic<unsigned> value = { 11 };
+ unsigned int test = 11;
uint64_t start = Cycles::rdtsc();
for (int i = 0; i < count; i++) {
- value.compare_and_swap(test, test+2);
+ value.compare_exchange_strong(test, test+2);
test += 2;
}
uint64_t stop = Cycles::rdtsc();
return Cycles::to_seconds(stop - start)/count;
}
-// Measure the cost of atomic_t::inc
+// Measure the cost of incrementing an atomic
double atomic_int_inc()
{
int count = 1000000;
- atomic_t value(11);
+ std::atomic<int64_t> value = { 11 };
uint64_t start = Cycles::rdtsc();
for (int i = 0; i < count; i++) {
- value.inc();
+ value++;
}
uint64_t stop = Cycles::rdtsc();
// printf("Final value: %d\n", value.load());
return Cycles::to_seconds(stop - start)/count;
}
-// Measure the cost of reading an atomic_t
+// Measure the cost of reading an atomic
double atomic_int_read()
{
int count = 1000000;
- atomic_t value(11);
+ std::atomic<int64_t> value = { 11 };
int total = 0;
uint64_t start = Cycles::rdtsc();
for (int i = 0; i < count; i++) {
- total += value.read();
+ total += value;
}
uint64_t stop = Cycles::rdtsc();
// printf("Total: %d\n", total);
return Cycles::to_seconds(stop - start)/count;
}
-// Measure the cost of storing a new value in a atomic_t
+// Measure the cost of storing a new value in an atomic
double atomic_int_set()
{
int count = 1000000;
- atomic_t value(11);
+ std::atomic<int64_t> value = { 11 };
uint64_t start = Cycles::rdtsc();
for (int i = 0; i < count; i++) {
- value.set(88);
+ value = 88;
}
uint64_t stop = Cycles::rdtsc();
return Cycles::to_seconds(stop - start)/count;
};
class CountEvent: public EventCallback {
- atomic_t *count;
+ std::atomic<int64_t> *count;
public:
- explicit CountEvent(atomic_t *atomic): count(atomic) {}
+ explicit CountEvent(std::atomic<int64_t> *atomic): count(atomic) {}
void do_request(int id) override {
- count->dec();
+ (*count)--;
}
};
int count = 100000;
CenterWorker worker(g_ceph_context);
- atomic_t flag(1);
+ std::atomic<int64_t> flag = { 1 };
worker.create("evt_center_disp");
EventCallbackRef count_event(new CountEvent(&flag));
worker.center.dispatch_event_external(count_event);
// Start a new thread and wait for it to ready.
- while (flag.read())
+ while (flag)
usleep(100);
uint64_t start = Cycles::rdtsc();
for (int i = 0; i < count; i++) {
- flag.set(1);
+ flag = 1;
worker.center.dispatch_event_external(count_event);
- while (flag.read())
+ while (flag)
;
}
uint64_t stop = Cycles::rdtsc();
#include "include/compat.h"
#include "common/errno.h"
-#include "include/atomic.h"
#include "systest_runnable.h"
#include "systest_settings.h"
#include <sys/wait.h>
#include <unistd.h>
#include <vector>
+#include <atomic>
using std::ostringstream;
using std::string;
#endif
}
-ceph::atomic_t m_highest_id(0);
+std::atomic<unsigned> m_highest_id = { 0 };
SysTestRunnable::
SysTestRunnable(int argc, const char **argv)
m_argv_orig(NULL)
{
m_started = false;
- m_id = m_highest_id.inc();
+ m_id = ++m_highest_id;
memset(&m_pthread, 0, sizeof(m_pthread));
update_id_str(false);
set_argv(argc, argv);
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
-#include "include/atomic.h"
#include "include/utime.h"
#include "common/Thread.h"
#include "common/Clock.h"
#include <sstream>
#include <iostream>
#include <string>
+#include <atomic>
#include "test/librados/TestCase.h"
using std::string;
static sem_t *sem;
-static atomic_t stop_flag;
+static std::atomic<bool> stop_flag = { false };
class WatchNotifyTestCtx : public WatchCtx
{
void *entry() override {
Rados cluster;
connect_cluster_pp(cluster);
- while (!stop_flag.read()) {
+ while (!stop_flag) {
IoCtx ioctx;
cluster.ioctx_create(pool.c_str(), ioctx);
ioctx.unwatch("foo", handle);
ioctx.close();
}
- stop_flag.set(1);
+ stop_flag = true;
thr->join();
nioctx.close();
ASSERT_EQ(0, destroy_one_pool_pp(pool_name, ncluster));