Plus cosmetics on my way.
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);
*/
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) {
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);
return 0;
}
+
+void simgrid::simix::Exec::unref()
+{
+ refcount--;
+ if (refcount > 0)
+ return;
+
+ if (surf_exec)
+ surf_exec->unref();
+
+ delete this;
+}
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
}
-/**
- * \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.
{
simgrid::simix::Exec *exec = dynamic_cast<simgrid::simix::Exec*>(synchro);
if (exec != nullptr) {
- SIMIX_post_host_execute(synchro);
+ SIMIX_post_host_execute(exec);
return;
}
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;
}
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();
SIMCALL_PROCESS_SLEEP,
SIMCALL_EXECUTION_START,
SIMCALL_EXECUTION_PARALLEL_START,
- SIMCALL_EXECUTION_DESTROY,
SIMCALL_EXECUTION_CANCEL,
SIMCALL_EXECUTION_SET_PRIORITY,
SIMCALL_EXECUTION_SET_BOUND,
"SIMCALL_PROCESS_SLEEP",
"SIMCALL_EXECUTION_START",
"SIMCALL_EXECUTION_PARALLEL_START",
- "SIMCALL_EXECUTION_DESTROY",
"SIMCALL_EXECUTION_CANCEL",
"SIMCALL_EXECUTION_SET_PRIORITY",
"SIMCALL_EXECUTION_SET_BOUND",
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);
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)
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.
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);
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 */
/* 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)
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 */
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) {
}
/* 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);
}
#include "simgrid/simix.h"
#include "popping_private.h"
+#include "src/simix/SynchroExec.hpp"
+
SG_BEGIN_DECL()
/** @brief Host datatype from SIMIX POV */
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);
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 */
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);