Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simcall_execution_destroy() -> simgrid::simix::Exec::unref()
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 19:53:05 +0000 (21:53 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 9 May 2016 19:54:39 +0000 (21:54 +0200)
Plus cosmetics on my way.

14 files changed:
include/simgrid/simix.h
src/msg/msg_task.cpp
src/simix/SynchroExec.cpp
src/simix/SynchroExec.hpp
src/simix/libsmx.cpp
src/simix/popping.cpp
src/simix/popping_accessors.h
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.h
src/simix/smx_process.cpp

index 77aeb08..59b4c3d 100644 (file)
@@ -278,7 +278,6 @@ XBT_PUBLIC(smx_synchro_t) simcall_execution_parallel_start(const char *name,
                                                      double *bytes_amount,
                                                      double amount,
                                                      double rate);
-XBT_PUBLIC(void) simcall_execution_destroy(smx_synchro_t execution);
 XBT_PUBLIC(void) simcall_execution_cancel(smx_synchro_t execution);
 XBT_PUBLIC(void) simcall_execution_set_priority(smx_synchro_t execution, double priority);
 XBT_PUBLIC(void) simcall_execution_set_bound(smx_synchro_t execution, double bound);
index 4910856..a3b6d20 100644 (file)
@@ -196,7 +196,6 @@ void MSG_task_set_name(msg_task_t task, const char *name)
  */
 msg_error_t MSG_task_destroy(msg_task_t task)
 {
-  smx_synchro_t action = NULL;
   xbt_assert((task != NULL), "Invalid parameter");
 
   if (task->simdata->isused) {
@@ -207,9 +206,8 @@ msg_error_t MSG_task_destroy(msg_task_t task)
 
   xbt_free(task->name);
 
-  action = task->simdata->compute;
-  if (action)
-    simcall_execution_destroy(action);
+  if (task->simdata->compute)
+    task->simdata->compute->unref();
 
   /* parallel tasks only */
   xbt_free(task->simdata->host_list);
index 6dfa770..02ce125 100644 (file)
@@ -25,3 +25,15 @@ double simgrid::simix::Exec::remains()
 
   return 0;
 }
+
+void simgrid::simix::Exec::unref()
+{
+  refcount--;
+  if (refcount > 0)
+    return;
+
+  if (surf_exec)
+    surf_exec->unref();
+
+  delete this;
+}
index d24af4f..7466a86 100644 (file)
@@ -17,9 +17,12 @@ namespace simix {
     void suspend();
     void resume();
     double remains();
+    void unref();
 
     sg_host_t host;                /* The host where the execution takes place */
     surf_action_t surf_exec;        /* The Surf execution action encapsulated */
+  private:
+    int refcount = 1;
   };
 
 }} // namespace simgrid::simix
index fe211b6..bbea457 100644 (file)
@@ -125,18 +125,6 @@ smx_synchro_t simcall_execution_parallel_start(const char *name,
 
 }
 
