Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf_disk_model: remove it.
[simgrid.git] / src / surf / disk_s19.cpp
1 /* Copyright (c) 2013-2021. 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(res_disk);
15
16 /*********
17  * Model *
18  *********/
19
20 void surf_disk_model_init_default()
21 {
22   /* FIXME[donassolo]: this smells bad, but works
23    * (the constructor saves its pointer in all_existing_models and models_by_type :O).
24    * We need a manager for these models */
25   new simgrid::kernel::resource::DiskS19Model();
26 }
27
28 namespace simgrid {
29 namespace kernel {
30 namespace resource {
31
32 DiskS19Model::DiskS19Model()
33 {
34   all_existing_models.push_back(this);
35   models_by_type[simgrid::kernel::resource::Model::Type::DISK].push_back(this);
36 }
37
38 DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
39 {
40   return (new DiskS19(name, read_bandwidth, write_bandwidth))->set_model(this);
41 }
42
43 double DiskS19Model::next_occurring_event(double now)
44 {
45   return DiskModel::next_occurring_event_full(now);
46 }
47
48 void DiskS19Model::update_actions_state(double /*now*/, double delta)
49 {
50   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
51     auto& action = *it;
52     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
53     action.update_remains(rint(action.get_variable()->get_value() * delta));
54     action.update_max_duration(delta);
55
56     if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
57         ((action.get_max_duration() != NO_MAX_DURATION) && (action.get_max_duration() <= 0))) {
58       action.finish(Action::State::FINISHED);
59     }
60   }
61 }
62
63 /************
64  * Resource *
65  ************/
66 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
67 {
68   return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, type);
69 }
70
71 DiskAction* DiskS19::read(sg_size_t size)
72 {
73   return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::READ);
74 }
75
76 DiskAction* DiskS19::write(sg_size_t size)
77 {
78   return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::WRITE);
79 }
80
81 /**********
82  * Action *
83  **********/
84
85 DiskS19Action::DiskS19Action(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
86     : DiskAction(model, cost, failed, model->get_maxmin_system()->variable_new(this, 1.0, -1.0, 3), disk, type)
87 {
88   XBT_IN("(%s,%g", disk->get_cname(), cost);
89
90   // Must be less than the max bandwidth for all actions
91   model->get_maxmin_system()->expand(disk->get_constraint(), get_variable(), 1.0);
92   switch (type) {
93     case s4u::Io::OpType::READ:
94       model->get_maxmin_system()->expand(disk->get_read_constraint(), get_variable(), 1.0);
95       break;
96     case s4u::Io::OpType::WRITE:
97       model->get_maxmin_system()->expand(disk->get_write_constraint(), get_variable(), 1.0);
98       break;
99     default:
100       THROW_UNIMPLEMENTED;
101   }
102   XBT_OUT();
103 }
104
105 void DiskS19Action::cancel()
106 {
107   set_state(Action::State::FAILED);
108 }
109
110 void DiskS19Action::suspend()
111 {
112   XBT_IN("(%p)", this);
113   if (is_running()) {
114     get_model()->get_maxmin_system()->update_variable_penalty(get_variable(), 0.0);
115     set_suspend_state(Action::SuspendStates::SUSPENDED);
116   }
117   XBT_OUT();
118 }
119
120 void DiskS19Action::resume()
121 {
122   THROW_UNIMPLEMENTED;
123 }
124
125 void DiskS19Action::set_max_duration(double /*duration*/)
126 {
127   THROW_UNIMPLEMENTED;
128 }
129
130 void DiskS19Action::set_sharing_penalty(double)
131 {
132   THROW_UNIMPLEMENTED;
133 }
134 void DiskS19Action::update_remains_lazy(double /*now*/)
135 {
136   THROW_IMPOSSIBLE;
137 }
138 } // namespace resource
139 } // namespace kernel
140 } // namespace simgrid