Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'udpor-phase7' into 'master'
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019-2023. 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_object_access(pimpl_, [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_object_access(pimpl_, [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_object_access(pimpl_, [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_object_access(pimpl_, [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_object_access(pimpl_, [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_object_access(pimpl_, [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_object_access(pimpl_,
104                                        [this, profile]() { this->pimpl_->set_read_bandwidth_profile(profile); });
105   return this;
106 }
107
108 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
109 {
110   xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
111   kernel::actor::simcall_object_access(pimpl_,
112                                        [this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); });
113   return this;
114 }
115 int Disk::get_concurrency_limit() const
116 {
117   return pimpl_->get_concurrency_limit();
118 }
119
120 Disk* Disk::set_concurrency_limit(int limit)
121 {
122   kernel::actor::simcall_object_access(pimpl_, [this, limit] { pimpl_->set_concurrency_limit(limit); });
123   return this;
124 }
125
126 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
127 {
128   return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
129 }
130
131 IoPtr Disk::read_async(sg_size_t size) const
132 {
133   return IoPtr(io_init(size, Io::OpType::READ))->start();
134 }
135
136 sg_size_t Disk::read(sg_size_t size) const
137 {
138   return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
139 }
140
141 sg_size_t Disk::read(sg_size_t size, double priority) const
142 {
143   return IoPtr(io_init(size, Io::OpType::READ))
144       ->set_priority(priority)
145       ->start()
146       ->wait()
147       ->get_performed_ioops();
148 }
149
150 IoPtr Disk::write_async(sg_size_t size) const
151 {
152   return IoPtr(io_init(size, Io::OpType::WRITE)->start());
153 }
154
155 sg_size_t Disk::write(sg_size_t size) const
156 {
157   return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
158 }
159
160 sg_size_t Disk::write(sg_size_t size, double priority) const
161 {
162   return IoPtr(io_init(size, Io::OpType::WRITE))
163       ->set_priority(priority)
164       ->start()
165       ->wait()
166       ->get_performed_ioops();
167 }
168
169 Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb)
170 {
171   kernel::actor::simcall_object_access(pimpl_, [this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });
172   return this;
173 }
174
175 Disk::SharingPolicy Disk::get_sharing_policy(Operation op) const
176 {
177   return this->pimpl_->get_sharing_policy(op);
178 }
179
180 Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
181 {
182   kernel::actor::simcall_object_access(pimpl_, [this, &cb] { pimpl_->set_factor_cb(cb); });
183   return this;
184 }
185
186 Disk* Disk::seal()
187 {
188   kernel::actor::simcall_answered([this] { pimpl_->seal(); });
189   Disk::on_creation(*this); // notify the signal
190   return this;
191 }
192 } // namespace s4u
193 } // namespace simgrid
194
195 /* **************************** Public C interface *************************** */
196
197 const char* sg_disk_get_name(const_sg_disk_t disk)
198 {
199   return disk->get_cname();
200 }
201
202 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
203 {
204   return disk->get_host();
205 }
206
207 double sg_disk_read_bandwidth(const_sg_disk_t disk)
208 {
209   return disk->get_read_bandwidth();
210 }
211
212 double sg_disk_write_bandwidth(const_sg_disk_t disk)
213 {
214   return disk->get_write_bandwidth();
215 }
216
217 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
218 {
219   return disk->read(size);
220 }
221 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
222 {
223   return disk->write(size);
224 }
225
226 void* sg_disk_get_data(const_sg_disk_t disk)
227 {
228   return disk->get_data<void>();
229 }
230
231 void sg_disk_set_data(sg_disk_t disk, void* data)
232 {
233   disk->set_data(data);
234 }