From 29902a8dfbe24a612cc3d0f3022c5e12fc5cc5bc Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Thu, 21 Oct 2021 16:36:13 +0200 Subject: [PATCH] split Comm::on_start into two signals (on_send and on_recv) + the actual start of the Comm occurs when both send and receiver are there. This event can be notified by CommImpl::on_start + TODO: Comm::on_completion and CommImpl::on_completion are redundant + TODO: The CommImpl signals should go back to Comm, but on kernel side a CommImpl does not have a piface to notify (yet) --- docs/source/Plugins.rst | 7 ++++--- docs/source/app_s4u.rst | 3 ++- include/simgrid/s4u/Comm.hpp | 4 +++- src/instr/instr_platform.cpp | 9 +++++---- src/kernel/activity/CommImpl.hpp | 1 - src/s4u/s4u_Comm.cpp | 11 ++++++----- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/source/Plugins.rst b/docs/source/Plugins.rst index a1285739c8..0c6fd2d35f 100644 --- a/docs/source/Plugins.rst +++ b/docs/source/Plugins.rst @@ -77,15 +77,16 @@ Partial list of existing signals in s4u: :cpp:member:`Actor::on_host_change ` :cpp:member:`Actor::on_termination ` :cpp:member:`Actor::on_destruction ` -- :cpp:member:`Comm::on_start ` +- :cpp:member:`Comm::on_send ` + :cpp:member:`Comm::on_recv ` :cpp:member:`Comm::on_completion ` +- :cpp:member:`CommImpl::on_start ` + :cpp:member:`CommImpl::on_completion ` - :cpp:member:`Engine::on_platform_creation ` :cpp:member:`Engine::on_platform_created ` :cpp:member:`Engine::on_time_advance ` :cpp:member:`Engine::on_simulation_end ` :cpp:member:`Engine::on_deadlock ` -- :cpp:member:`Comm::on_start ` - :cpp:member:`Comm::on_completion ` - :cpp:member:`Exec::on_start ` :cpp:member:`Exec::on_completion ` - :cpp:member:`Exec::on_start ` diff --git a/docs/source/app_s4u.rst b/docs/source/app_s4u.rst index a28efe8941..09faa66f42 100644 --- a/docs/source/app_s4u.rst +++ b/docs/source/app_s4u.rst @@ -2101,7 +2101,8 @@ Signals .. group-tab:: C++ .. doxygenvariable:: simgrid::s4u::Comm::on_completion - .. doxygenvariable:: simgrid::s4u::Comm::on_start + .. doxygenvariable:: simgrid::s4u::Comm::on_recv + .. doxygenvariable:: simgrid::s4u::Comm::on_send .. _API_s4u_Exec: diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 228fcec0dc..b42d1e9bcf 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -64,7 +64,9 @@ public: */ static void sendto(Host* from, Host* to, uint64_t simulated_size_in_bytes); - static xbt::signal on_start; + static xbt::signal on_send; + static xbt::signal on_recv; + static xbt::signal on_start; static xbt::signal on_completion; /*! take a vector s4u::CommPtr and return when one of them is finished. diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 2b6db3f681..9e70fa7006 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -470,10 +470,11 @@ void define_callbacks() s4u::Exec::on_completion.connect([](s4u::Exec const&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->pop_event(); }); - s4u::Comm::on_start.connect([](s4u::Comm const&, bool is_sender) { - Container::by_name(instr_pid(*s4u::Actor::self())) - ->get_state("ACTOR_STATE") - ->push_event(is_sender ? "send" : "receive"); + s4u::Comm::on_send.connect([](s4u::Comm const&) { + Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("send"); + }); + s4u::Comm::on_recv.connect([](s4u::Comm const&) { + Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("receive"); }); s4u::Comm::on_completion.connect([](s4u::Comm const&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->pop_event(); diff --git a/src/kernel/activity/CommImpl.hpp b/src/kernel/activity/CommImpl.hpp index 0334947bf0..c6411df3a1 100644 --- a/src/kernel/activity/CommImpl.hpp +++ b/src/kernel/activity/CommImpl.hpp @@ -89,7 +89,6 @@ expectations of the other side, too. See */ void* src_data_ = nullptr; /* User data associated to the communication */ void* dst_data_ = nullptr; - static xbt::signal on_start; static xbt::signal on_completion; }; diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index b30f3115dd..8db5454fb2 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -19,7 +19,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm, s4u_activity, "S4U asynchronous commun namespace simgrid { namespace s4u { -xbt::signal Comm::on_start; +xbt::signal Comm::on_send; +xbt::signal Comm::on_recv; xbt::signal Comm::on_completion; void Comm::complete(Activity::State state) @@ -195,12 +196,12 @@ Comm* Comm::start() }); } else if (src_buff_ != nullptr) { // Sender side - on_start(*this, true /* is_sender*/); + on_send(*this); pimpl_ = simcall_comm_isend(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, clean_fun_, copy_data_function_, get_user_data(), detached_); } else if (dst_buff_ != nullptr) { // Receiver side xbt_assert(not detached_, "Receive cannot be detached"); - on_start(*this, false /*is_sender*/); + on_recv(*this); pimpl_ = simcall_comm_irecv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_, get_user_data(), rate_); @@ -234,12 +235,12 @@ Comm* Comm::wait_for(double timeout) if (from_ != nullptr || to_ != nullptr) { return vetoable_start()->wait_for(timeout); // In the case of host2host comm, do it in two simcalls } else if (src_buff_ != nullptr) { - on_start(*this, true /*is_sender*/); + on_send(*this); simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_, copy_data_function_, get_user_data(), timeout); } else { // Receiver - on_start(*this, false /*is_sender*/); + on_recv(*this); simcall_comm_recv(receiver_, mailbox_->get_impl(), dst_buff_, &dst_buff_size_, match_fun_, copy_data_function_, get_user_data(), timeout, rate_); } -- 2.20.1