Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'multi_models_no_globals' into 'master'
[simgrid.git] / src / kernel / resource / DiskImpl.cpp
1 /* Copyright (c) 2019-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 "DiskImpl.hpp"
7
8 #include "simgrid/s4u/Engine.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
13
14 namespace simgrid {
15 namespace kernel {
16 namespace resource {
17
18 /*********
19  * Model *
20  *********/
21
22 DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
23 {
24   set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
25 }
26
27 DiskModel::~DiskModel()
28 {
29 }
30
31 /************
32  * Resource *
33  ************/
34 DiskImpl* DiskImpl::set_host(s4u::Host* host)
35 {
36   host_ = host;
37   return this;
38 }
39
40 DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
41 {
42   read_bw_ = read_bw;
43   return this;
44 }
45
46 DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
47 {
48   write_bw_ = write_bw;
49   return this;
50 }
51
52 DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
53 {
54   constraint_read_ = constraint_read;
55   return this;
56 }
57
58 DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
59 {
60   constraint_write_ = constraint_write;
61   return this;
62 }
63
64 /** @brief Fire the required callbacks and destroy the object
65  *
66  * Don't delete directly a Disk, call d->destroy() instead.
67  */
68 void DiskImpl::destroy()
69 {
70   s4u::Disk::on_destruction(this->piface_);
71   delete this;
72 }
73
74 bool DiskImpl::is_used() const
75 {
76   THROW_UNIMPLEMENTED;
77 }
78
79 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
80 {
81   THROW_UNIMPLEMENTED;
82 }
83
84 void DiskImpl::turn_on()
85 {
86   if (not is_on()) {
87     Resource::turn_on();
88     s4u::Disk::on_state_change(this->piface_);
89   }
90 }
91 void DiskImpl::turn_off()
92 {
93   if (is_on()) {
94     Resource::turn_off();
95     s4u::Disk::on_state_change(this->piface_);
96   }
97 }
98
99 void DiskImpl::seal()
100 {
101   xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", this->get_cname());
102   lmm::System* maxmin_system = get_model()->get_maxmin_system();
103   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
104       ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
105       ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
106   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
107   Resource::seal();
108   turn_on();
109 }
110 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
111
112 /**********
113  * Action *
114  **********/
115 void DiskAction::set_state(Action::State state)
116 {
117   Action::State old = get_state();
118   Action::set_state(state);
119   on_state_change(*this, old, state);
120 }
121 } // namespace resource
122 } // namespace kernel
123 } // namespace simgrid