-/**
- * \ingroup simix_process_management
- * \brief Destroys an execution synchro.
- *
- * Destroys a synchro, freeing its memory. This function cannot be called if there are a conditional waiting for it.
- * \param execution The execution synchro to destroy
- */
-void simcall_execution_destroy(smx_synchro_t execution)
-{
-  simcall_BODY_execution_destroy(execution);
-}
-
 /**
  * \ingroup simix_process_management
  * \brief Cancels an execution synchro.
index e4a621b..e8c8e5f 100644 (file)
@@ -39,7 +39,7 @@ void SIMIX_simcall_exit(smx_synchro_t synchro)
 {
   simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(synchro);
   if (exec != nullptr) {
-    SIMIX_post_host_execute(synchro);
+    SIMIX_post_host_execute(exec);
     return;
   }
 
index f59b4b1..f5f1a3f 100644 (file)
@@ -289,13 +289,6 @@ static inline void simcall_execution_parallel_start__set__result(smx_simcall_t s
     simcall->result.dp = result;
 }
 
-static inline smx_synchro_t simcall_execution_destroy__get__execution(smx_simcall_t simcall) {
-  return (smx_synchro_t) simcall->args[0].dp;
-}
-static inline void simcall_execution_destroy__set__execution(smx_simcall_t simcall, void* arg) {
-    simcall->args[0].dp = arg;
-}
-
 static inline smx_synchro_t simcall_execution_cancel__get__execution(smx_simcall_t simcall) {
   return (smx_synchro_t) simcall->args[0].dp;
 }
index 04cf2e5..b872bbb 100644 (file)
@@ -395,27 +395,6 @@ inline static smx_synchro_t simcall_BODY_execution_parallel_start(const char* na
     return (smx_synchro_t) self->simcall.result.dp;
   }
   
-inline static void simcall_BODY_execution_destroy(smx_synchro_t execution) {
-    smx_process_t self = SIMIX_process_self();
-
-    /* Go to that function to follow the code flow through the simcall barrier */
-    if (0) SIMIX_execution_destroy(execution);
-    /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */
-
-    self->simcall.call = SIMCALL_EXECUTION_DESTROY;
-    memset(&self->simcall.result, 0, sizeof(self->simcall.result));
-    memset(self->simcall.args, 0, sizeof(self->simcall.args));
-    self->simcall.args[0].dp = (void*) execution;
-    if (self != simix_global->maestro_process) {
-      XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name,
-                SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
-      SIMIX_process_yield(self);
-    } else {
-      SIMIX_simcall_handle(&self->simcall, 0);
-    }    
-    
-  }
-  
 inline static void simcall_BODY_execution_cancel(smx_synchro_t execution) {
     smx_process_t self = SIMIX_process_self();
 
index 42156ce..5185e8e 100644 (file)
@@ -35,7 +35,6 @@ typedef enum {
   SIMCALL_PROCESS_SLEEP,
   SIMCALL_EXECUTION_START,
   SIMCALL_EXECUTION_PARALLEL_START,
-  SIMCALL_EXECUTION_DESTROY,
   SIMCALL_EXECUTION_CANCEL,
   SIMCALL_EXECUTION_SET_PRIORITY,
   SIMCALL_EXECUTION_SET_BOUND,
index 23d99fd..c572811 100644 (file)
@@ -40,7 +40,6 @@ const char* simcall_names[] = {
   "SIMCALL_PROCESS_SLEEP",
   "SIMCALL_EXECUTION_START",
   "SIMCALL_EXECUTION_PARALLEL_START",
-  "SIMCALL_EXECUTION_DESTROY",
   "SIMCALL_EXECUTION_CANCEL",
   "SIMCALL_EXECUTION_SET_PRIORITY",
   "SIMCALL_EXECUTION_SET_BOUND",
@@ -187,11 +186,6 @@ case SIMCALL_EXECUTION_PARALLEL_START:
       SIMIX_simcall_answer(simcall);
       break;  
 
-case SIMCALL_EXECUTION_DESTROY:
-       SIMIX_execution_destroy((smx_synchro_t) simcall->args[0].dp);
-      SIMIX_simcall_answer(simcall);
-      break;  
-
 case SIMCALL_EXECUTION_CANCEL:
        SIMIX_execution_cancel((smx_synchro_t) simcall->args[0].dp);
       SIMIX_simcall_answer(simcall);
index 3dd9ca7..e867deb 100644 (file)
@@ -65,7 +65,6 @@ Blck H process_sleep (int) (duration, double)
 
 Func H execution_start (void*, smx_synchro_t) (name, const char*) (flops_amount, double) (priority, double) (bound, double) (affinity_mask, unsigned long)
 Func - execution_parallel_start (void*, smx_synchro_t) (name, const char*) (host_nb, int) (host_list, void*, sg_host_t*) (flops_amount, void*, double*) (bytes_amount, void*, double*) (amount, double) (rate, double)
-Proc - execution_destroy (void) (execution, void*, smx_synchro_t)
 Proc - execution_cancel (void) (execution, void*, smx_synchro_t)
 Proc - execution_set_priority (void) (execution, void*, smx_synchro_t) (priority, double)
 Proc - execution_set_bound (void) (execution, void*, smx_synchro_t) (bound, double)
index 4b4b325..79630cc 100644 (file)
@@ -16,7 +16,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts");
 
-static void SIMIX_execution_finish(smx_synchro_t synchro);
+static void SIMIX_execution_finish(simgrid::simix::Exec *exec);
 
 /**
  * \brief Internal function to create a SIMIX host.
@@ -332,18 +332,6 @@ smx_synchro_t SIMIX_execution_parallel_start(const char *name,
   return exec;
 }
 
-void SIMIX_execution_destroy(smx_synchro_t synchro)
-{
-  XBT_DEBUG("Destroy synchro %p", synchro);
-  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
-
-  if (exec->surf_exec) {
-    exec->surf_exec->unref();
-    exec->surf_exec = NULL;
-  }
-  delete exec;
-}
-
 void SIMIX_execution_cancel(smx_synchro_t synchro)
 {
   XBT_DEBUG("Cancel synchro %p", synchro);
@@ -379,7 +367,7 @@ void SIMIX_execution_set_affinity(smx_synchro_t synchro, sg_host_t host, unsigne
 
 void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro)
 {
-
+  simgrid::simix::Exec *exec = static_cast<simgrid::simix::Exec *>(synchro);
   XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state);
 
   /* Associate this simcall to the synchro */
@@ -389,13 +377,13 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro
   /* set surf's synchro */
   if (MC_is_active() || MC_record_replay_is_active()) {
     synchro->state = SIMIX_DONE;
-    SIMIX_execution_finish(synchro);
+    SIMIX_execution_finish(exec);
     return;
   }
 
   /* If the synchro is already finished then perform the error handling */
   if (synchro->state != SIMIX_RUNNING)
-    SIMIX_execution_finish(synchro);
+    SIMIX_execution_finish(exec);
 }
 
 void SIMIX_execution_suspend(smx_synchro_t synchro)
@@ -408,14 +396,14 @@ void SIMIX_execution_resume(smx_synchro_t synchro)
   synchro->resume(); // FIXME: USELESS
 }
 
-void SIMIX_execution_finish(smx_synchro_t synchro)
+void SIMIX_execution_finish(simgrid::simix::Exec *exec)
 {
   xbt_fifo_item_t item;
   smx_simcall_t simcall;
 
-  xbt_fifo_foreach(synchro->simcalls, item, simcall, smx_simcall_t) {
+  xbt_fifo_foreach(exec->simcalls, item, simcall, smx_simcall_t) {
 
-    switch (synchro->state) {
+    switch (exec->state) {
 
       case SIMIX_DONE:
         /* do nothing, synchro done */
@@ -435,37 +423,34 @@ void SIMIX_execution_finish(smx_synchro_t synchro)
 
       default:
         xbt_die("Internal error in SIMIX_execution_finish: unexpected synchro state %d",
-            (int)synchro->state);
+            (int)exec->state);
     }
-    /* check if the host is down */
-    if (simcall->issuer->host->isOff()) {
+    /* Fail the process if the host is down */
+    if (simcall->issuer->host->isOff())
       simcall->issuer->context->iwannadie = 1;
-    }
 
-    simcall->issuer->waiting_synchro =    NULL;
-    simcall_execution_wait__set__result(simcall, synchro->state);
+    simcall->issuer->waiting_synchro = NULL;
+    simcall_execution_wait__set__result(simcall, exec->state);
     SIMIX_simcall_answer(simcall);
   }
 
   /* We no longer need it */
-  SIMIX_execution_destroy(synchro);
+  exec->unref();
 }
 
 
-void SIMIX_post_host_execute(smx_synchro_t synchro)
+void SIMIX_post_host_execute(simgrid::simix::Exec *exec)
 {
-  simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec *>(synchro);
-
   if (exec != nullptr && exec->host && /* FIMXE: handle resource failure for parallel tasks too */
       exec->host->isOff()) {
     /* If the host running the synchro failed, notice it. This way, the asking
      * process can be killed if it runs on that host itself */
-    synchro->state = SIMIX_FAILED;
+    exec->state = SIMIX_FAILED;
   } else if (exec->surf_exec->getState() == simgrid::surf::Action::State::failed) {
     /* If the host running the synchro didn't fail, then the synchro was canceled */
-    synchro->state = SIMIX_CANCELED;
+    exec->state = SIMIX_CANCELED;
   } else {
-    synchro->state = SIMIX_DONE;
+    exec->state = SIMIX_DONE;
   }
 
   if (exec != nullptr && exec->surf_exec) {
@@ -474,9 +459,8 @@ void SIMIX_post_host_execute(smx_synchro_t synchro)
   }
 
   /* If there are simcalls associated with the synchro, then answer them */
-  if (xbt_fifo_size(synchro->simcalls)) {
-    SIMIX_execution_finish(synchro);
-  }
+  if (xbt_fifo_size(exec->simcalls))
+    SIMIX_execution_finish(exec);
 }
 
 
index 312e5bd..2981202 100644 (file)
@@ -12,6 +12,8 @@
 #include "simgrid/simix.h"
 #include "popping_private.h"
 
+#include "src/simix/SynchroExec.hpp"
+
 SG_BEGIN_DECL()
 
 /** @brief Host datatype from SIMIX POV */
@@ -43,7 +45,6 @@ XBT_PRIVATE smx_synchro_t SIMIX_execution_parallel_start(const char *name,
     int host_nb, sg_host_t *host_list,
     double *flops_amount, double *bytes_amount,
     double amount, double rate);
-XBT_PRIVATE void SIMIX_execution_destroy(smx_synchro_t synchro);
 XBT_PRIVATE void SIMIX_execution_cancel(smx_synchro_t synchro);
 XBT_PRIVATE void SIMIX_execution_set_priority(smx_synchro_t synchro, double priority);
 XBT_PRIVATE void SIMIX_execution_set_bound(smx_synchro_t synchro, double bound);
@@ -52,7 +53,7 @@ XBT_PRIVATE void SIMIX_execution_set_affinity(smx_synchro_t synchro, sg_host_t h
 XBT_PRIVATE void SIMIX_execution_suspend(smx_synchro_t synchro);
 XBT_PRIVATE void SIMIX_execution_resume(smx_synchro_t synchro);
 
-XBT_PRIVATE void SIMIX_post_host_execute(smx_synchro_t synchro);
+XBT_PRIVATE void SIMIX_post_host_execute(simgrid::simix::Exec *exec);
 XBT_PRIVATE void SIMIX_set_category(smx_synchro_t synchro, const char *category);
 
 /* vm related stuff */
index 95e411c..b6c82b2 100644 (file)
@@ -502,7 +502,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
     simgrid::simix::Io *io = dynamic_cast<simgrid::simix::Io*>(process->waiting_synchro);
 
     if (exec != nullptr) {
-      SIMIX_execution_destroy(process->waiting_synchro);
+      exec->unref();
 
     } else if (comm != nullptr) {
       xbt_fifo_remove(process->comms, process->waiting_synchro);