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. */
5 #include "src/kernel/activity/IoImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/resource/Action.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/mc/mc_replay.hpp"
11 #include "src/simix/smx_private.hpp"
12 #include "src/surf/StorageImpl.hpp"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
16 void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::IoImpl* synchro)
18 XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro, (int)synchro->state_);
20 /* Associate this simcall to the synchro */
21 synchro->register_simcall(simcall);
23 /* set surf's synchro */
24 if (MC_is_active() || MC_record_replay_is_active()) {
25 synchro->state_ = SIMIX_DONE;
30 /* If the synchro is already finished then perform the error handling */
31 if (synchro->state_ != SIMIX_RUNNING)
39 IoImpl& IoImpl::set_type(s4u::Io::OpType type)
45 IoImpl& IoImpl::set_size(sg_size_t size)
51 IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
57 IoImpl* IoImpl::start()
59 state_ = SIMIX_RUNNING;
60 surf_action_ = storage_->io_start(size_, type_);
61 surf_action_->set_activity(this);
63 XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
64 IoImpl::on_start(*this);
71 performed_ioops_ = surf_action_->get_cost();
72 if (surf_action_->get_state() == resource::Action::State::FAILED) {
73 if (storage_ && not storage_->is_on())
74 state_ = SIMIX_FAILED;
76 state_ = SIMIX_CANCELED;
77 } else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
87 while (not simcalls_.empty()) {
88 smx_simcall_t simcall = simcalls_.front();
89 simcalls_.pop_front();
92 /* do nothing, synchro done */
95 simcall->issuer->context_->iwannadie = true;
96 simcall->issuer->exception_ =
97 std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
100 simcall->issuer->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
103 xbt_die("Internal error in IoImpl::finish(): unexpected synchro state %d", static_cast<int>(state_));
106 simcall->issuer->waiting_synchro = nullptr;
107 SIMIX_simcall_answer(simcall);
114 xbt::signal<void(IoImpl const&)> IoImpl::on_start;
115 xbt::signal<void(IoImpl const&)> IoImpl::on_completion;
117 } // namespace activity
118 } // namespace kernel
119 } // namespace simgrid