From: Martin Quinson Date: Mon, 9 May 2016 19:53:05 +0000 (+0200) Subject: simcall_execution_destroy() -> simgrid::simix::Exec::unref() X-Git-Tag: v3_14~1249 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f748ce48955ffc37989647090ef5b5a6676b7cd1 simcall_execution_destroy() -> simgrid::simix::Exec::unref() Plus cosmetics on my way. --- diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 77aeb08b08..59b4c3da9a 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -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); diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 4910856980..a3b6d203ee 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -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); diff --git a/src/simix/SynchroExec.cpp b/src/simix/SynchroExec.cpp index 6dfa770f56..02ce12513a 100644 --- a/src/simix/SynchroExec.cpp +++ b/src/simix/SynchroExec.cpp @@ -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; +} diff --git a/src/simix/SynchroExec.hpp b/src/simix/SynchroExec.hpp index d24af4fde5..7466a86425 100644 --- a/src/simix/SynchroExec.hpp +++ b/src/simix/SynchroExec.hpp @@ -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 diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index fe211b6c81..bbea457dd7 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -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. diff --git a/src/simix/popping.cpp b/src/simix/popping.cpp index e4a621b274..e8c8e5f3ff 100644 --- a/src/simix/popping.cpp +++ b/src/simix/popping.cpp @@ -39,7 +39,7 @@ void SIMIX_simcall_exit(smx_synchro_t synchro) { simgrid::simix::Exec *exec = dynamic_cast(synchro); if (exec != nullptr) { - SIMIX_post_host_execute(synchro); + SIMIX_post_host_execute(exec); return; } diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index f59b4b1395..f5f1a3fdca 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -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; } diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 04cf2e50db..b872bbbf8c 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -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(); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 42156cebe5..5185e8e705 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -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, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 23d99fd7ba..c572811aad 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -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); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 3dd9ca7cb2..e867deba46 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -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) diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 4b4b3255e6..79630cc59b 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -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(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(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(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); } diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 312e5bd76b..29812023aa 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -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 */ diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 95e411c706..b6c82b29f4 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -502,7 +502,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { simgrid::simix::Io *io = dynamic_cast(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);