From 2f32ccb82b474b69e3100f139e0b602d67ea5f63 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 12 Feb 2019 11:05:29 +0100 Subject: [PATCH] start to differentiate kill from exit in ActorImpl --- src/s4u/s4u_Actor.cpp | 12 ++-- src/simix/ActorImpl.cpp | 106 ++++++++++++++++---------------- src/simix/ActorImpl.hpp | 1 + src/smpi/bindings/smpi_pmpi.cpp | 4 +- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 5380bba1f9..0138cf83b8 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -191,8 +191,12 @@ void Actor::kill(aid_t pid) // deprecated void Actor::kill() { smx_actor_t process = SIMIX_process_self(); - simgrid::simix::simcall( - [this, process] { SIMIX_process_kill(pimpl_, (pimpl_ == simix_global->maestro_process) ? pimpl_ : process); }); + simgrid::simix::simcall([this, process] { + if (pimpl_ == simix_global->maestro_process) + pimpl_->exit(); + else + SIMIX_process_kill(pimpl_, process); + }); } smx_actor_t Actor::get_impl() @@ -390,8 +394,8 @@ void resume() void exit() { - smx_actor_t process = SIMIX_process_self(); - simgrid::simix::simcall([process] { SIMIX_process_kill(process, process); }); + smx_actor_t actor = SIMIX_process_self(); + simgrid::simix::simcall([actor] { actor->exit(); }); } void on_exit(std::function fun, void* data) diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index c23b3b86c2..97d9d230fc 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -107,13 +107,62 @@ ActorImpl::~ActorImpl() delete this->context_; } +void ActorImpl::exit() +{ + context_->iwannadie = true; + blocked_ = false; + suspended_ = false; + exception = nullptr; + + // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that + if (host_->is_off()) + this->throw_exception(std::make_exception_ptr(simgrid::kernel::context::StopRequest("host failed"))); + + /* destroy the blocking synchro if any */ + if (waiting_synchro != nullptr) { + + activity::ExecImplPtr exec = boost::dynamic_pointer_cast(waiting_synchro); + activity::CommImplPtr comm = boost::dynamic_pointer_cast(waiting_synchro); + activity::SleepImplPtr sleep = boost::dynamic_pointer_cast(waiting_synchro); + activity::RawImplPtr raw = boost::dynamic_pointer_cast(waiting_synchro); + activity::IoImplPtr io = boost::dynamic_pointer_cast(waiting_synchro); + + if (exec != nullptr && exec->surf_action_) { + exec->cancel(); + exec->surf_action_->unref(); + exec->surf_action_ = nullptr; + } else if (comm != nullptr) { + comms.remove(waiting_synchro); + comm->cancel(); + // Remove first occurrence of &process->simcall: + auto i = boost::range::find(waiting_synchro->simcalls_, &simcall); + if (i != waiting_synchro->simcalls_.end()) + waiting_synchro->simcalls_.remove(&simcall); + } else if (sleep != nullptr) { + if (sleep->surf_action_) + sleep->surf_action_->cancel(); + sleep->post(); + } else if (raw != nullptr) { + SIMIX_synchro_stop_waiting(this, &simcall); + } else if (io != nullptr) { + io->cancel(); + } else { + simgrid::kernel::activity::ActivityImplPtr activity = waiting_synchro; + xbt_die("Activity %s is of unknown type %s", activity->name_.c_str(), + simgrid::xbt::demangle(typeid(activity).name()).get()); + } + + waiting_synchro = nullptr; + } +} + void ActorImpl::set_kill_time(double kill_time) { if (kill_time <= SIMIX_get_clock()) return; XBT_DEBUG("Set kill time %f for process %s@%s", kill_time, get_cname(), host_->get_cname()); kill_timer = SIMIX_timer_set(kill_time, [this] { - SIMIX_process_kill(this, nullptr); + this->exit(); kill_timer = nullptr; }); } @@ -148,7 +197,7 @@ simgrid::s4u::Actor* ActorImpl::restart() simgrid::kernel::actor::ProcessArg arg = ProcessArg(host_, this); // kill the old process - SIMIX_process_kill(this, (this == simix_global->maestro_process) ? this : SIMIX_process_self()); + (this == simix_global->maestro_process) ? this->exit() : SIMIX_process_kill(this, SIMIX_process_self()); // start the new process ActorImplPtr actor = @@ -431,59 +480,8 @@ void SIMIX_process_kill(smx_actor_t actor, smx_actor_t issuer) (issuer == nullptr || issuer->host_ == nullptr ? "(null)" : issuer->host_->get_cname()), actor->get_cname(), actor->host_->get_cname()); - actor->context_->iwannadie = true; - actor->blocked_ = false; - actor->suspended_ = false; - actor->exception = nullptr; - - // Forcefully kill the actor if its host is turned off. Not an HostFailureException because you should not survive that - if (actor->host_->is_off()) - actor->throw_exception(std::make_exception_ptr(simgrid::kernel::context::StopRequest("host failed"))); - - /* destroy the blocking synchro if any */ - if (actor->waiting_synchro != nullptr) { - - simgrid::kernel::activity::ExecImplPtr exec = - boost::dynamic_pointer_cast(actor->waiting_synchro); - simgrid::kernel::activity::CommImplPtr comm = - boost::dynamic_pointer_cast(actor->waiting_synchro); - simgrid::kernel::activity::SleepImplPtr sleep = - boost::dynamic_pointer_cast(actor->waiting_synchro); - simgrid::kernel::activity::RawImplPtr raw = - boost::dynamic_pointer_cast(actor->waiting_synchro); - simgrid::kernel::activity::IoImplPtr io = - boost::dynamic_pointer_cast(actor->waiting_synchro); - - if (exec != nullptr) { - if (exec->surf_action_) { - exec->surf_action_->cancel(); - exec->surf_action_->unref(); - exec->surf_action_ = nullptr; - } - } else if (comm != nullptr) { - actor->comms.remove(actor->waiting_synchro); - comm->cancel(); - // Remove first occurrence of &process->simcall: - auto i = boost::range::find(actor->waiting_synchro->simcalls_, &actor->simcall); - if (i != actor->waiting_synchro->simcalls_.end()) - actor->waiting_synchro->simcalls_.remove(&actor->simcall); - } else if (sleep != nullptr) { - if (sleep->surf_action_) - sleep->surf_action_->cancel(); - sleep->post(); - } else if (raw != nullptr) { - SIMIX_synchro_stop_waiting(actor, &actor->simcall); - - } else if (io != nullptr) { - io->cancel(); - } else { - simgrid::kernel::activity::ActivityImplPtr activity = actor->waiting_synchro; - xbt_die("Activity %s is of unknown type %s", activity->name_.c_str(), - simgrid::xbt::demangle(typeid(activity).name()).get()); - } + actor->exit(); - actor->waiting_synchro = nullptr; - } if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), actor) == end(simix_global->process_to_run) && actor != issuer) { diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index e04ec22748..acb80de17d 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -94,6 +94,7 @@ private: public: static ActorImplPtr create(std::string name, simix::ActorCode code, void* data, s4u::Host* host, std::unordered_map* properties, smx_actor_t parent_actor); + void exit(); void daemonize(); bool is_daemon() { return daemon_; } /** Whether this actor has been daemonized */ diff --git a/src/smpi/bindings/smpi_pmpi.cpp b/src/smpi/bindings/smpi_pmpi.cpp index 07e616a7e9..8d8886f123 100644 --- a/src/smpi/bindings/smpi_pmpi.cpp +++ b/src/smpi/bindings/smpi_pmpi.cpp @@ -122,8 +122,8 @@ int PMPI_Abort(MPI_Comm /*comm*/, int /*errorcode*/) { smpi_bench_end(); // FIXME: should kill all processes in comm instead - smx_actor_t process = SIMIX_process_self(); - simgrid::simix::simcall([process] { SIMIX_process_kill(process, process); }); + smx_actor_t actor = SIMIX_process_self(); + simgrid::simix::simcall([actor] { actor->exit(); }); return MPI_SUCCESS; } -- 2.20.1