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 double Disk::get_write_bandwidth() const
52 return pimpl_->get_write_bandwidth();
55 Disk* Disk::set_host(Host* host)
57 pimpl_->set_host(host);
61 Host* Disk::get_host() const
63 return pimpl_->get_host();
66 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
68 return pimpl_->get_properties();
71 const char* Disk::get_property(const std::string& key) const
73 return pimpl_->get_property(key);
76 Disk* Disk::set_property(const std::string& key, const std::string& value)
78 kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
82 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
84 kernel::actor::simcall([this, properties] { this->pimpl_->set_properties(properties); });
88 Disk* Disk::set_state_profile(kernel::profile::Profile* profile)
90 xbt_assert(not pimpl_->is_sealed(), "Cannot set a state profile once the Disk is sealed");
91 kernel::actor::simcall([this, profile]() { this->pimpl_->set_state_profile(profile); });
95 Disk* Disk::set_read_bandwidth_profile(kernel::profile::Profile* profile)
97 xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
98 kernel::actor::simcall([this, profile]() { this->pimpl_->set_read_bandwidth_profile(profile); });
102 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
104 xbt_assert(not pimpl_->is_sealed(), "Cannot set a bandwidth profile once the Disk is sealed");
105 kernel::actor::simcall([this, profile]() { this->pimpl_->set_write_bandwidth_profile(profile); });
109 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
111 return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
114 IoPtr Disk::read_async(sg_size_t size) const
116 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
119 sg_size_t Disk::read(sg_size_t size) const
121 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
124 IoPtr Disk::write_async(sg_size_t size) const
126 return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
129 sg_size_t Disk::write(sg_size_t size) const
131 return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
136 kernel::actor::simcall([this]{ pimpl_->seal(); });
137 Disk::on_creation(*this);
141 } // namespace simgrid
143 /* **************************** Public C interface *************************** */
145 const char* sg_disk_get_name(const_sg_disk_t disk)
147 return disk->get_cname();
150 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
152 return disk->get_host();
155 double sg_disk_read_bandwidth(const_sg_disk_t disk)
157 return disk->get_read_bandwidth();
160 double sg_disk_write_bandwidth(const_sg_disk_t disk)
162 return disk->get_write_bandwidth();
165 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
167 return disk->read(size);
169 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
171 return disk->write(size);
174 void* sg_disk_get_data(const_sg_disk_t disk)
176 return disk->get_data();
179 void sg_disk_set_data(sg_disk_t disk, void* data)
181 disk->set_data(data);