Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add test() for asynchronous executions
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 11 Dec 2017 14:21:11 +0000 (15:21 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 11 Dec 2017 14:21:11 +0000 (15:21 +0100)
very inspired by that for comms
and use it in exec-monitor

examples/s4u/exec-monitor/s4u-exec-monitor.cpp
include/simgrid/simix.h
src/s4u/s4u_exec.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
src/simix/smx_host.cpp
src/simix/smx_host_private.hpp

index 88e51ce..535f2fb 100644 (file)
@@ -12,7 +12,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example")
 
 static void monitor(simgrid::s4u::ExecPtr activity)
 {
-  while (activity->getRemains() > 0) { // FIXME: use a test() here once that function is implemented
+  while (not activity->test()) {
     XBT_INFO("activity remaining duration: %g (%.0f%%)", activity->getRemains(), 100 * activity->getRemainingRatio());
     simgrid::s4u::this_actor::sleep_for(5);
   }
index ba24e68..5acf3b8 100644 (file)
@@ -195,6 +195,7 @@ XBT_PUBLIC(void) simcall_execution_cancel(smx_activity_t execution);
 XBT_PUBLIC(void) simcall_execution_set_priority(smx_activity_t execution, double priority);
 XBT_PUBLIC(void) simcall_execution_set_bound(smx_activity_t execution, double bound);
 XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution);
+XBT_PUBLIC(e_smx_state_t) simcall_execution_test(smx_activity_t execution);
 
 /**************************** Process simcalls ********************************/
 SG_BEGIN_DECL()
index f14a450..ca3623d 100644 (file)
@@ -41,6 +41,11 @@ bool Exec::test()
     this->start();
   }
 
+  if (simcall_execution_test(pimpl_)) {
+    state_ = finished;
+    return true;
+  }
+
   return false;
 }
 
index 9662361..c6b6e1c 100644 (file)
@@ -170,6 +170,11 @@ e_smx_state_t simcall_execution_wait(smx_activity_t execution)
   return (e_smx_state_t) simcall_BODY_execution_wait(execution);
 }
 
+e_smx_state_t simcall_execution_test(smx_activity_t execution)
+{
+  return (e_smx_state_t)simcall_BODY_execution_test(execution);
+}
+
 /**
  * \ingroup simix_process_management
  * \brief Kills all SIMIX processes.
index 1ec7132..fc80fc2 100644 (file)
@@ -311,6 +311,34 @@ static inline void simcall_execution_wait__set__result(smx_simcall_t simcall, in
   simgrid::simix::marshal<int>(simcall->result, result);
 }
 
+static inline boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>
+simcall_execution_test__get__execution(smx_simcall_t simcall)
+{
+  return simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]);
+}
+static inline simgrid::kernel::activity::ActivityImpl* simcall_execution_test__getraw__execution(smx_simcall_t simcall)
+{
+  return simgrid::simix::unmarshal_raw<simgrid::kernel::activity::ActivityImpl*>(simcall->args[0]);
+}
+static inline void
+simcall_execution_test__set__execution(smx_simcall_t simcall,
+                                       boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> arg)
+{
+  simgrid::simix::marshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0], arg);
+}
+static inline int simcall_execution_test__get__result(smx_simcall_t simcall)
+{
+  return simgrid::simix::unmarshal<int>(simcall->result);
+}
+static inline int simcall_execution_test__getraw__result(smx_simcall_t simcall)
+{
+  return simgrid::simix::unmarshal_raw<int>(simcall->result);
+}
+static inline void simcall_execution_test__set__result(smx_simcall_t simcall, int result)
+{
+  simgrid::simix::marshal<int>(simcall->result, result);
+}
+
 static inline smx_actor_t simcall_process_on_exit__get__process(smx_simcall_t simcall)
 {
   return simgrid::simix::unmarshal<smx_actor_t>(simcall->args[0]);
@@ -1379,6 +1407,9 @@ XBT_PRIVATE boost::intrusive_ptr<simgrid::kernel::activity::ExecImpl>
 simcall_HANDLER_execution_start(smx_simcall_t simcall, const char* name, double flops_amount, double priority,
                                 double bound, sg_host_t host);
 XBT_PRIVATE void simcall_HANDLER_execution_wait(smx_simcall_t simcall, boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> execution);
+XBT_PRIVATE void
+simcall_HANDLER_execution_test(smx_simcall_t simcall,
+                               boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> execution);
 XBT_PRIVATE boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> simcall_HANDLER_comm_iprobe(smx_simcall_t simcall, smx_mailbox_t mbox, int type, simix_match_func_t match_fun, void* data);
 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout);
 XBT_PRIVATE boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, simix_match_func_t match_fun, simix_clean_func_t clean_fun, simix_copy_data_func_t copy_data_fun, void* data, int detached);
index e464ce2..f616cf5 100644 (file)
@@ -94,6 +94,13 @@ inline static int simcall_BODY_execution_wait(boost::intrusive_ptr<simgrid::kern
   return simcall<int, boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(SIMCALL_EXECUTION_WAIT, execution);
 }
 
+inline static int simcall_BODY_execution_test(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> execution)
+{
+  if (0) /* Go to that function to follow the code flow through the simcall barrier */
+    simcall_HANDLER_execution_test(&SIMIX_process_self()->simcall, execution);
+  return simcall<int, boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(SIMCALL_EXECUTION_TEST, execution);
+}
+
 inline static void simcall_BODY_process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void* data)
 {
   if (0) /* Go to that function to follow the code flow through the simcall barrier */
index e2a7c49..7d489a4 100644 (file)
@@ -27,6 +27,7 @@ typedef enum {
   SIMCALL_EXECUTION_START,
   SIMCALL_EXECUTION_PARALLEL_START,
   SIMCALL_EXECUTION_WAIT,
+  SIMCALL_EXECUTION_TEST,
   SIMCALL_PROCESS_ON_EXIT,
   SIMCALL_COMM_IPROBE,
   SIMCALL_COMM_SEND,
index 21e7222..5184279 100644 (file)
@@ -33,6 +33,7 @@ const char* simcall_names[] = {
     "SIMCALL_EXECUTION_START",
     "SIMCALL_EXECUTION_PARALLEL_START",
     "SIMCALL_EXECUTION_WAIT",
+    "SIMCALL_EXECUTION_TEST",
     "SIMCALL_PROCESS_ON_EXIT",
     "SIMCALL_COMM_IPROBE",
     "SIMCALL_COMM_SEND",
@@ -113,6 +114,12 @@ case SIMCALL_EXECUTION_WAIT:
   simcall_HANDLER_execution_wait(simcall, simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]));
   break;
 
+case SIMCALL_EXECUTION_TEST:
+  simcall_HANDLER_execution_test(
+      simcall,
+      simgrid::simix::unmarshal<boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl>>(simcall->args[0]));
+  break;
+
 case SIMCALL_PROCESS_ON_EXIT:
   SIMIX_process_on_exit(simgrid::simix::unmarshal<smx_actor_t>(simcall->args[0]), simgrid::simix::unmarshal<int_f_pvoid_pvoid_t>(simcall->args[1]), simgrid::simix::unmarshal<void*>(simcall->args[2]));
   SIMIX_simcall_answer(simcall);
index 4faaeed..b2425c0 100644 (file)
@@ -44,6 +44,7 @@ int  process_sleep(double duration) [[block]];
 boost::intrusive_ptr<simgrid::kernel::activity::ExecImpl> execution_start(const char* name, double flops_amount, double priority, double bound, sg_host_t host);
 boost::intrusive_ptr<simgrid::kernel::activity::ExecImpl> execution_parallel_start(const char* name, int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double rate, double timeout) [[nohandler]];
 int           execution_wait(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> execution) [[block]];
+int           execution_test(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> execution) [[block]];
 
 void          process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void* data) [[nohandler]];
 
