From a21c899e4be4bccd122de490e9aa3348e436b81f Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 13 Dec 2019 11:45:41 +0100 Subject: [PATCH] end the implementation of Io::test with a new simcall --- examples/s4u/io-async/s4u-io-async.cpp | 16 +++++++++++++++ examples/s4u/io-async/s4u-io-async.tesh | 7 ++++++- include/simgrid/simix.h | 1 + src/kernel/activity/IoImpl.cpp | 13 +++++++++++++ src/s4u/s4u_Io.cpp | 7 +++++-- src/simix/libsmx.cpp | 5 +++++ src/simix/popping_accessors.hpp | 26 +++++++++++++++++++++++++ src/simix/popping_bodies.cpp | 7 +++++++ src/simix/popping_enum.h | 1 + src/simix/popping_generated.cpp | 5 +++++ src/simix/simcalls.in | 1 + 11 files changed, 86 insertions(+), 3 deletions(-) diff --git a/examples/s4u/io-async/s4u-io-async.cpp b/examples/s4u/io-async/s4u-io-async.cpp index 8819f759aa..fe9deac0a9 100644 --- a/examples/s4u/io-async/s4u-io-async.cpp +++ b/examples/s4u/io-async/s4u-io-async.cpp @@ -48,6 +48,21 @@ static void test_cancel(sg_size_t size) XBT_INFO("Goodbye now!"); } +static void test_monitor(sg_size_t size) +{ + simgrid::s4u::Disk* disk = simgrid::s4u::Host::current()->get_disks().front(); + simgrid::s4u::this_actor::sleep_for(1); + simgrid::s4u::IoPtr activity = disk->write_async(size); + + while (not activity->test()) { + XBT_INFO("Remaining amount of bytes to write: %g", activity->get_remaining()); + simgrid::s4u::this_actor::sleep_for(0.2); + } + activity->wait(); + + XBT_INFO("Goodbye now!"); +} + int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); @@ -55,6 +70,7 @@ int main(int argc, char* argv[]) simgrid::s4u::Actor::create("test", simgrid::s4u::Host::by_name("bob"), test, 2e7); simgrid::s4u::Actor::create("test_waitfor", simgrid::s4u::Host::by_name("alice"), test_waitfor, 5e7); simgrid::s4u::Actor::create("test_cancel", simgrid::s4u::Host::by_name("alice"), test_cancel, 5e7); + simgrid::s4u::Actor::create("test_monitor", simgrid::s4u::Host::by_name("alice"), test_monitor, 5e7); e.run(); diff --git a/examples/s4u/io-async/s4u-io-async.tesh b/examples/s4u/io-async/s4u-io-async.tesh index 3b6c006543..a1ca8d7618 100644 --- a/examples/s4u/io-async/s4u-io-async.tesh +++ b/examples/s4u/io-async/s4u-io-async.tesh @@ -9,4 +9,9 @@ $ ${bindir:=.}/s4u-io-async ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%1 > [ 0.500000] (3:test_cancel@alice) Hello! write 50000000 bytes from Disk1 > [ 1.000000] (3:test_cancel@alice) I changed my mind, cancel! > [ 1.000000] (3:test_cancel@alice) Goodbye now! -> [ 1.000000] (0:maestro@) Simulation time 1 +> [ 1.000000] (4:test_monitor@alice) Remaining amount of bytes to write: 5e+07 +> [ 1.200000] (4:test_monitor@alice) Remaining amount of bytes to write: 3.4e+07 +> [ 1.400000] (4:test_monitor@alice) Remaining amount of bytes to write: 1.8e+07 +> [ 1.600000] (4:test_monitor@alice) Remaining amount of bytes to write: 2e+06 +> [ 1.800000] (4:test_monitor@alice) Goodbye now! +> [ 1.800000] (0:maestro@) Simulation time 1.8 diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index cf9e3e0afa..4adb5c061d 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -192,6 +192,7 @@ SG_END_DECL /***************************** Io **************************************/ #ifdef __cplusplus XBT_PUBLIC e_smx_state_t simcall_io_wait(const smx_activity_t& io, double timeout); +XBT_PUBLIC bool simcall_io_test(const smx_activity_t& io); #endif /************************** MC simcalls **********************************/ SG_BEGIN_DECL diff --git a/src/kernel/activity/IoImpl.cpp b/src/kernel/activity/IoImpl.cpp index 338999b786..8472157856 100644 --- a/src/kernel/activity/IoImpl.cpp +++ b/src/kernel/activity/IoImpl.cpp @@ -50,6 +50,19 @@ void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::I } } +void simcall_HANDLER_io_test(smx_simcall_t simcall, simgrid::kernel::activity::IoImpl* synchro) +{ + bool res = (synchro->state_ != simgrid::kernel::activity::State::WAITING && + synchro->state_ != simgrid::kernel::activity::State::RUNNING); + if (res) { + synchro->simcalls_.push_back(simcall); + synchro->finish(); + } else { + simcall->issuer_->simcall_answer(); + } + simcall_io_test__set__result(simcall, res); +} + namespace simgrid { namespace kernel { namespace activity { diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index d02bce14a7..a95426b44a 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -76,9 +76,12 @@ bool Io::test() if (state_ == State::INITED) this->start(); - THROW_UNIMPLEMENTED; + if (simcall_io_test(pimpl_)) { + state_ = State::FINISHED; + return true; + } - // return false + return false; } /** @brief Returns the amount of flops that remain to be done */ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 5cc3f8c8e5..42988e9c0e 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -308,6 +308,11 @@ e_smx_state_t simcall_io_wait(const smx_activity_t& io, double timeout) return (e_smx_state_t)simcall_BODY_io_wait(static_cast(io.get()), timeout); } +bool simcall_io_test(const smx_activity_t& io) +{ + return simcall_BODY_io_test(static_cast(io.get())); +} + void simcall_run_kernel(std::function const& code, simgrid::mc::SimcallInspector* t) { simgrid::kernel::actor::ActorImpl::self()->simcall.inspector_ = t; diff --git a/src/simix/popping_accessors.hpp b/src/simix/popping_accessors.hpp index a3c8dd01a6..792fcb93f3 100644 --- a/src/simix/popping_accessors.hpp +++ b/src/simix/popping_accessors.hpp @@ -958,6 +958,31 @@ static inline void simcall_io_wait__set__result(smx_simcall_t simcall, sg_size_t simgrid::simix::marshal(simcall->result_, result); } +static inline simgrid::kernel::activity::IoImpl* simcall_io_test__get__io(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal(simcall->args_[0]); +} +static inline simgrid::kernel::activity::IoImpl* simcall_io_test__getraw__io(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal_raw(simcall->args_[0]); +} +static inline void simcall_io_test__set__io(smx_simcall_t simcall, simgrid::kernel::activity::IoImpl* arg) +{ + simgrid::simix::marshal(simcall->args_[0], arg); +} +static inline bool simcall_io_test__get__result(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal(simcall->result_); +} +static inline bool simcall_io_test__getraw__result(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal_raw(simcall->result_); +} +static inline void simcall_io_test__set__result(smx_simcall_t simcall, bool result) +{ + simgrid::simix::marshal(simcall->result_, result); +} + static inline int simcall_mc_random__get__min(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args_[0]); @@ -1042,4 +1067,5 @@ XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_co XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem); XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout); XBT_PRIVATE void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::IoImpl* io, double timeout); +XBT_PRIVATE void simcall_HANDLER_io_test(smx_simcall_t simcall, simgrid::kernel::activity::IoImpl* io); XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index 356a7b7c30..6f96dc7cc9 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -172,6 +172,13 @@ inline static sg_size_t simcall_BODY_io_wait(simgrid::kernel::activity::IoImpl* return simcall(SIMCALL_IO_WAIT, io, timeout); } +inline static bool simcall_BODY_io_test(simgrid::kernel::activity::IoImpl* io) +{ + if (0) /* Go to that function to follow the code flow through the simcall barrier */ + simcall_HANDLER_io_test(&SIMIX_process_self()->simcall, io); + return simcall(SIMCALL_IO_TEST, io); +} + inline static int simcall_BODY_mc_random(int min, int max) { 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 f2182ee622..00a8b9868f 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -38,6 +38,7 @@ typedef enum { SIMCALL_SEM_ACQUIRE, SIMCALL_SEM_ACQUIRE_TIMEOUT, SIMCALL_IO_WAIT, + SIMCALL_IO_TEST, SIMCALL_MC_RANDOM, SIMCALL_RUN_KERNEL, SIMCALL_RUN_BLOCKING, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index d6d25a0277..deb834267f 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -45,6 +45,7 @@ const char* simcall_names[] = { "SIMCALL_SEM_ACQUIRE", "SIMCALL_SEM_ACQUIRE_TIMEOUT", "SIMCALL_IO_WAIT", + "SIMCALL_IO_TEST", "SIMCALL_MC_RANDOM", "SIMCALL_RUN_KERNEL", "SIMCALL_RUN_BLOCKING", @@ -141,6 +142,10 @@ void simgrid::kernel::actor::ActorImpl::simcall_handle(int value) { simcall_HANDLER_io_wait(&simcall, simgrid::simix::unmarshal(simcall.args_[0]), simgrid::simix::unmarshal(simcall.args_[1])); break; + case SIMCALL_IO_TEST: + simcall_HANDLER_io_test(&simcall, simgrid::simix::unmarshal(simcall.args_[0])); + break; + case SIMCALL_MC_RANDOM: simgrid::simix::marshal(simcall.result_, simcall_HANDLER_mc_random(&simcall, simgrid::simix::unmarshal(simcall.args_[0]), simgrid::simix::unmarshal(simcall.args_[1]))); simcall_answer(); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index f0ebde69fc..2a6bc4910b 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -59,6 +59,7 @@ void sem_acquire(smx_sem_t sem) [[block]]; int sem_acquire_timeout(smx_sem_t sem, double timeout) [[block]]; sg_size_t io_wait(simgrid::kernel::activity::IoImpl* io, double timeout) [[block]]; +bool io_test(simgrid::kernel::activity::IoImpl* io) [[block]]; int mc_random(int min, int max); -- 2.20.1