Logo AND Algorithmique Numérique Distribuée

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