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/FileImpl.hpp"
13 #include "src/surf/HostImpl.hpp"
14 #include "src/surf/StorageImpl.hpp"
15 #include "surf/surf.hpp"
17 #include "smx_private.hpp"
18 #include "src/surf/surf_interface.hpp"
20 #include "src/kernel/activity/SynchroIo.hpp"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
24 void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
26 smx_activity_t synchro = SIMIX_storage_read(st, size);
27 synchro->simcalls.push_back(simcall);
28 simcall->issuer->waiting_synchro = synchro;
31 smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
33 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
34 synchro->surf_io = st->read(size);
36 synchro->surf_io->setData(synchro);
37 XBT_DEBUG("Create io synchro %p", synchro);
42 void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
44 smx_activity_t synchro = SIMIX_storage_write(st, size);
45 synchro->simcalls.push_back(simcall);
46 simcall->issuer->waiting_synchro = synchro;
49 smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
51 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
52 synchro->surf_io = st->write(size);
53 synchro->surf_io->setData(synchro);
54 XBT_DEBUG("Create io synchro %p", synchro);
59 void SIMIX_io_destroy(smx_activity_t synchro)
61 simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
62 XBT_DEBUG("Destroy synchro %p", synchro.get());
67 void SIMIX_io_finish(smx_activity_t synchro)
69 for (smx_simcall_t const& simcall : synchro->simcalls) {
70 switch (synchro->state) {
72 /* do nothing, synchro done */
75 SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
78 SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
81 xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state));
84 if (simcall->issuer->host->isOff()) {
85 simcall->issuer->context->iwannadie = 1;
88 simcall->issuer->waiting_synchro = nullptr;
89 SIMIX_simcall_answer(simcall);
92 /* We no longer need it */
93 SIMIX_io_destroy(synchro);