From: adfaure Date: Thu, 21 Jul 2016 07:48:33 +0000 (+0200) Subject: [SIMIX]add timeout to simcall_comm_waitany X-Git-Tag: v3_14~729^2^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/252e94ece72d34b22cb9343b13e7869d47ce48f2 [SIMIX]add timeout to simcall_comm_waitany --- diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d9b6007c41..dd789b2c3e 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -359,7 +359,7 @@ XBT_PUBLIC(smx_synchro_t) simcall_comm_iprobe(smx_mailbox_t mbox, int type, int XBT_PUBLIC(void) simcall_comm_cancel(smx_synchro_t comm); /* FIXME: waitany is going to be a vararg function, and should take a timeout */ -XBT_PUBLIC(unsigned int) simcall_comm_waitany(xbt_dynar_t comms); +XBT_PUBLIC(unsigned int) simcall_comm_waitany(xbt_dynar_t comms, double timeout); XBT_PUBLIC(void) simcall_comm_wait(smx_synchro_t comm, double timeout); XBT_PUBLIC(int) simcall_comm_test(smx_synchro_t comm); XBT_PUBLIC(int) simcall_comm_testany(xbt_dynar_t comms); diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 9e0378e805..0ec8312b71 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -627,7 +627,7 @@ int MSG_comm_waitany(xbt_dynar_t comms) msg_error_t status = MSG_OK; try { - finished_index = simcall_comm_waitany(s_comms); + finished_index = simcall_comm_waitany(s_comms, -1); } catch(xbt_ex& e) { switch (e.category) { diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 8f41f627b8..2742d6d324 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -765,9 +765,9 @@ void simcall_comm_cancel(smx_synchro_t synchro) /** * \ingroup simix_comm_management */ -unsigned int simcall_comm_waitany(xbt_dynar_t comms) +unsigned int simcall_comm_waitany(xbt_dynar_t comms, double timeout) { - return simcall_BODY_comm_waitany(comms); + return simcall_BODY_comm_waitany(comms, timeout); } /** diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 32e906ec8f..e74bb3b4e9 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -657,6 +657,12 @@ static inline xbt_dynar_t simcall_comm_waitany__get__comms(smx_simcall_t simcall static inline void simcall_comm_waitany__set__comms(smx_simcall_t simcall, xbt_dynar_t arg) { simgrid::simix::marshal(simcall->args[0], arg); } +static inline double simcall_comm_waitany__get__timeout(smx_simcall_t simcall) { + return simgrid::simix::unmarshal(simcall->args[1]); +} +static inline void simcall_comm_waitany__set__timeout(smx_simcall_t simcall, double arg) { + simgrid::simix::marshal(simcall->args[1], arg); +} static inline int simcall_comm_waitany__get__result(smx_simcall_t simcall){ return simgrid::simix::unmarshal(simcall->result); } @@ -1179,7 +1185,7 @@ XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_process_t XBT_PRIVATE smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_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); XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_process_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout, double rate); XBT_PRIVATE smx_synchro_t simcall_HANDLER_comm_irecv(smx_simcall_t simcall, smx_process_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double rate); -XBT_PRIVATE void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t comms); +XBT_PRIVATE void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t comms, double timeout); XBT_PRIVATE void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t comm, double timeout); XBT_PRIVATE void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t comm); XBT_PRIVATE void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t comms); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index ba83d704e2..e1cbb57b33 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -221,10 +221,10 @@ inline static smx_synchro_t simcall_BODY_comm_irecv(smx_process_t receiver, smx_ return simcall(SIMCALL_COMM_IRECV, receiver, mbox, dst_buff, dst_buff_size, match_fun, copy_data_fun, data, rate); } -inline static int simcall_BODY_comm_waitany(xbt_dynar_t comms) { +inline static int simcall_BODY_comm_waitany(xbt_dynar_t comms, double timeout) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_comm_waitany(&SIMIX_process_self()->simcall, comms); - return simcall(SIMCALL_COMM_WAITANY, comms); + if (0) simcall_HANDLER_comm_waitany(&SIMIX_process_self()->simcall, comms, timeout); + return simcall(SIMCALL_COMM_WAITANY, comms, timeout); } inline static void simcall_BODY_comm_wait(smx_synchro_t comm, double timeout) { diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 1ba87540ed..226dc13059 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -254,7 +254,7 @@ case SIMCALL_COMM_IRECV: break; case SIMCALL_COMM_WAITANY: - simcall_HANDLER_comm_waitany(simcall, simgrid::simix::unmarshal(simcall->args[0])); + simcall_HANDLER_comm_waitany(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); break; case SIMCALL_COMM_WAIT: diff --git a/src/simix/popping_private.h b/src/simix/popping_private.h index d6a3a57115..d532dbd5b8 100644 --- a/src/simix/popping_private.h +++ b/src/simix/popping_private.h @@ -45,6 +45,7 @@ union u_smx_scalar { struct s_smx_simcall { e_smx_simcall_t call; smx_process_t issuer; + smx_timer_t timer; int mc_value; union u_smx_scalar args[11]; union u_smx_scalar result; diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 55858b21f1..185f440048 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -72,7 +72,7 @@ void comm_send(smx_process_t sender, smx_mailbox_t mbox, double task_si smx_synchro_t comm_isend(smx_process_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); void comm_recv(smx_process_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout, double rate) [[block]]; smx_synchro_t comm_irecv(smx_process_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double rate); -int comm_waitany(xbt_dynar_t comms) [[block]]; +int comm_waitany(xbt_dynar_t comms, double timeout) [[block]]; void comm_wait(smx_synchro_t comm, double timeout) [[block]]; int comm_test(smx_synchro_t comm) [[block]]; int comm_testany(xbt_dynar_t comms) [[block]]; diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index db3b4fde80..9810cbf2a5 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -476,12 +476,14 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) SIMIX_simcall_answer(simcall); } -void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros) +void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros, double timeout) { smx_synchro_t synchro; unsigned int cursor = 0; if (MC_is_active() || MC_record_replay_is_active()){ + if (timeout != -1) + xbt_die("Timeout not implemented for waitany in the model-checker"); int idx = SIMCALL_GET_MC_VALUE(simcall); synchro = xbt_dynar_get_as(synchros, idx, smx_synchro_t); synchro->simcalls.push_back(simcall); @@ -490,7 +492,17 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t synchros) SIMIX_comm_finish(synchro); return; } - + + if (timeout == -1 ){ + simcall->timer = NULL; + } else { + simcall->timer = SIMIX_timer_set(timeout, [simcall]() { + SIMIX_waitany_remove_simcall_from_actions(simcall); + simcall_comm_waitany__set__result(simcall, -1); + SIMIX_simcall_answer(simcall); + }); + } + xbt_dynar_foreach(synchros, cursor, synchro){ /* associate this simcall to the the synchro */ synchro->simcalls.push_back(simcall); @@ -582,6 +594,8 @@ void SIMIX_comm_finish(smx_synchro_t synchro) continue; // if process handling comm is killed if (simcall->call == SIMCALL_COMM_WAITANY) { SIMIX_waitany_remove_simcall_from_actions(simcall); + if (simcall->timer) + SIMIX_timer_remove(simcall->timer); if (!MC_is_active() && !MC_record_replay_is_active()) simcall_comm_waitany__set__result(simcall, xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro)); } diff --git a/src/smpi/smpi_base.cpp b/src/smpi/smpi_base.cpp index 0170851808..3a987711f9 100644 --- a/src/smpi/smpi_base.cpp +++ b/src/smpi/smpi_base.cpp @@ -945,7 +945,7 @@ int smpi_mpi_waitany(int count, MPI_Request requests[], MPI_Status * status) } } if(size > 0) { - i = simcall_comm_waitany(comms); + i = simcall_comm_waitany(comms, -1); // not MPI_UNDEFINED, as this is a simix return code if (i != -1) {