Logo AND Algorithmique Numérique Distribuée

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