index b736f17..692e828 100644 (file)
@@ -222,18 +222,40 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_activity_t synchr
   /* set surf's synchro */
   if (MC_is_active() || MC_record_replay_is_active()) {
     synchro->state = SIMIX_DONE;
-    SIMIX_execution_finish(exec);
+    SIMIX_execution_finish(synchro);
     return;
   }
 
   /* If the synchro is already finished then perform the error handling */
   if (synchro->state != SIMIX_RUNNING)
-    SIMIX_execution_finish(exec);
+    SIMIX_execution_finish(synchro);
 }
 
-void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec)
+void simcall_HANDLER_execution_test(smx_simcall_t simcall, smx_activity_t synchro)
 {
-  for (smx_simcall_t const& simcall : exec->simcalls) {
+  simgrid::kernel::activity::ExecImplPtr exec =
+      boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(synchro);
+
+  simcall_execution_test__set__result(simcall, (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING));
+  if (simcall_execution_test__get__result(simcall)) {
+    synchro->simcalls.push_back(simcall);
+    SIMIX_execution_finish(synchro);
+  } else {
+    SIMIX_simcall_answer(simcall);
+  }
+  /* If the synchro is already finished then perform the error handling */
+  if (synchro->state != SIMIX_RUNNING)
+    SIMIX_execution_finish(synchro);
+}
+
+void SIMIX_execution_finish(smx_activity_t synchro)
+{
+  simgrid::kernel::activity::ExecImplPtr exec =
+      boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(synchro);
+
+  while (not synchro->simcalls.empty()) {
+    smx_simcall_t simcall = synchro->simcalls.front();
+    synchro->simcalls.pop_front();
     switch (exec->state) {
 
       case SIMIX_DONE:
index f4b6a96..899fab3 100644 (file)
@@ -49,7 +49,7 @@ XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char*
 
 XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host);
 
-XBT_PRIVATE void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec);
+XBT_PRIVATE void SIMIX_execution_finish(smx_activity_t synchro);
 
 XBT_PRIVATE void SIMIX_set_category(smx_activity_t synchro, const char* category);
 }