From: Frederic Suter Date: Mon, 11 Dec 2017 14:21:11 +0000 (+0100) Subject: add test() for asynchronous executions X-Git-Tag: v3.18~50 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cc4ca208c5e056ac569cd07e08f09a416f3606fe add test() for asynchronous executions very inspired by that for comms and use it in exec-monitor --- diff --git a/examples/s4u/exec-monitor/s4u-exec-monitor.cpp b/examples/s4u/exec-monitor/s4u-exec-monitor.cpp index 88e51ce97c..535f2fb23b 100644 --- a/examples/s4u/exec-monitor/s4u-exec-monitor.cpp +++ b/examples/s4u/exec-monitor/s4u-exec-monitor.cpp @@ -12,7 +12,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example") static void monitor(simgrid::s4u::ExecPtr activity) { - while (activity->getRemains() > 0) { // FIXME: use a test() here once that function is implemented + while (not activity->test()) { XBT_INFO("activity remaining duration: %g (%.0f%%)", activity->getRemains(), 100 * activity->getRemainingRatio()); simgrid::s4u::this_actor::sleep_for(5); } diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index ba24e6824d..5acf3b829e 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -195,6 +195,7 @@ XBT_PUBLIC(void) simcall_execution_cancel(smx_activity_t execution); XBT_PUBLIC(void) simcall_execution_set_priority(smx_activity_t execution, double priority); XBT_PUBLIC(void) simcall_execution_set_bound(smx_activity_t execution, double bound); XBT_PUBLIC(e_smx_state_t) simcall_execution_wait(smx_activity_t execution); +XBT_PUBLIC(e_smx_state_t) simcall_execution_test(smx_activity_t execution); /**************************** Process simcalls ********************************/ SG_BEGIN_DECL() diff --git a/src/s4u/s4u_exec.cpp b/src/s4u/s4u_exec.cpp index f14a4500e2..ca3623d279 100644 --- a/src/s4u/s4u_exec.cpp +++ b/src/s4u/s4u_exec.cpp @@ -41,6 +41,11 @@ bool Exec::test() this->start(); } + if (simcall_execution_test(pimpl_)) { + state_ = finished; + return true; + } + return false; } diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 9662361389..c6b6e1c78e 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -170,6 +170,11 @@ e_smx_state_t simcall_execution_wait(smx_activity_t execution) return (e_smx_state_t) simcall_BODY_execution_wait(execution); } +e_smx_state_t simcall_execution_test(smx_activity_t execution) +{ + return (e_smx_state_t)simcall_BODY_execution_test(execution); +} + /** * \ingroup simix_process_management * \brief Kills all SIMIX processes. diff --git a/src/simix/popping_accessors.hpp b/src/simix/popping_accessors.hpp index 1ec713273b..fc80fc2159 100644 --- a/src/simix/popping_accessors.hpp +++ b/src/simix/popping_accessors.hpp @@ -311,6 +311,34 @@ static inline void simcall_execution_wait__set__result(smx_simcall_t simcall, in simgrid::simix::marshal(simcall->result, result); } +static inline boost::intrusive_ptr +simcall_execution_test__get__execution(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal>(simcall->args[0]); +} +static inline simgrid::kernel::activity::ActivityImpl* simcall_execution_test__getraw__execution(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal_raw(simcall->args[0]); +} +static inline void +simcall_execution_test__set__execution(smx_simcall_t simcall, + boost::intrusive_ptr arg) +{ + simgrid::simix::marshal>(simcall->args[0], arg); +} +static inline int simcall_execution_test__get__result(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal(simcall->result); +} +static inline int simcall_execution_test__getraw__result(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal_raw(simcall->result); +} +static inline void simcall_execution_test__set__result(smx_simcall_t simcall, int result) +{ + simgrid::simix::marshal(simcall->result, result); +} + static inline smx_actor_t simcall_process_on_exit__get__process(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); @@ -1379,6 +1407,9 @@ XBT_PRIVATE boost::intrusive_ptr simcall_HANDLER_execution_start(smx_simcall_t simcall, const char* name, double flops_amount, double priority, double bound, sg_host_t host); XBT_PRIVATE void simcall_HANDLER_execution_wait(smx_simcall_t simcall, boost::intrusive_ptr execution); +XBT_PRIVATE void +simcall_HANDLER_execution_test(smx_simcall_t simcall, + boost::intrusive_ptr execution); XBT_PRIVATE boost::intrusive_ptr simcall_HANDLER_comm_iprobe(smx_simcall_t simcall, smx_mailbox_t mbox, int type, simix_match_func_t match_fun, void* data); XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_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_copy_data_func_t copy_data_fun, void* data, double timeout); XBT_PRIVATE boost::intrusive_ptr simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_actor_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); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index e464ce2267..f616cf57b7 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -94,6 +94,13 @@ inline static int simcall_BODY_execution_wait(boost::intrusive_ptr>(SIMCALL_EXECUTION_WAIT, execution); } +inline static int simcall_BODY_execution_test(boost::intrusive_ptr execution) +{ + if (0) /* Go to that function to follow the code flow through the simcall barrier */ + simcall_HANDLER_execution_test(&SIMIX_process_self()->simcall, execution); + return simcall>(SIMCALL_EXECUTION_TEST, execution); +} + inline static void simcall_BODY_process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void* data) { if (0) /* Go to that function to follow the code flow through the simcall barrier */ diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index e2a7c49e97..7d489a4156 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -27,6 +27,7 @@ typedef enum { SIMCALL_EXECUTION_START, SIMCALL_EXECUTION_PARALLEL_START, SIMCALL_EXECUTION_WAIT, + SIMCALL_EXECUTION_TEST, SIMCALL_PROCESS_ON_EXIT, SIMCALL_COMM_IPROBE, SIMCALL_COMM_SEND, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 21e72227b9..51842797b4 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -33,6 +33,7 @@ const char* simcall_names[] = { "SIMCALL_EXECUTION_START", "SIMCALL_EXECUTION_PARALLEL_START", "SIMCALL_EXECUTION_WAIT", + "SIMCALL_EXECUTION_TEST", "SIMCALL_PROCESS_ON_EXIT", "SIMCALL_COMM_IPROBE", "SIMCALL_COMM_SEND", @@ -113,6 +114,12 @@ case SIMCALL_EXECUTION_WAIT: simcall_HANDLER_execution_wait(simcall, simgrid::simix::unmarshal>(simcall->args[0])); break; +case SIMCALL_EXECUTION_TEST: + simcall_HANDLER_execution_test( + simcall, + simgrid::simix::unmarshal>(simcall->args[0])); + break; + case SIMCALL_PROCESS_ON_EXIT: SIMIX_process_on_exit(simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]), simgrid::simix::unmarshal(simcall->args[2])); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 4faaeed745..b2425c02a4 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -44,6 +44,7 @@ int process_sleep(double duration) [[block]]; boost::intrusive_ptr execution_start(const char* name, double flops_amount, double priority, double bound, sg_host_t host); boost::intrusive_ptr execution_parallel_start(const char* name, int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double rate, double timeout) [[nohandler]]; int execution_wait(boost::intrusive_ptr execution) [[block]]; +int execution_test(boost::intrusive_ptr execution) [[block]]; void process_on_exit(smx_actor_t process, int_f_pvoid_pvoid_t fun, void* data) [[nohandler]]; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index b736f17a9e..692e828540 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -222,18 +222,40 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_activity_t synchr /* set surf's synchro */ if (MC_is_active() || MC_record_replay_is_active()) { synchro->state = SIMIX_DONE; - SIMIX_execution_finish(exec); + SIMIX_execution_finish(synchro); return; } /* If the synchro is already finished then perform the error handling */ if (synchro->state != SIMIX_RUNNING) - SIMIX_execution_finish(exec); + SIMIX_execution_finish(synchro); } -void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec) +void simcall_HANDLER_execution_test(smx_simcall_t simcall, smx_activity_t synchro) { - for (smx_simcall_t const& simcall : exec->simcalls) { + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); + + simcall_execution_test__set__result(simcall, (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING)); + if (simcall_execution_test__get__result(simcall)) { + synchro->simcalls.push_back(simcall); + SIMIX_execution_finish(synchro); + } else { + SIMIX_simcall_answer(simcall); + } + /* If the synchro is already finished then perform the error handling */ + if (synchro->state != SIMIX_RUNNING) + SIMIX_execution_finish(synchro); +} + +void SIMIX_execution_finish(smx_activity_t synchro) +{ + simgrid::kernel::activity::ExecImplPtr exec = + boost::static_pointer_cast(synchro); + + while (not synchro->simcalls.empty()) { + smx_simcall_t simcall = synchro->simcalls.front(); + synchro->simcalls.pop_front(); switch (exec->state) { case SIMIX_DONE: diff --git a/src/simix/smx_host_private.hpp b/src/simix/smx_host_private.hpp index f4b6a9601f..899fab36fd 100644 --- a/src/simix/smx_host_private.hpp +++ b/src/simix/smx_host_private.hpp @@ -49,7 +49,7 @@ XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* XBT_PRIVATE void SIMIX_host_autorestart(sg_host_t host); -XBT_PRIVATE void SIMIX_execution_finish(simgrid::kernel::activity::ExecImplPtr exec); +XBT_PRIVATE void SIMIX_execution_finish(smx_activity_t synchro); XBT_PRIVATE void SIMIX_set_category(smx_activity_t synchro, const char* category); }