Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I/O factors: noise for disks.
[simgrid.git] / src / s4u / s4u_Disk.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 "simgrid/s4u/Disk.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
10 #include "simgrid/simix.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12
13 namespace simgrid {
14
15 template class xbt::Extendable<s4u::Disk>;
16
17 namespace s4u {
18
19 xbt::signal<void(Disk&)> Disk::on_creation;
20 xbt::signal<void(Disk const&)> Disk::on_destruction;
21 xbt::signal<void(Disk const&)> Disk::on_state_change;
22
23 const std::string& Disk::get_name() const
24 {
25   return pimpl_->get_name();
26 }
27
28 const char* Disk::get_cname() const
29 {
30   return pimpl_->get_cname();
31 }
32
33 Disk* Disk::set_read_bandwidth(double read_bw)
34 {
35   kernel::actor::simcall([this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
36   return this;
37 }
38
39 Disk* Disk::set_write_bandwidth(double write_bw)
40 {
41   kernel::actor::simcall([this, write_bw] { pimpl_->set_write_bandwidth(write_bw); });
42   return this;
43 }
44
45 double Disk::get_read_bandwidth() const
46 {
47   return pimpl_->get_read_bandwidth();
48 }
49
50 double Disk::get_write_bandwidth() const
51 {
52   return pimpl_->get_write_bandwidth();
53 }
54
55 Disk* Disk::set_host(Host* host)
56 {
57   pimpl_->set_host(host);
58   return this;
59 }
60
61 Host* Disk::get_host() const
62 {
63   return pimpl_->get_host();
64 }
65
66 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
67 {
68   return pimpl_->get_properties();
69 }
70
71 const char* Disk::get_property(const std::string& key) const
72 {
73   return pimpl_->get_property(key);
74 }
75
76 Disk* Disk::set_property(const std::string& key, const std::string& value)
77 {
78   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
79   return this;
80 }
81
82 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
83 {
84   kernel::actor::simcall([this, properties] { this->pimpl_->set_properties(properties); });
85   return this;
86 }
87
88 Disk* Disk::set_state_profile(kernel::profile::Profile* profile)
89 {
90   xbt_assert(not pimpl_->is_sealed(), "Cannot set a state profile once the Disk is sealed");
91   kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
92   return this;
93 }
94
95 Disk* Disk::set_read_bandwidth_profile(kernel::profile::Profile* profile)
96 {
97   xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
98   kernel::actor::simcall([this, profile]() { this->pimpl_->set_read_bandwidth_profile(profile); });
99   return this;
100 }
101
102 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
103 {
104   xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
105   kernel::actor::simcall([this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); });
106   return this;
107 }
108
109 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
110 {
111   return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
112 }
113
114 IoPtr Disk::read_async(sg_size_t size) const
115 {
116   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
117 }
118
119 sg_size_t Disk::read(sg_size_t size) const
120 {
121   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
122 }
123
124 IoPtr Disk::write_async(sg_size_t size) const
125 {
126   return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
127 }
128
129 sg_size_t Disk::write(sg_size_t size) const
130 {
131   return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
132 }
133
134 Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb)
135 {
136   kernel::actor::simcall([this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });
137   return this;
138 }
139
140 Disk::SharingPolicy Disk::get_sharing_policy(Operation op) const
141 {
142   return this->pimpl_->get_sharing_policy(op);
143 }
144
145 Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
146 {
147   kernel::actor::simcall([this, &cb] { pimpl_->set_factor_cb(cb); });
148   return this;
149 }
150
151 Disk* Disk::seal()
152 {
153   kernel::actor::simcall([this]{ pimpl_->seal(); });
154   Disk::on_creation(*this);
155   return this;
156 }
157 } // namespace s4u
158 } // namespace simgrid
159
160 /* **************************** Public C interface *************************** */
161
162 const char* sg_disk_get_name(const_sg_disk_t disk)
163 {
164   return disk->get_cname();
165 }
166
167 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
168 {
169   return disk->get_host();
170 }
171
172 double sg_disk_read_bandwidth(const_sg_disk_t disk)
173 {
174   return disk->get_read_bandwidth();
175 }
176
177 double sg_disk_write_bandwidth(const_sg_disk_t disk)
178 {
179   return disk->get_write_bandwidth();
180 }
181
182 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
183 {
184   return disk->read(size);
185 }
186 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
187 {
188   return disk->write(size);
189 }
190
191 void* sg_disk_get_data(const_sg_disk_t disk)
192 {
193   return disk->get_data();
194 }
195
196 void sg_disk_set_data(sg_disk_t disk, void* data)
197 {
198   disk->set_data(data);
199 }