From: Martin Quinson Date: Sun, 26 Apr 2015 21:39:35 +0000 (+0200) Subject: Remove the kill_time timer when a process stops (fix #18888) X-Git-Tag: v3_12~732^2~50^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9bd89d253a72967d4bb3c041c5fb5df8b210a556 Remove the kill_time timer when a process stops (fix #18888) --- diff --git a/ChangeLog b/ChangeLog index af38a7ee48..455983dd86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,8 @@ SimGrid (3.12) NOT RELEASED; urgency=low For example, a communication is a sort of synchronization involving the communicating processes (that may block until the exchange) and the platform. The same can be said from computations, etc. + * Bug fixes: + - #18888: segfault when a process ends before its kill_time SMPI: * New functions diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index a79adf3726..ba20c93bfc 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -52,8 +52,6 @@ typedef enum { } e_smx_state_t; /** @} */ -typedef struct s_smx_timer* smx_timer_t; - /* ******************************** Synchro ************************************ */ /** * \ingroup simix_synchro_management @@ -235,8 +233,12 @@ XBT_PUBLIC(void) SIMIX_run(void); XBT_PUBLIC(double) SIMIX_get_clock(void); /* Timer functions FIXME: should these be public? */ -XBT_PUBLIC(void) SIMIX_timer_set(double date, void *function, void *arg); +typedef struct s_smx_timer* smx_timer_t; + +XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, void *function, void *arg); +XBT_PUBLIC(void) SIMIX_timer_remove(smx_timer_t timer); XBT_PUBLIC(double) SIMIX_timer_next(void); +XBT_PUBLIC(double) SIMIX_timer_get_date(smx_timer_t timer); XBT_PUBLIC(void) SIMIX_display_process_status(void); diff --git a/src/simix/libsmx.c b/src/simix/libsmx.c index 35b3c8ec62..f604cec2fd 100644 --- a/src/simix/libsmx.c +++ b/src/simix/libsmx.c @@ -737,7 +737,7 @@ void simcall_process_set_kill_time(smx_process_t process, double kill_time) if (simix_global->kill_process_function) { XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name, sg_host_name(process->smx_host)); - SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); + process->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); } } } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 0011f977f2..2689131134 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -516,7 +516,7 @@ void SIMIX_run(void) * \param arg Parameters of the function * */ -XBT_INLINE void SIMIX_timer_set(double date, void *function, void *arg) +XBT_INLINE smx_timer_t SIMIX_timer_set(double date, void *function, void *arg) { smx_timer_t timer = xbt_new0(s_smx_timer_t, 1); @@ -524,6 +524,16 @@ XBT_INLINE void SIMIX_timer_set(double date, void *function, void *arg) timer->func = function; timer->args = arg; xbt_heap_push(simix_timers, timer, date); + return timer; +} +/** @brief cancels a timer that was added earlier */ +XBT_INLINE void SIMIX_timer_remove(smx_timer_t timer) { + xbt_heap_rm_elm(simix_timers, timer, timer->date); +} + +/** @brief Returns the date at which the timer will trigger (or 0 if NULL timer) */ +XBT_INLINE double SIMIX_timer_get_date(smx_timer_t timer) { + return timer?timer->date:0; } /** diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 8fa3c6b8da..d466c2c9d6 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -49,6 +49,10 @@ void SIMIX_process_cleanup(smx_process_t process) SIMIX_process_on_exit_runall(process); + /* Unregister from the kill timer if any */ + if (process->kill_timer != NULL) + SIMIX_timer_remove(process->kill_timer); + /* cancel non-blocking communications */ smx_synchro_t synchro; while ((synchro = xbt_fifo_pop(process->comms))) { @@ -157,7 +161,7 @@ void SIMIX_process_stop(smx_process_t arg) { if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) { SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data, sg_host_name(arg->smx_host), - arg->kill_time, + SIMIX_timer_get_date(arg->kill_timer), arg->argc,arg->argv,arg->properties, arg->auto_restart); } @@ -260,7 +264,6 @@ void SIMIX_process_create(smx_process_t *process, (*process)->code = code; (*process)->argc = argc; (*process)->argv = argv; - (*process)->kill_time = kill_time; XBT_VERB("Create context %s", (*process)->name); @@ -290,7 +293,7 @@ void SIMIX_process_create(smx_process_t *process, if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) { XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name, sg_host_name((*process)->smx_host), kill_time); - SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process); + (*process)->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process); } } } @@ -952,18 +955,15 @@ void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart) { smx_process_t simcall_HANDLER_process_restart(smx_simcall_t simcall, smx_process_t process) { return SIMIX_process_restart(process, simcall->issuer); } -/** - * \brief Restart a process. - * Restart a process, starting it again from the beginning. - */ +/** @brief Restart a process, starting it again from the beginning. */ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) { XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_name(process->smx_host)); //retrieve the arguments of the old process - //FIXME: Factorise this with SIMIX_host_add_auto_restart_process ? + //FIXME: Factorize this with SIMIX_host_add_auto_restart_process ? s_smx_process_arg_t arg; arg.code = process->code; arg.hostname = sg_host_name(process->smx_host); - arg.kill_time = process->kill_time; + arg.kill_time = SIMIX_timer_get_date(process->kill_timer); arg.argc = process->argc; arg.data = process->data; int i; diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 8b4f8ed9ba..b3cd4bcede 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -58,8 +58,7 @@ typedef struct s_smx_process { xbt_main_func_t code; int argc; char **argv; - double kill_time; - + smx_timer_t kill_timer; } s_smx_process_t;