1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
11 #include "smx_private.hpp"
12 #include "src/kernel/activity/IoImpl.hpp"
13 #include "src/mc/mc_replay.hpp"
14 #include "src/simix/smx_io_private.hpp"
15 #include "src/surf/StorageImpl.hpp"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
19 simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
20 simgrid::s4u::Io::OpType type)
22 /* set surf's action */
23 simgrid::kernel::resource::Action* surf_action = storage->get_impl()->io_start(size, type);
25 simgrid::kernel::activity::IoImplPtr io =
26 simgrid::kernel::activity::IoImplPtr(new simgrid::kernel::activity::IoImpl(name, surf_action, storage));
28 XBT_DEBUG("Create IO synchro %p %s", io.get(), name.c_str());
29 simgrid::kernel::activity::IoImpl::on_creation(io);
34 void simcall_HANDLER_io_wait(smx_simcall_t simcall, smx_activity_t synchro)
36 XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro.get(), (int)synchro->state_);
38 /* Associate this simcall to the synchro */
39 synchro->simcalls_.push_back(simcall);
40 simcall->issuer->waiting_synchro = synchro;
42 /* set surf's synchro */
43 if (MC_is_active() || MC_record_replay_is_active()) {
44 synchro->state_ = SIMIX_DONE;
45 SIMIX_io_finish(synchro);
49 /* If the synchro is already finished then perform the error handling */
50 if (synchro->state_ != SIMIX_RUNNING)
51 SIMIX_io_finish(synchro);
54 void SIMIX_io_finish(smx_activity_t synchro)
56 for (smx_simcall_t const& simcall : synchro->simcalls_) {
57 switch (synchro->state_) {
59 /* do nothing, synchro done */
62 SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
65 SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
68 xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state_));
71 if (simcall->issuer->host_->is_off()) {
72 simcall->issuer->context_->iwannadie = 1;
75 simcall->issuer->waiting_synchro = nullptr;
76 SIMIX_simcall_answer(simcall);