1 /* Copyright (c) 2019-2021. 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/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"
15 template class xbt::Extendable<s4u::Disk>;
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;
23 const std::string& Disk::get_name() const
25 return pimpl_->get_name();
28 const char* Disk::get_cname() const
30 return pimpl_->get_cname();
33 Disk* Disk::set_read_bandwidth(double read_bw)
35 kernel::actor::simcall([this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
39 Disk* Disk::set_write_bandwidth(double write_bw)
41 kernel::actor::simcall([this, write_bw] { pimpl_->set_write_bandwidth(write_bw); });
45 double Disk::get_read_bandwidth() const
47 return pimpl_->get_read_bandwidth();
50 Disk* Disk::set_readwrite_bandwidth(double bw)
52 kernel::actor::simcall([this, bw] { pimpl_->set_readwrite_bandwidth(bw); });
56 double Disk::get_write_bandwidth() const
58 return pimpl_->get_write_bandwidth();
61 Disk* Disk::set_host(Host* host)
63 pimpl_->set_host(host);
67 Host* Disk::get_host() const
69 return pimpl_->get_host();
72 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
74 return pimpl_->get_properties();
77 const char* Disk::get_property(const std::string& key) const
79 return pimpl_->get_property(key);
82 Disk* Disk::set_property(const std::string& key, const std::string& value)
84 kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
88 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
90 kernel::actor::simcall([this, properties] { this->pimpl_->set_properties(properties); });
94 Disk* Disk::set_state_profile(kernel::profile::Profile* profile)
96 xbt_assert(not pimpl_->is_sealed(), "Cannot set a state profile once the Disk is sealed");
97 kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
101 Disk* Disk::set_read_bandwidth_profile(kernel::profile::Profile* profile)
103 xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
104 kernel::actor::simcall([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([this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); });
115 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
117 return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
120 IoPtr Disk::read_async(sg_size_t size) const
122 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
125 sg_size_t Disk::read(sg_size_t size) const
127 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
130 IoPtr Disk::write_async(sg_size_t size) const
132 return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
135 sg_size_t Disk::write(sg_size_t size) const
137 return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
140 Disk* Disk::set_sharing_policy(Disk::Operation op, Disk::SharingPolicy policy, const NonLinearResourceCb& cb)
142 kernel::actor::simcall([this, op, policy, &cb] { pimpl_->set_sharing_policy(op, policy, cb); });
146 Disk::SharingPolicy Disk::get_sharing_policy(Operation op) const
148 return this->pimpl_->get_sharing_policy(op);
151 Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
153 kernel::actor::simcall([this, &cb] { pimpl_->set_factor_cb(cb); });
159 kernel::actor::simcall([this]{ pimpl_->seal(); });
160 Disk::on_creation(*this);
164 } // namespace simgrid
166 /* **************************** Public C interface *************************** */
168 const char* sg_disk_get_name(const_sg_disk_t disk)
170 return disk->get_cname();
173 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
175 return disk->get_host();
178 double sg_disk_read_bandwidth(const_sg_disk_t disk)
180 return disk->get_read_bandwidth();
183 double sg_disk_write_bandwidth(const_sg_disk_t disk)
185 return disk->get_write_bandwidth();
188 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
190 return disk->read(size);
192 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
194 return disk->write(size);
197 void* sg_disk_get_data(const_sg_disk_t disk)
199 return disk->get_data();
202 void sg_disk_set_data(sg_disk_t disk, void* data)
204 disk->set_data(data);