Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change way disks are managed in the XML parsing
[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(const std::string& name) : Model(name)
23 {
24   set_maxmin_system(new lmm::System(true /* selective update */));
25 }
26
27 /************
28  * Resource *
29  ************/
30 DiskImpl* DiskImpl::set_host(s4u::Host* host)
31 {
32   xbt_assert(host, "Cannot set host, none given");
33   host_ = host;
34   return this;
35 }
36
37 DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
38 {
39   read_bw_ = read_bw;
40   return this;
41 }
42
43 DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
44 {
45   write_bw_ = write_bw;
46   return this;
47 }
48
49 DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
50 {
51   constraint_read_ = constraint_read;
52   return this;
53 }
54
55 DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
56 {
57   constraint_write_ = constraint_write;
58   return this;
59 }
60
61 /** @brief Fire the required callbacks and destroy the object
62  *
63  * Don't delete directly a Disk, call d->destroy() instead.
64  */
65 void DiskImpl::destroy()
66 {
67   s4u::Disk::on_destruction(this->piface_);
68   delete this;
69 }
70
71 bool DiskImpl::is_used() const
72 {
73   return get_model()->get_maxmin_system()->constraint_used(get_constraint());
74 }
75
76 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
77 {
78   THROW_UNIMPLEMENTED;
79 }
80
81 void DiskImpl::turn_on()
82 {
83   if (not is_on()) {
84     Resource::turn_on();
85     s4u::Disk::on_state_change(this->piface_);
86   }
87 }
88 void DiskImpl::turn_off()
89 {
90   if (is_on()) {
91     Resource::turn_off();
92     s4u::Disk::on_state_change(this->piface_);
93   }
94 }
95
96 void DiskImpl::seal()
97 {
98   xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", this->get_cname());
99   lmm::System* maxmin_system = get_model()->get_maxmin_system();
100   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
101       ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
102       ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
103   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
104   Resource::seal();
105   turn_on();
106 }
107 xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
108
109 /**********
110  * Action *
111  **********/
112 void DiskAction::set_state(Action::State state)
113 {
114   Action::State old = get_state();
115   Action::set_state(state);
116   on_state_change(*this, old, state);
117 }
118 } // namespace resource
119 } // namespace kernel
120 } // namespace simgrid