From: Jesse Williamson Date: Thu, 27 Apr 2017 07:52:11 +0000 (-0700) Subject: test: migrate atomic_t to std::atomic<> X-Git-Tag: v12.1.1~65^2~9^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d07cfd40685e209f32bf4821f22e6c234591e011;p=ceph.git test: migrate atomic_t to std::atomic<> Signed-off-by: Jesse Williamson --- diff --git a/src/test/librados_test_stub/TestIoCtxImpl.cc b/src/test/librados_test_stub/TestIoCtxImpl.cc index 5200bea84bbe..d5de8b54aa6c 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestIoCtxImpl.cc @@ -39,15 +39,15 @@ TestIoCtxImpl::TestIoCtxImpl(const TestIoCtxImpl& rhs) } 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; @@ -57,11 +57,11 @@ void TestObjectOperationImpl::put() { } 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; } @@ -95,7 +95,7 @@ void TestIoCtxImpl::aio_flush_async(AioCompletionImpl *c) { 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, @@ -107,7 +107,7 @@ int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl & 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(0), @@ -121,7 +121,7 @@ int TestIoCtxImpl::aio_operate_read(const std::string& oid, 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; @@ -129,7 +129,7 @@ int TestIoCtxImpl::aio_operate_read(const std::string& oid, 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()) { @@ -142,7 +142,7 @@ int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c, } 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()) { @@ -198,7 +198,7 @@ int TestIoCtxImpl::operate(const std::string& oid, TestObjectOperationImpl &ops) 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(0), m_snapc), comp); @@ -214,7 +214,7 @@ int TestIoCtxImpl::operate_read(const std::string& oid, TestObjectOperationImpl 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); @@ -361,13 +361,13 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid, } } } - 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); } diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index aa5318e1171d..04629d128ff0 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -4,12 +4,14 @@ #ifndef CEPH_TEST_IO_CTX_IMPL_H #define CEPH_TEST_IO_CTX_IMPL_H +#include +#include + +#include + #include "include/rados/librados.hpp" -#include "include/atomic.h" #include "include/Context.h" #include "common/snap_types.h" -#include -#include namespace librados { @@ -30,7 +32,7 @@ public: ObjectOperations ops; private: - atomic_t m_refcount; + std::atomic m_refcount = { 0 }; }; class TestIoCtxImpl { @@ -179,8 +181,8 @@ private: std::string m_pool_name; snap_t m_snap_seq; SnapContext m_snapc; - atomic_t m_refcount; - atomic_t m_pending_ops; + std::atomic m_refcount = { 0 }; + std::atomic m_pending_ops = { 0 }; void handle_aio_notify_complete(AioCompletionImpl *aio_comp, int r); }; diff --git a/src/test/librados_test_stub/TestRadosClient.cc b/src/test/librados_test_stub/TestRadosClient.cc index 156bd15ec9a5..546973558d2b 100644 --- a/src/test/librados_test_stub/TestRadosClient.cc +++ b/src/test/librados_test_stub/TestRadosClient.cc @@ -11,6 +11,8 @@ #include #include +#include + static int get_concurrency() { int concurrency = 0; char *env = getenv("LIBRADOS_CONCURRENCY"); @@ -114,11 +116,11 @@ TestRadosClient::~TestRadosClient() { } void TestRadosClient::get() { - m_refcount.inc(); + m_refcount++; } void TestRadosClient::put() { - if (m_refcount.dec() == 0) { + if (--m_refcount == 0) { shutdown(); delete this; } @@ -180,7 +182,7 @@ void TestRadosClient::add_aio_operation(const std::string& oid, 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; @@ -188,7 +190,7 @@ struct WaitForFlush { return 0; } - atomic_t count; + std::atomic count = { 0 }; Finisher *aio_finisher; AioCompletionImpl *c; }; @@ -204,7 +206,7 @@ void TestRadosClient::flush_aio_operations(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; diff --git a/src/test/librados_test_stub/TestRadosClient.h b/src/test/librados_test_stub/TestRadosClient.h index 1f14172ca3d6..7e84916bc754 100644 --- a/src/test/librados_test_stub/TestRadosClient.h +++ b/src/test/librados_test_stub/TestRadosClient.h @@ -4,17 +4,19 @@ #ifndef CEPH_TEST_RADOS_CLIENT_H #define CEPH_TEST_RADOS_CLIENT_H +#include +#include +#include +#include +#include + +#include +#include + #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 -#include -#include -#include -#include -#include class Finisher; @@ -113,7 +115,7 @@ protected: private: CephContext *m_cct; - atomic_t m_refcount; + std::atomic m_refcount = { 0 }; TestWatchNotify *m_watch_notify; diff --git a/src/test/msgr/perf_msgr_client.cc b/src/test/msgr/perf_msgr_client.cc index 5bb20715c1a5..d8d25720033f 100644 --- a/src/test/msgr/perf_msgr_client.cc +++ b/src/test/msgr/perf_msgr_client.cc @@ -22,7 +22,6 @@ using namespace std; -#include "include/atomic.h" #include "common/ceph_argparse.h" #include "common/debug.h" #include "common/Cycles.h" @@ -30,6 +29,8 @@ using namespace std; #include "msg/Messenger.h" #include "messages/MOSDOp.h" +#include + class MessengerClient { class ClientThread; class ClientDispatcher : public Dispatcher { @@ -67,7 +68,7 @@ class MessengerClient { Messenger *msgr; int concurrent; ConnectionRef conn; - atomic_t client_inc; + std::atomic client_inc = { 0 }; object_t oid; object_locator_t oloc; pg_t pgid; @@ -82,7 +83,7 @@ class MessengerClient { 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); @@ -98,7 +99,7 @@ class MessengerClient { 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); diff --git a/src/test/msgr/perf_msgr_server.cc b/src/test/msgr/perf_msgr_server.cc index c687d77a6493..79e36721aa84 100644 --- a/src/test/msgr/perf_msgr_server.cc +++ b/src/test/msgr/perf_msgr_server.cc @@ -22,7 +22,6 @@ using namespace std; -#include "include/atomic.h" #include "common/ceph_argparse.h" #include "common/debug.h" #include "global/global_init.h" diff --git a/src/test/msgr/test_async_driver.cc b/src/test/msgr/test_async_driver.cc index a93cffa0f4e2..e68e57b6ba83 100644 --- a/src/test/msgr/test_async_driver.cc +++ b/src/test/msgr/test_async_driver.cc @@ -24,13 +24,14 @@ #include #include #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 + // We use epoll, kqueue, evport, select in descending order by performance. #if defined(__linux__) #define HAVE_EPOLL 1 @@ -293,15 +294,15 @@ class Worker : public Thread { }; class CountEvent: public EventCallback { - atomic_t *count; + std::atomic *count; Mutex *lock; Cond *cond; public: - CountEvent(atomic_t *atomic, Mutex *l, Cond *c): count(atomic), lock(l), cond(c) {} + CountEvent(std::atomic *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(); } @@ -309,18 +310,18 @@ class CountEvent: public EventCallback { TEST(EventCenterTest, DispatchTest) { Worker worker1(g_ceph_context, 1), worker2(g_ceph_context, 2); - atomic_t count(0); + std::atomic 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(); diff --git a/src/test/msgr/test_msgr.cc b/src/test/msgr/test_msgr.cc index 518ec7732ee2..831f71aa85e5 100644 --- a/src/test/msgr/test_msgr.cc +++ b/src/test/msgr/test_msgr.cc @@ -1370,9 +1370,9 @@ class MarkdownDispatcher : public Dispatcher { set conns; bool last_mark; public: - atomic_t count; + std::atomic 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()) { @@ -1395,7 +1395,7 @@ class MarkdownDispatcher : public Dispatcher { 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(); @@ -1471,8 +1471,8 @@ TEST_P(MessengerTest, MarkdownTest) { 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++; @@ -1480,7 +1480,7 @@ TEST_P(MessengerTest, MarkdownTest) { 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); diff --git a/src/test/objectstore/TestObjectStoreState.cc b/src/test/objectstore/TestObjectStoreState.cc index 9a4f6e1be949..7eab8b3842ff 100644 --- a/src/test/objectstore/TestObjectStoreState.cc +++ b/src/test/objectstore/TestObjectStoreState.cc @@ -77,7 +77,7 @@ void TestObjectStoreState::init(int colls, int objs) 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; } diff --git a/src/test/objectstore/TestObjectStoreState.h b/src/test/objectstore/TestObjectStoreState.h index c59d4769113e..7d1ac8c08213 100644 --- a/src/test/objectstore/TestObjectStoreState.h +++ b/src/test/objectstore/TestObjectStoreState.h @@ -65,19 +65,19 @@ public: int m_num_objects; int m_max_in_flight; - atomic_t m_in_flight; + std::atomic 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); } @@ -101,7 +101,6 @@ public: 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() { @@ -119,11 +118,11 @@ public: } 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); diff --git a/src/test/objectstore/workload_generator.cc b/src/test/objectstore/workload_generator.cc index a529e576b790..343cc2cd7362 100644 --- a/src/test/objectstore/workload_generator.cc +++ b/src/test/objectstore/workload_generator.cc @@ -60,7 +60,7 @@ WorkloadGenerator::WorkloadGenerator(vector args) { int err = 0; - m_nr_runs.set(0); + m_nr_runs = 0; init_args(args); dout(0) << "data = " << g_conf->osd_data << dendl; @@ -352,7 +352,7 @@ void WorkloadGenerator::do_destroy_collection(ObjectStore::Transaction *t, coll_entry_t *entry, C_StatState *stat) { - m_nr_runs.set(0); + m_nr_runs = 0; entry->m_osr.flush(); vector ls; m_store->collection_list(entry->m_coll, ghobject_t(), ghobject_t::get_max(), @@ -431,7 +431,7 @@ void WorkloadGenerator::run() 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(); @@ -502,7 +502,7 @@ queue_tx: } 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(); diff --git a/src/test/objectstore/workload_generator.h b/src/test/objectstore/workload_generator.h index 978cd043b1ec..a1c21b9d0718 100644 --- a/src/test/objectstore/workload_generator.h +++ b/src/test/objectstore/workload_generator.h @@ -17,11 +17,13 @@ #include #include #include -#include #include #include "TestObjectStoreState.h" +#include +#include + typedef boost::mt11213b rngen_t; class WorkloadGenerator : public TestObjectStoreState { @@ -57,7 +59,7 @@ 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 m_nr_runs = { 0 }; int m_num_colls; @@ -110,7 +112,7 @@ class WorkloadGenerator : public TestObjectStoreState { 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); @@ -135,7 +137,7 @@ public: void finish(int r) override { TestObjectStoreState::C_OnFinished::finish(r); - wrkldgen_state->m_nr_runs.inc(); + wrkldgen_state->m_nr_runs++; } }; diff --git a/src/test/osdc/FakeWriteback.cc b/src/test/osdc/FakeWriteback.cc index 72e80e433f6d..24a780288b3a 100644 --- a/src/test/osdc/FakeWriteback.cc +++ b/src/test/osdc/FakeWriteback.cc @@ -84,7 +84,7 @@ ceph_tid_t FakeWriteback::write(const object_t& oid, 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, diff --git a/src/test/osdc/FakeWriteback.h b/src/test/osdc/FakeWriteback.h index 6112eb720826..0d3705c87fd5 100644 --- a/src/test/osdc/FakeWriteback.h +++ b/src/test/osdc/FakeWriteback.h @@ -3,12 +3,13 @@ #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 + class Finisher; class Mutex; @@ -40,7 +41,7 @@ private: CephContext *m_cct; Mutex *m_lock; uint64_t m_delay_ns; - atomic_t m_tid; + std::atomic m_tid = { 0 }; Finisher *m_finisher; }; diff --git a/src/test/osdc/MemWriteback.cc b/src/test/osdc/MemWriteback.cc index e9e1f9fe345b..f8f9844b30c7 100644 --- a/src/test/osdc/MemWriteback.cc +++ b/src/test/osdc/MemWriteback.cc @@ -116,7 +116,7 @@ ceph_tid_t MemWriteback::write(const object_t& oid, 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, diff --git a/src/test/osdc/MemWriteback.h b/src/test/osdc/MemWriteback.h index a073cbf1760d..84ea78f5a2c4 100644 --- a/src/test/osdc/MemWriteback.h +++ b/src/test/osdc/MemWriteback.h @@ -3,12 +3,13 @@ #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 + class Finisher; class Mutex; @@ -45,7 +46,7 @@ private: CephContext *m_cct; Mutex *m_lock; uint64_t m_delay_ns; - atomic_t m_tid; + std::atomic m_tid = { 0 }; Finisher *m_finisher; }; diff --git a/src/test/osdc/object_cacher_stress.cc b/src/test/osdc/object_cacher_stress.cc index c23c6c26ed33..fc9c56f95554 100644 --- a/src/test/osdc/object_cacher_stress.cc +++ b/src/test/osdc/object_cacher_stress.cc @@ -14,7 +14,6 @@ #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" @@ -23,6 +22,8 @@ #include "FakeWriteback.h" #include "MemWriteback.h" +#include + // XXX: Only tests default namespace struct op_data { op_data(std::string oid, uint64_t offset, uint64_t len, bool read) @@ -35,19 +36,19 @@ struct op_data { ObjectExtent extent; bool is_read; ceph::bufferlist result; - atomic_t done; + std::atomic done = { 0 }; }; class C_Count : public Context { op_data *m_op; - atomic_t *m_outstanding; + std::atomic *m_outstanding = nullptr; public: - C_Count(op_data *op, atomic_t *outstanding) + C_Count(op_data *op, std::atomic *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--; } }; @@ -67,7 +68,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs, true); obc.start(); - atomic_t outstanding_reads; + std::atomic outstanding_reads = { 0 }; vector > ops; ObjectCacher::ObjectSet object_set(NULL, 0, 0); SnapContext snapc; @@ -100,7 +101,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs, 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); @@ -128,7 +129,7 @@ int stress_test(uint64_t num_ops, uint64_t num_objs, 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); } diff --git a/src/test/perf_local.cc b/src/test/perf_local.cc index a74ef8342adb..98cccd87bbd5 100644 --- a/src/test/perf_local.cc +++ b/src/test/perf_local.cc @@ -41,7 +41,6 @@ #include #endif -#include "include/atomic.h" #include "include/buffer.h" #include "include/encoding.h" #include "include/ceph_hash.h" @@ -57,6 +56,8 @@ #include "test/perf_helper.h" +#include + using namespace ceph; /** @@ -95,15 +96,15 @@ void discard(void* value) { // 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 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(); @@ -111,43 +112,43 @@ double atomic_int_cmp() 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 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 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 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; @@ -483,12 +484,12 @@ class CenterWorker : public Thread { }; class CountEvent: public EventCallback { - atomic_t *count; + std::atomic *count; public: - explicit CountEvent(atomic_t *atomic): count(atomic) {} + explicit CountEvent(std::atomic *atomic): count(atomic) {} void do_request(int id) override { - count->dec(); + (*count)--; } }; @@ -497,20 +498,20 @@ double eventcenter_dispatch() int count = 100000; CenterWorker worker(g_ceph_context); - atomic_t flag(1); + std::atomic 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(); diff --git a/src/test/system/systest_runnable.cc b/src/test/system/systest_runnable.cc index 95453391207a..7a97f2ffbba4 100644 --- a/src/test/system/systest_runnable.cc +++ b/src/test/system/systest_runnable.cc @@ -14,7 +14,6 @@ #include "include/compat.h" #include "common/errno.h" -#include "include/atomic.h" #include "systest_runnable.h" #include "systest_settings.h" @@ -31,6 +30,7 @@ #include #include #include +#include using std::ostringstream; using std::string; @@ -44,7 +44,7 @@ static pid_t do_gettid(void) #endif } -ceph::atomic_t m_highest_id(0); +std::atomic m_highest_id = { 0 }; SysTestRunnable:: SysTestRunnable(int argc, const char **argv) @@ -53,7 +53,7 @@ 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); diff --git a/src/test/test_stress_watch.cc b/src/test/test_stress_watch.cc index ff964df17ed3..8604328b59c2 100644 --- a/src/test/test_stress_watch.cc +++ b/src/test/test_stress_watch.cc @@ -1,6 +1,5 @@ #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" @@ -13,6 +12,7 @@ #include #include #include +#include #include "test/librados/TestCase.h" @@ -23,7 +23,7 @@ using std::ostringstream; using std::string; static sem_t *sem; -static atomic_t stop_flag; +static std::atomic stop_flag = { false }; class WatchNotifyTestCtx : public WatchCtx { @@ -45,7 +45,7 @@ struct WatcherUnwatcher : public Thread { 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); @@ -113,7 +113,7 @@ TEST_P(WatchStress, Stress1) { 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));