1 /* Copyright (c) 2019-2022. 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_state_change;
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_answered([this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
38 Disk* Disk::set_write_bandwidth(double write_bw)
40 kernel::actor::simcall_answered([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_answered([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_answered([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_answered([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_answered([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_answered([this, profile]() { this->pimpl_->set_read_bandwidth_profile(profile); });
107 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
109 xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
110 kernel::actor::simcall_answered([this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); });
114 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
116 return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
119 IoPtr Disk::read_async(sg_size_t size) const
121 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
124 sg_size_t Disk::read(sg_size_t size) const
126 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
129 sg_size_t Disk::read(sg_size_t size, double priority) const
131 return IoPtr(io_init(size, Io::OpType::READ))
132 ->set_priority(priority)
135 ->get_performed_ioops();
138 IoPtr Disk::write_async(sg_size_t size) const
140 return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
143 sg_size_t Disk::write(sg_size_t size) const
145 return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
148 sg_size_t Disk::write(sg_size_t size, double priority) const
150 return IoPtr(io_init(size, Io::OpType::WRITE))
151 ->set_priority(priority)
154 ->get_performed_ioops();
157 Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb)
159 kernel::actor::simcall_answered([this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });
163 Disk::SharingPolicy Disk::get_sharing_policy(Operation op) const
165 return this->pimpl_->get_sharing_policy(op);
168 Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
170 kernel::actor::simcall_answered([this, &cb] { pimpl_->set_factor_cb(cb); });
176 kernel::actor::simcall_answered([this] { pimpl_->seal(); });
177 Disk::on_creation(*this); // notify the signal
181 } // namespace simgrid
183 /* **************************** Public C interface *************************** */
185 const char* sg_disk_get_name(const_sg_disk_t disk)
187 return disk->get_cname();
190 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
192 return disk->get_host();
195 double sg_disk_read_bandwidth(const_sg_disk_t disk)
197 return disk->get_read_bandwidth();
200 double sg_disk_write_bandwidth(const_sg_disk_t disk)
202 return disk->get_write_bandwidth();
205 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
207 return disk->read(size);
209 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
211 return disk->write(size);
214 void* sg_disk_get_data(const_sg_disk_t disk)
216 return disk->get_data<void>();
219 void sg_disk_set_data(sg_disk_t disk, void* data)
221 disk->set_data(data);