1 /* Copyright (c) 2007-2017. 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 <xbt/sysdep.h>
10 #include "simgrid/s4u/Host.hpp"
11 #include "simgrid/s4u/Storage.hpp"
12 #include "src/surf/HostImpl.hpp"
13 #include "src/surf/StorageImpl.hpp"
14 #include "surf/surf.hpp"
16 #include "smx_private.hpp"
17 #include "src/surf/surf_interface.hpp"
19 #include "src/kernel/activity/SynchroIo.hpp"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
23 void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
25 smx_activity_t synchro = SIMIX_storage_read(st, size);
26 synchro->simcalls.push_back(simcall);
27 simcall->issuer->waiting_synchro = synchro;
30 smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
32 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
33 synchro->surf_io = st->read(size);
35 synchro->surf_io->set_data(synchro);
36 XBT_DEBUG("Create io synchro %p", synchro);
41 void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
43 smx_activity_t synchro = SIMIX_storage_write(st, size);
44 synchro->simcalls.push_back(simcall);
45 simcall->issuer->waiting_synchro = synchro;
48 smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
50 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
51 synchro->surf_io = st->write(size);
52 synchro->surf_io->set_data(synchro);
53 XBT_DEBUG("Create io synchro %p", synchro);
58 void SIMIX_io_destroy(smx_activity_t synchro)
60 simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
61 XBT_DEBUG("Destroy synchro %p", synchro.get());
66 void SIMIX_io_finish(smx_activity_t synchro)
68 for (smx_simcall_t const& simcall : synchro->simcalls) {
69 switch (synchro->state) {
71 /* do nothing, synchro done */
74 SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
77 SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
80 xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state));
83 if (simcall->issuer->host->isOff()) {
84 simcall->issuer->context->iwannadie = 1;
87 simcall->issuer->waiting_synchro = nullptr;
88 SIMIX_simcall_answer(simcall);
91 /* We no longer need it */
92 SIMIX_io_destroy(synchro);