1 /* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include <simgrid/s4u/Disk.hpp>
7 #include <simgrid/s4u/Io.hpp>
8 #include <simgrid/simix.hpp>
10 #include "src/kernel/resource/DiskImpl.hpp"
14 template class xbt::Extendable<s4u::Disk>;
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_onoff;
22 const std::string& Disk::get_name() const
24 return pimpl_->get_name();
27 const char* Disk::get_cname() const
29 return pimpl_->get_cname();
32 Disk* Disk::set_read_bandwidth(double read_bw)
34 kernel::actor::simcall_object_access(pimpl_, [this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
38 Disk* Disk::set_write_bandwidth(double write_bw)
40 kernel::actor::simcall_object_access(pimpl_, [this, write_bw] { pimpl_->set_write_bandwidth(write_bw); });
44 double Disk::get_read_bandwidth() const
46 return pimpl_->get_read_bandwidth();
49 Disk* Disk::set_readwrite_bandwidth(double bw)
51 kernel::actor::simcall_object_access(pimpl_, [this, bw] { pimpl_->set_readwrite_bandwidth(bw); });
55 double Disk::get_write_bandwidth() const
57 return pimpl_->get_write_bandwidth();
60 Disk* Disk::set_host(Host* host)
62 pimpl_->set_host(host);
66 Host* Disk::get_host() const
68 return pimpl_->get_host();
71 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
73 return pimpl_->get_properties();
76 const char* Disk::get_property(const std::string& key) const
78 return pimpl_->get_property(key);
81 Disk* Disk::set_property(const std::string& key, const std::string& value)
83 kernel::actor::simcall_object_access(pimpl_, [this, &key, &value] { this->pimpl_->set_property(key, value); });
87 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
89 kernel::actor::simcall_object_access(pimpl_, [this, properties] { this->pimpl_->set_properties(properties); });
93 Disk* Disk::set_state_profile(kernel::profile::Profile* profile)
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); });
100 Disk* Disk::set_read_bandwidth_profile(kernel::profile::Profile* profile)
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); });
108 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
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); });
115 int Disk::get_concurrency_limit() const
117 return pimpl_->get_concurrency_limit();
120 Disk* Disk::set_concurrency_limit(int limit)
122 kernel::actor::simcall_object_access(pimpl_, [this, limit] { pimpl_->set_concurrency_limit(limit); });
126 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
128 return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
131 IoPtr Disk::read_async(sg_size_t size) const
133 return IoPtr(io_init(size, Io::OpType::READ))->start();
136 sg_size_t Disk::read(sg_size_t size) const
138 return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
141 sg_size_t Disk::read(sg_size_t size, double priority) const
143 return IoPtr(io_init(size, Io::OpType::READ))
144 ->set_priority(priority)
147 ->get_performed_ioops();
150 IoPtr Disk::write_async(sg_size_t size) const
152 return IoPtr(io_init(size, Io::OpType::WRITE)->start());
155 sg_size_t Disk::write(sg_size_t size) const
157 return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
160 sg_size_t Disk::write(sg_size_t size, double priority) const
162 return IoPtr(io_init(size, Io::OpType::WRITE))
163 ->set_priority(priority)
166 ->get_performed_ioops();
169 Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb)
171 kernel::actor::simcall_object_access(pimpl_, [this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });
175 Disk::SharingPolicy Disk::get_sharing_policy(Operation op) const
177 return this->pimpl_->get_sharing_policy(op);
180 Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
182 kernel::actor::simcall_object_access(pimpl_, [this, &cb] { pimpl_->set_factor_cb(cb); });
188 kernel::actor::simcall_answered([this] { pimpl_->seal(); });
189 Disk::on_creation(*this); // notify the signal
193 } // namespace simgrid
195 /* **************************** Public C interface *************************** */
197 const char* sg_disk_get_name(const_sg_disk_t disk)
199 return disk->get_cname();
202 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
204 return disk->get_host();
207 double sg_disk_read_bandwidth(const_sg_disk_t disk)
209 return disk->get_read_bandwidth();
212 double sg_disk_write_bandwidth(const_sg_disk_t disk)
214 return disk->get_write_bandwidth();
217 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
219 return disk->read(size);
221 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
223 return disk->write(size);
226 void* sg_disk_get_data(const_sg_disk_t disk)
228 return disk->get_data<void>();
231 void sg_disk_set_data(sg_disk_t disk, void* data)
233 disk->set_data(data);