From: Martin Quinson Date: Sat, 7 May 2016 20:56:55 +0000 (+0200) Subject: SIMIX_comm_cancel() -> simix::Comm->cancel() X-Git-Tag: v3_14~1261 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e49a7949060118737703106058657735cf3892d6?ds=sidebyside SIMIX_comm_cancel() -> simix::Comm->cancel() --- diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp index 27ac085cba..69eca5dca4 100644 --- a/src/simix/SynchroComm.cpp +++ b/src/simix/SynchroComm.cpp @@ -5,6 +5,10 @@ #include "src/simix/SynchroComm.hpp" #include "src/surf/surf_interface.hpp" +#include "src/simix/smx_network_private.h" +#include "simgrid/modelchecker.h" +#include "src/mc/mc_replay.h" + void simgrid::simix::Comm::suspend() { /* FIXME: shall we suspend also the timeout synchro? */ @@ -20,3 +24,18 @@ void simgrid::simix::Comm::resume() { surf_comm->resume(); /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */ } + +void simgrid::simix::Comm::cancel() { + /* if the synchro is a waiting state means that it is still in a mbox */ + /* so remove from it and delete it */ + if (state == SIMIX_WAITING) { + SIMIX_mbox_remove(mbox, this); + state = SIMIX_CANCELED; + } + else if (!MC_is_active() /* when running the MC there are no surf actions */ + && !MC_record_replay_is_active() + && (state == SIMIX_READY || state == SIMIX_RUNNING)) { + + surf_comm->cancel(); + } +} diff --git a/src/simix/SynchroComm.hpp b/src/simix/SynchroComm.hpp index 58e0466c38..68a21e88b9 100644 --- a/src/simix/SynchroComm.hpp +++ b/src/simix/SynchroComm.hpp @@ -23,6 +23,7 @@ namespace simix { public: void suspend(); void resume(); + void cancel(); e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */ smx_mailbox_t mbox; /* Rendez-vous where the comm is queued */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 3b36d09a14..883d2c7f97 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -22,6 +22,8 @@ #include "mc/mc.h" #include "src/simix/smx_host_private.h" +#include "src/simix/SynchroComm.hpp" + #include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix); @@ -827,9 +829,12 @@ smx_synchro_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag /** * \ingroup simix_comm_management */ -void simcall_comm_cancel(smx_synchro_t comm) +void simcall_comm_cancel(smx_synchro_t synchro) { - simcall_BODY_comm_cancel(comm); + simgrid::simix::kernel([synchro]{ + simgrid::simix::Comm *comm = static_cast(synchro); + comm->cancel(); + }); } /** diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index d98bbc2a91..e336da996c 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -771,13 +771,6 @@ static inline void simcall_comm_irecv__set__result(smx_simcall_t simcall, void* simcall->result.dp = result; } -static inline smx_synchro_t simcall_comm_cancel__get__comm(smx_simcall_t simcall) { - return (smx_synchro_t) simcall->args[0].dp; -} -static inline void simcall_comm_cancel__set__comm(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline xbt_dynar_t simcall_comm_waitany__get__comms(smx_simcall_t simcall) { return (xbt_dynar_t) simcall->args[0].dp; } diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index ffb3331c43..b7d5be4088 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -862,27 +862,6 @@ inline static smx_synchro_t simcall_BODY_comm_irecv(smx_process_t receiver, smx_ return (smx_synchro_t) self->simcall.result.dp; } -inline static void simcall_BODY_comm_cancel(smx_synchro_t comm) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_comm_cancel(comm); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_COMM_CANCEL; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) comm; - 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 int simcall_BODY_comm_waitany(xbt_dynar_t comms) { smx_process_t self = SIMIX_process_self(); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index cbac010c0b..3ad74e6647 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -55,7 +55,6 @@ typedef enum { SIMCALL_COMM_ISEND, SIMCALL_COMM_RECV, SIMCALL_COMM_IRECV, - SIMCALL_COMM_CANCEL, SIMCALL_COMM_WAITANY, SIMCALL_COMM_WAIT, SIMCALL_COMM_TEST, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 1d8618988a..c5803664a6 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -60,7 +60,6 @@ const char* simcall_names[] = { "SIMCALL_COMM_ISEND", "SIMCALL_COMM_RECV", "SIMCALL_COMM_IRECV", - "SIMCALL_COMM_CANCEL", "SIMCALL_COMM_WAITANY", "SIMCALL_COMM_WAIT", "SIMCALL_COMM_TEST", @@ -294,11 +293,6 @@ case SIMCALL_COMM_IRECV: SIMIX_simcall_answer(simcall); break; -case SIMCALL_COMM_CANCEL: - SIMIX_comm_cancel((smx_synchro_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_COMM_WAITANY: simcall_HANDLER_comm_waitany(simcall , (xbt_dynar_t) simcall->args[0].dp); break; diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index aaabae51aa..e75dd4eb23 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -88,7 +88,6 @@ Blck H comm_send (void) (sender, void*, smx_process_t) (mbox, v Func H comm_isend (void*, smx_synchro_t) (sender, void*, smx_process_t) (mbox, void*, smx_mailbox_t) (task_size, double) (rate, double) (src_buff, void*) (src_buff_size, size_t) (match_fun, FPtr, simix_match_func_t) (clean_fun, FPtr, simix_clean_func_t) (copy_data_fun, FPtr, simix_copy_data_func_t) (data, void*) (detached, int) Blck H comm_recv (void) (receiver, void*, smx_process_t) (mbox, void*, smx_mailbox_t) (dst_buff, void*) (dst_buff_size, void*, size_t*) (match_fun, FPtr, simix_match_func_t) (copy_data_fun, FPtr, simix_copy_data_func_t) (data, void*) (timeout, double) (rate, double) Func H comm_irecv (void*, smx_synchro_t) (receiver, void*, smx_process_t) (mbox, void*, smx_mailbox_t) (dst_buff, void*) (dst_buff_size, void*, size_t*) (match_fun, FPtr, simix_match_func_t) (copy_data_fun, FPtr, simix_copy_data_func_t) (data, void*) (rate, double) -Proc - comm_cancel (void) (comm, void*, smx_synchro_t) Blck H comm_waitany (int) (comms, void*, xbt_dynar_t) Blck H comm_wait (void) (comm, void*, smx_synchro_t) (timeout, double) Blck H comm_test (int) (comm, void*, smx_synchro_t) diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index f913e7f628..fa759cb61c 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -833,24 +833,6 @@ void SIMIX_post_comm(smx_synchro_t synchro) } } -void SIMIX_comm_cancel(smx_synchro_t synchro) -{ - simgrid::simix::Comm *comm = static_cast(synchro); - - /* if the synchro is a waiting state means that it is still in a mbox */ - /* so remove from it and delete it */ - if (comm->state == SIMIX_WAITING) { - SIMIX_mbox_remove(comm->mbox, synchro); - comm->state = SIMIX_CANCELED; - } - else if (!MC_is_active() /* when running the MC there are no surf actions */ - && !MC_record_replay_is_active() - && (comm->state == SIMIX_READY || comm->state == SIMIX_RUNNING)) { - - comm->surf_comm->cancel(); - } -} - /************* synchro Getters **************/ /** diff --git a/src/simix/smx_network_private.h b/src/simix/smx_network_private.h index f888ce29c1..965bf7722a 100644 --- a/src/simix/smx_network_private.h +++ b/src/simix/smx_network_private.h @@ -39,7 +39,6 @@ XBT_PRIVATE void SIMIX_comm_destroy_internal_actions(smx_synchro_t synchro); XBT_PRIVATE smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int type, int src, int tag, int (*match_fun)(void *, void *, smx_synchro_t), void *data); XBT_PRIVATE void SIMIX_post_comm(smx_synchro_t synchro); -XBT_PRIVATE void SIMIX_comm_cancel(smx_synchro_t synchro); XBT_PRIVATE double SIMIX_comm_get_remains(smx_synchro_t synchro); XBT_PRIVATE e_smx_state_t SIMIX_comm_get_state(smx_synchro_t synchro); XBT_PRIVATE smx_process_t SIMIX_comm_get_src_proc(smx_synchro_t synchro); diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 450d081107..1bd0a3b6a1 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -72,7 +72,7 @@ void SIMIX_process_cleanup(smx_process_t process) /* make sure no one will finish the comm after this process is destroyed, * because src_proc or dst_proc would be an invalid pointer */ - SIMIX_comm_cancel(comm); + comm->cancel(); if (comm->src_proc == process) { XBT_DEBUG("Found an unfinished send comm %p (detached = %d), state %d, src = %p, dst = %p", @@ -506,7 +506,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) { } else if (comm != nullptr) { xbt_fifo_remove(process->comms, process->waiting_synchro); - SIMIX_comm_cancel(process->waiting_synchro); + comm->cancel(); xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall); SIMIX_comm_destroy(process->waiting_synchro); @@ -559,8 +559,8 @@ void SIMIX_process_throw(smx_process_t process, xbt_errcat_t cat, int value, con simgrid::simix::Comm *comm = dynamic_cast(process->waiting_synchro); if (comm != nullptr) { - xbt_fifo_remove(process->comms, process->waiting_synchro); - SIMIX_comm_cancel(process->waiting_synchro); + xbt_fifo_remove(process->comms, comm); + comm->cancel(); } simgrid::simix::Sleep *sleep = dynamic_cast(process->waiting_synchro);