Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
declare an Io::OpType enum class
[simgrid.git] / src / simix / smx_io.cpp
1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
2
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
6 #include "simgrid/s4u/Host.hpp"
7 #include "simgrid/s4u/Io.hpp"
8 #include "xbt/ex.hpp"
9
10 #include "smx_private.hpp"
11 #include "src/kernel/activity/IoImpl.hpp"
12 #include "src/simix/smx_io_private.hpp"
13 #include "src/surf/StorageImpl.hpp"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
16
17 simgrid::kernel::activity::IoImplPtr SIMIX_io_start(std::string name, sg_size_t size, sg_storage_t storage,
18                                                     simgrid::s4u::Io::OpType type)
19 {
20   /* set surf's action */
21   simgrid::kernel::resource::Action* surf_action = storage->get_impl()->io_start(size, type);
22
23   simgrid::kernel::activity::IoImplPtr io =
24       simgrid::kernel::activity::IoImplPtr(new simgrid::kernel::activity::IoImpl(name, surf_action, storage));
25
26   XBT_DEBUG("Create IO synchro %p %s", io.get(), name.c_str());
27   simgrid::kernel::activity::IoImpl::on_creation(io);
28
29   return io;
30 }
31
32 void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
33 {
34   smx_activity_t synchro = SIMIX_storage_read(st, size);
35   synchro->simcalls_.push_back(simcall);
36   simcall->issuer->waiting_synchro = synchro;
37 }
38
39 smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
40 {
41   //  simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
42   //  synchro->surf_action_                      = st->read(size);
43   //
44   //  synchro->surf_action_->set_data(synchro);
45   //  XBT_DEBUG("Create io synchro %p", synchro);
46   //
47   //  return synchro;
48   return nullptr;
49 }
50
51 void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
52 {
53   smx_activity_t synchro = SIMIX_storage_write(st, size);
54   synchro->simcalls_.push_back(simcall);
55   simcall->issuer->waiting_synchro = synchro;
56 }
57
58 smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
59 {
60   //  simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
61   //  synchro->surf_action_                      = st->write(size);
62   //  synchro->surf_action_->set_data(synchro);
63   //  XBT_DEBUG("Create io synchro %p", synchro);
64   //
65   //  return synchro;
66   return nullptr;
67 }
68
69 void SIMIX_io_destroy(smx_activity_t synchro)
70 {
71   simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
72   XBT_DEBUG("Destroy synchro %p", synchro.get());
73   if (io->surf_action_)
74     io->surf_action_->unref();
75 }
76
77 void SIMIX_io_finish(smx_activity_t synchro)
78 {
79   for (smx_simcall_t const& simcall : synchro->simcalls_) {
80     switch (synchro->state_) {
81       case SIMIX_DONE:
82         /* do nothing, synchro done */
83         break;
84       case SIMIX_FAILED:
85         SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
86         break;
87       case SIMIX_CANCELED:
88         SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
89         break;
90       default:
91         xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state_));
92     }
93
94     if (simcall->issuer->host_->is_off()) {
95       simcall->issuer->context_->iwannadie = 1;
96     }
97
98     simcall->issuer->waiting_synchro = nullptr;
99     SIMIX_simcall_answer(simcall);
100   }
101
102   /* We no longer need it */
103   SIMIX_io_destroy(synchro);
104 }