From 5d4c47baed3b8ae7aac5e5bbdcd4bf11229b38d1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 3 Jul 2017 21:48:08 +0200 Subject: [PATCH 1/1] try to speed up the refcounting madness by using std::move --- include/simgrid/s4u/Actor.hpp | 14 +++----------- include/simgrid/s4u/forward.hpp | 2 ++ include/simgrid/simix.h | 2 -- src/s4u/s4u_actor.cpp | 11 +++++++++++ src/simix/ActorImpl.cpp | 15 --------------- src/simix/smx_network.cpp | 9 ++++----- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 524f508b66..1168847e21 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -153,17 +153,9 @@ public: Actor(Actor const&) = delete; Actor& operator=(Actor const&) = delete; - // ***** Reference count (delegated to pimpl_) ***** - friend void intrusive_ptr_add_ref(Actor* actor) - { - xbt_assert(actor != nullptr); - SIMIX_process_ref(actor->pimpl_); - } - friend void intrusive_ptr_release(Actor* actor) - { - xbt_assert(actor != nullptr); - SIMIX_process_unref(actor->pimpl_); - } + // ***** Reference count ***** + friend void intrusive_ptr_add_ref(Actor * actor); + friend void intrusive_ptr_release(Actor * actor); // ***** Actor creation ***** /** Retrieve a reference to myself */ diff --git a/include/simgrid/s4u/forward.hpp b/include/simgrid/s4u/forward.hpp index 237a5ebe33..ec485ba5b3 100644 --- a/include/simgrid/s4u/forward.hpp +++ b/include/simgrid/s4u/forward.hpp @@ -13,6 +13,8 @@ namespace simgrid { namespace s4u { class Actor; +XBT_PUBLIC(void) intrusive_ptr_release(Actor* actor); +XBT_PUBLIC(void) intrusive_ptr_add_ref(Actor* actor); using ActorPtr = boost::intrusive_ptr; class Activity; diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index f134c43c99..152fcccbb4 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -189,8 +189,6 @@ XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data); XBT_PUBLIC(void*) SIMIX_host_self_get_data(); /********************************* Process ************************************/ -XBT_PUBLIC(smx_actor_t) SIMIX_process_ref(smx_actor_t process); -XBT_PUBLIC(void) SIMIX_process_unref(smx_actor_t process); XBT_PUBLIC(int) SIMIX_process_count(); XBT_PUBLIC(smx_actor_t) SIMIX_process_self(); XBT_PUBLIC(const char*) SIMIX_process_self_get_name(); diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index eb588cabd2..3b27ed8473 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -44,6 +44,17 @@ ActorPtr Actor::createActor(const char* name, s4u::Host* host, const char* funct return actor->iface(); } +void intrusive_ptr_add_ref(Actor* actor) +{ + xbt_assert(actor != nullptr); + intrusive_ptr_add_ref(actor->pimpl_); +} +void intrusive_ptr_release(Actor* actor) +{ + xbt_assert(actor != nullptr); + intrusive_ptr_release(actor->pimpl_); +} + // ***** Actor methods ***** void Actor::join() { diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index d4b3934ff4..d0f4ae723c 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -38,21 +38,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX unsigned long simix_process_maxpid = 0; -/** Increase the refcount for this process */ -smx_actor_t SIMIX_process_ref(smx_actor_t process) -{ - if (process != nullptr) - intrusive_ptr_add_ref(process); - return process; -} - -/** Decrease the refcount for this process */ -void SIMIX_process_unref(smx_actor_t process) -{ - if (process != nullptr) - intrusive_ptr_release(process); -} - /** * \brief Returns the current agent. * diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 07f4c3c8e6..d4a4781530 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -41,9 +41,8 @@ _find_matching_comm(boost::circular_buffer_space_optimized* dequ void* other_user_data = nullptr; for(auto it = deque->begin(); it != deque->end(); it++){ - smx_activity_t synchro = *it; simgrid::kernel::activity::CommImplPtr comm = - boost::dynamic_pointer_cast(std::move(synchro)); + boost::dynamic_pointer_cast(std::move(*it)); if (comm->type == SIMIX_COMM_SEND) { other_user_data = comm->src_data; @@ -59,7 +58,7 @@ _find_matching_comm(boost::circular_buffer_space_optimized* dequ comm->mbox_cpy = comm->mbox; #endif comm->mbox = nullptr; - return comm; + return std::move(comm); } XBT_DEBUG("Sorry, communication synchro %p does not match our needs:" " its type is %d but we are looking for a comm of type %d (or maybe the filtering didn't match)", @@ -189,8 +188,8 @@ smx_activity_t SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void * XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication"); //find a match in the list of already received comms - other_comm = _find_matching_comm(&mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro, - /*remove_matching*/ true); + other_comm = std::move(_find_matching_comm(&mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro, + /*remove_matching*/ true)); //if not found, assume the receiver came first, register it to the mailbox in the classical way if (not other_comm) { XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request into list"); -- 2.20.1