Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
160279aa698025b2fe4a529227ed23053af7be27
[simgrid.git] / src / surf / disk_s19.cpp
1 /* Copyright (c) 2013-2019. 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 "disk_s19.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11 #include "src/surf/xml/platf.hpp"
12 #include "surf/surf.hpp"
13
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(disk_kernel);
15
16 /*********
17  * Model *
18  *********/
19
20 void surf_disk_model_init_default()
21 {
22   surf_disk_model = new simgrid::kernel::resource::DiskS19Model();
23 }
24
25 namespace simgrid {
26 namespace kernel {
27 namespace resource {
28
29 DiskS19Model::DiskS19Model()
30 {
31   all_existing_models.push_back(this);
32 }
33
34 DiskImpl* DiskS19Model::createDisk(const std::string& id, double read_bw, double write_bw)
35 {
36   XBT_DEBUG("SURF disk create resource\n\t\tid '%s'\n\t\tread_bw '%f'\n", id.c_str(), read_bw);
37
38   return new DiskS19(this, id, get_maxmin_system(), read_bw, write_bw);
39 }
40
41 double DiskS19Model::next_occuring_event(double now)
42 {
43   return DiskModel::next_occuring_event_full(now);
44 }
45
46 void DiskS19Model::update_actions_state(double /*now*/, double delta)
47 {
48   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
49     auto& action = *it;
50     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
51     action.update_remains(lrint(action.get_variable()->get_value() * delta));
52     action.update_max_duration(delta);
53
54     if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
55         ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
56       action.finish(Action::State::FINISHED);
57     }
58   }
59 }
60
61 /************
62  * Resource *
63  ************/
64
65 DiskS19::DiskS19(DiskModel* model, const std::string& name, lmm::System* maxminSystem, double read_bw, double write_bw)
66     : DiskImpl(model, name, maxminSystem, read_bw, write_bw)
67 {
68   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
69   // FIXME s4u::Storage::on_creation(this->piface_);
70 }
71
72 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
73 {
74   return new DiskS19Action(get_model(), size, not is_on(), this, type);
75 }
76
77 DiskAction* DiskS19::read(sg_size_t size)
78 {
79   return new DiskS19Action(get_model(), size, not is_on(), this, s4u::Io::OpType::READ);
80 }
81
82 DiskAction* DiskS19::write(sg_size_t size)
83 {
84   return new DiskS19Action(get_model(), size, not is_on(), this, s4u::Io::OpType::WRITE);
85 }
86
87 /**********
88  * Action *
89  **********/
90
91 DiskS19Action::DiskS19Action(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
92     : DiskAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), disk, type)
93 {
94   XBT_IN("(%s,%g", disk->get_cname(), cost);
95
96   // Must be less than the max bandwidth for all actions
97   model->get_maxmin_system()->expand(disk->get_constraint(), get_variable(), 1.0);
98   switch (type) {
99     case s4u::Io::OpType::READ:
100       model->get_maxmin_system()->expand(disk->constraint_read_, get_variable(), 1.0);
101       break;
102     case s4u::Io::OpType::WRITE:
103       model->get_maxmin_system()->expand(disk->constraint_write_, get_variable(), 1.0);
104       break;
105     default:
106       THROW_UNIMPLEMENTED;
107   }
108   XBT_OUT();
109 }
110
111 void DiskS19Action::cancel()
112 {
113   set_state(Action::State::FAILED);
114 }
115
116 void DiskS19Action::suspend()
117 {
118   XBT_IN("(%p)", this);
119   if (is_running()) {
120     get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
121     set_suspend_state(Action::SuspendStates::SUSPENDED);
122   }
123   XBT_OUT();
124 }
125
126 void DiskS19Action::resume()
127 {
128   THROW_UNIMPLEMENTED;
129 }
130
131 void DiskS19Action::set_max_duration(double /*duration*/)
132 {
133   THROW_UNIMPLEMENTED;
134 }
135
136 void DiskS19Action::set_sharing_penalty(double)
137 {
138   THROW_UNIMPLEMENTED;
139 }
140 void DiskS19Action::update_remains_lazy(double /*now*/)
141 {
142   THROW_IMPOSSIBLE;
143 }
144 } // namespace resource
145 } // namespace kernel
146 } // namespace simgrid