From f063625862eb4dfe006653ce98a4291fb4c1810e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 11 Aug 2019 00:51:16 +0200 Subject: [PATCH] Port simcall_process_suspend to the modernity Also simplify its logic by moving the s4u parts within the kernel --- include/simgrid/simix.h | 3 +-- src/kernel/activity/SleepImpl.cpp | 2 +- src/kernel/actor/ActorImpl.cpp | 35 ++++++++----------------------- src/kernel/actor/ActorImpl.hpp | 2 +- src/s4u/s4u_Actor.cpp | 15 ++++++++----- src/simix/libsmx.cpp | 6 +----- src/simix/popping_accessors.hpp | 14 ------------- src/simix/popping_bodies.cpp | 7 ------- src/simix/popping_enum.h | 1 - src/simix/popping_generated.cpp | 5 ----- src/simix/simcalls.in | 2 -- 11 files changed, 23 insertions(+), 69 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index bd2601c1e4..db8f5dc34e 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -178,8 +178,7 @@ XBT_PUBLIC bool simcall_execution_test(const smx_activity_t& execution); /**************************** Process simcalls ********************************/ SG_BEGIN_DECL() void simcall_process_set_data(smx_actor_t process, void* data); -/* Process handling */ -XBT_PUBLIC void simcall_process_suspend(smx_actor_t process); +XBT_ATTRIB_DEPRECATED_v327("Please use Actor::suspend()") XBT_PUBLIC void simcall_process_suspend(smx_actor_t process); XBT_ATTRIB_DEPRECATED_v327("Please use Actor::join()") XBT_PUBLIC void simcall_process_join(smx_actor_t process, double timeout); diff --git a/src/kernel/activity/SleepImpl.cpp b/src/kernel/activity/SleepImpl.cpp index 4cf48083f7..f80692be18 100644 --- a/src/kernel/activity/SleepImpl.cpp +++ b/src/kernel/activity/SleepImpl.cpp @@ -61,7 +61,7 @@ void SleepImpl::finish() if (simcall->issuer->is_suspended()) { XBT_DEBUG("Wait! This process is suspended and can't wake up now."); simcall->issuer->suspended_ = false; - simcall_HANDLER_process_suspend(simcall, simcall->issuer); + simcall->issuer->suspend(simcall->issuer); } else { simcall->issuer->simcall_answer(); } diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index d8214a7a19..0d4521318d 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -356,27 +356,24 @@ s4u::Actor* ActorImpl::restart() return actor->ciface(); } -activity::ActivityImplPtr ActorImpl::suspend(ActorImpl* issuer) +void ActorImpl::suspend(ActorImpl* issuer) { if (suspended_) { XBT_DEBUG("Actor '%s' is already suspended", get_cname()); - return nullptr; + return; } suspended_ = true; - /* If we are suspending another actor that is waiting on a sync, suspend its synchronization. */ - if (this != issuer) { - if (waiting_synchro) - waiting_synchro->suspend(); - /* If the other actor is not waiting, its suspension is delayed to when the actor is rescheduled. */ - - return nullptr; - } else { + /* If the suspended actor is waiting on a sync, suspend its synchronization. */ + if (waiting_synchro == nullptr) { activity::ExecImpl* exec = new activity::ExecImpl(); - (*exec).set_name("suspend").set_host(host_).set_flops_amount(0.0).start(); - return activity::ExecImplPtr(exec); + exec->set_name("suspend").set_host(host_).set_flops_amount(0.0).start(); + waiting_synchro = activity::ExecImplPtr(exec); + + waiting_synchro->simcalls_.push_back(&simcall); } + waiting_synchro->suspend(); } void ActorImpl::resume() @@ -554,20 +551,6 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn return simgrid::kernel::actor::ActorImpl::attach(name, data, sg_host_by_name(hostname), properties).get(); } -void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t actor) -{ - smx_activity_t sync_suspend = actor->suspend(simcall->issuer); - - if (actor != simcall->issuer) { - simcall->issuer->simcall_answer(); - } else { - sync_suspend->simcalls_.push_back(simcall); - actor->waiting_synchro = sync_suspend; - actor->waiting_synchro->suspend(); - } - /* If we are suspending ourselves, then just do not finish the simcall now */ -} - int SIMIX_process_count() { return simix_global->process_list.size(); diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index 81a710a7a5..d118e36bb6 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -123,7 +123,7 @@ public: void daemonize(); bool is_suspended() { return suspended_; } s4u::Actor* restart(); - activity::ActivityImplPtr suspend(ActorImpl* issuer); + void suspend(ActorImpl* issuer); void resume(); activity::ActivityImplPtr join(ActorImpl* actor, double timeout); activity::ActivityImplPtr sleep(double duration); diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index b5bbadd696..83e905fd82 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -186,8 +186,16 @@ aid_t Actor::get_ppid() const void Actor::suspend() { + auto issuer = SIMIX_process_self(); + auto target = pimpl_; s4u::Actor::on_suspend(*this); - simcall_process_suspend(pimpl_); + simix::simcall_blocking([issuer, target]() { + target->suspend(issuer); + if (target != issuer) { + /* If we are suspending ourselves, then just do not finish the simcall now */ + issuer->simcall_answer(); + } + }); } void Actor::resume() @@ -435,10 +443,7 @@ Host* get_host() void suspend() { - kernel::actor::ActorImpl* actor = SIMIX_process_self(); - Actor::on_suspend(*actor->ciface()); - - simcall_process_suspend(actor); + SIMIX_process_self()->iface()->suspend(); } void resume() diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index e2a4e63cd6..70b401484e 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -49,13 +49,9 @@ void simcall_process_join(smx_actor_t process, double timeout) SIMIX_process_self()->join(process, timeout); } -/** - * @ingroup simix_process_management - * @brief Suspends an actor - */ void simcall_process_suspend(smx_actor_t process) { - simcall_BODY_process_suspend(process); + SIMIX_process_self()->iface()->suspend(); } e_smx_state_t simcall_process_sleep(double duration) diff --git a/src/simix/popping_accessors.hpp b/src/simix/popping_accessors.hpp index ea7db0f99a..9843aaea86 100644 --- a/src/simix/popping_accessors.hpp +++ b/src/simix/popping_accessors.hpp @@ -15,19 +15,6 @@ */ #include "src/simix/popping_private.hpp" -static inline smx_actor_t simcall_process_suspend__get__process(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline smx_actor_t simcall_process_suspend__getraw__process(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal_raw(simcall->args[0]); -} -static inline void simcall_process_suspend__set__process(smx_simcall_t simcall, smx_actor_t arg) -{ - simgrid::simix::marshal(simcall->args[0], arg); -} - static inline simgrid::kernel::activity::ExecImpl* simcall_execution_wait__get__execution(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); @@ -1012,7 +999,6 @@ static inline void simcall_run_blocking__set__code(smx_simcall_t simcall, std::f /* The prototype of all simcall handlers, automatically generated for you */ -XBT_PRIVATE void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process); XBT_PRIVATE void simcall_HANDLER_execution_wait(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl* execution); XBT_PRIVATE void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl** execs, size_t count, double timeout); XBT_PRIVATE void simcall_HANDLER_execution_test(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl* execution); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index e5d44ad56b..40a802fcd1 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -39,13 +39,6 @@ inline static R simcall(e_smx_simcall_t call, T const&... t) return simgrid::simix::unmarshal(self->simcall.result); } -inline static void simcall_BODY_process_suspend(smx_actor_t process) -{ - if (0) /* Go to that function to follow the code flow through the simcall barrier */ - simcall_HANDLER_process_suspend(&SIMIX_process_self()->simcall, process); - return simcall(SIMCALL_PROCESS_SUSPEND, process); -} - inline static int simcall_BODY_execution_wait(simgrid::kernel::activity::ExecImpl* execution) { if (0) /* Go to that function to follow the code flow through the simcall barrier */ diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 8a477ff714..f2182ee622 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -19,7 +19,6 @@ */ typedef enum { SIMCALL_NONE, - SIMCALL_PROCESS_SUSPEND, SIMCALL_EXECUTION_WAIT, SIMCALL_EXECUTION_WAITANY_FOR, SIMCALL_EXECUTION_TEST, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 6b68380117..880712d9cf 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -26,7 +26,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping); /** @brief Simcalls' names (generated from src/simix/simcalls.in) */ const char* simcall_names[] = { "SIMCALL_NONE", - "SIMCALL_PROCESS_SUSPEND", "SIMCALL_EXECUTION_WAIT", "SIMCALL_EXECUTION_WAITANY_FOR", "SIMCALL_EXECUTION_TEST", @@ -62,10 +61,6 @@ void simgrid::kernel::actor::ActorImpl::simcall_handle(int value) { if (context_->iwannadie) return; switch (simcall.call) { - case SIMCALL_PROCESS_SUSPEND: - simcall_HANDLER_process_suspend(&simcall, simgrid::simix::unmarshal(simcall.args[0])); - break; - case SIMCALL_EXECUTION_WAIT: simcall_HANDLER_execution_wait(&simcall, simgrid::simix::unmarshal(simcall.args[0])); break; diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 6d264cb298..05a4c06aef 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -35,8 +35,6 @@ # Last but not the least, you should declare the new simix call in # ./include/simgrid/simix.h (otherwise you will get a warning at compile time) -void process_suspend(smx_actor_t process) [[block]]; - int execution_wait(simgrid::kernel::activity::ExecImpl* execution) [[block]]; int execution_waitany_for(simgrid::kernel::activity::ExecImpl** execs, size_t count, double timeout) [[block]]; bool execution_test(simgrid::kernel::activity::ExecImpl* execution) [[block]]; -- 2.20.1