Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Port simcall_process_suspend to the modernity
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 10 Aug 2019 22:51:16 +0000 (00:51 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 10 Aug 2019 23:07:52 +0000 (01:07 +0200)
Also simplify its logic by moving the s4u parts within the kernel

include/simgrid/simix.h
src/kernel/activity/SleepImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp
src/s4u/s4u_Actor.cpp
src/simix/libsmx.cpp
src/simix/popping_accessors.hpp
src/simix/popping_bodies.cpp
src/simix/popping_enum.h
src/simix/popping_generated.cpp
src/simix/simcalls.in

index bd2601c..db8f5dc 100644 (file)
@@ -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);
index 4cf4808..f80692b 100644 (file)
@@ -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();
     }
index d8214a7..0d45213 100644 (file)
@@ -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();
index 81a710a..d118e36 100644 (file)
@@ -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);
index b5bbadd..83e905f 100644 (file)
@@ -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()
index e2a4e63..70b4014 100644 (file)
@@ -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)
index ea7db0f..9843aae 100644 (file)
  */
 
 #include "src/simix/popping_private.hpp"
-static inline smx_actor_t simcall_process_suspend__get__process(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal<smx_actor_t>(simcall->args[0]);
-}
-static inline smx_actor_t simcall_process_suspend__getraw__process(smx_simcall_t simcall)
-{
-  return simgrid::simix::unmarshal_raw<smx_actor_t>(simcall->args[0]);
-}
-static inline void simcall_process_suspend__set__process(smx_simcall_t simcall, smx_actor_t arg)
-{
-  simgrid::simix::marshal<smx_actor_t>(simcall->args[0], arg);
-}
-
 static inline simgrid::kernel::activity::ExecImpl* simcall_execution_wait__get__execution(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal<simgrid::kernel::activity::ExecImpl*>(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);
index e5d44ad..40a802f 100644 (file)
@@ -39,13 +39,6 @@ inline static R simcall(e_smx_simcall_t call, T const&... t)
   return simgrid::simix::unmarshal<R>(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<void, smx_actor_t>(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 */
index 8a477ff..f2182ee 100644 (file)
@@ -19,7 +19,6 @@
  */
 typedef enum {
   SIMCALL_NONE,
-  SIMCALL_PROCESS_SUSPEND,
   SIMCALL_EXECUTION_WAIT,
   SIMCALL_EXECUTION_WAITANY_FOR,
   SIMCALL_EXECUTION_TEST,
index 6b68380..880712d 100644 (file)
@@ -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<smx_actor_t>(simcall.args[0]));
-      break;
-
     case SIMCALL_EXECUTION_WAIT:
       simcall_HANDLER_execution_wait(&simcall, simgrid::simix::unmarshal<simgrid::kernel::activity::ExecImpl*>(simcall.args[0]));
       break;
index 6d264cb..05a4c06 100644 (file)
@@ -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]];