1 /* Copyright (c) 2007-2021. 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/kernel/resource/DiskImpl.hpp"
11 #include "src/mc/mc_replay.hpp"
12 #include "src/simix/smx_private.hpp"
13 #include "src/surf/StorageImpl.hpp"
14 #include "src/surf/cpu_interface.hpp"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
22 IoImpl& IoImpl::set_timeout(double timeout)
24 const s4u::Host* host = get_disk() ? get_disk()->get_host() : s4u::Host::by_name(get_storage()->get_host());
25 timeout_detector_ = host->pimpl_cpu->sleep(timeout);
26 timeout_detector_->set_activity(this);
30 IoImpl& IoImpl::set_type(s4u::Io::OpType type)
36 IoImpl& IoImpl::set_size(sg_size_t size)
42 IoImpl& IoImpl::set_disk(resource::DiskImpl* disk)
48 IoImpl& IoImpl::set_storage(resource::StorageImpl* storage)
54 IoImpl* IoImpl::start()
56 state_ = State::RUNNING;
58 surf_action_ = storage_->io_start(size_, type_);
60 surf_action_ = disk_->io_start(size_, type_);
61 surf_action_->set_activity(this);
63 XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
70 performed_ioops_ = surf_action_->get_cost();
71 if (surf_action_->get_state() == resource::Action::State::FAILED) {
72 if ((storage_ && not storage_->is_on()) || (disk_ && not disk_->is_on()))
73 state_ = State::FAILED;
75 state_ = State::CANCELED;
76 } else if (surf_action_->get_state() == resource::Action::State::FINISHED) {
78 } else if (timeout_detector_ && timeout_detector_->get_state() == resource::Action::State::FINISHED) {
79 state_ = State::TIMEOUT;
83 if (timeout_detector_) {
84 timeout_detector_->unref();
85 timeout_detector_ = nullptr;
88 /* Answer all simcalls associated with the synchro */
94 while (not simcalls_.empty()) {
95 const s_smx_simcall* simcall = simcalls_.front();
96 simcalls_.pop_front();
99 /* do nothing, synchro done */
102 simcall->issuer_->context_->set_wannadie();
103 simcall->issuer_->exception_ =
104 std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
106 case State::CANCELED:
107 simcall->issuer_->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
110 XBT_DEBUG("IoImpl::finish(): execution timeouted");
111 simcall->issuer_->exception_ = std::make_exception_ptr(simgrid::TimeoutException(XBT_THROW_POINT, "Timeouted"));
114 xbt_die("Internal error in IoImpl::finish(): unexpected synchro state %d", static_cast<int>(state_));
117 simcall->issuer_->waiting_synchro_ = nullptr;
118 simcall->issuer_->simcall_answer();
122 } // namespace activity
123 } // namespace kernel
124 } // namespace simgrid