Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add Profile support for Disk
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019-2021. 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/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"
12
13 namespace simgrid {
14
15 template class xbt::Extendable<s4u::Disk>;
16
17 namespace s4u {
18
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;
22
23 const std::string& Disk::get_name() const
24 {
25   return pimpl_->get_name();
26 }
27
28 const char* Disk::get_cname() const
29 {
30   return pimpl_->get_cname();
31 }
32
33 Disk* Disk::set_read_bandwidth(double read_bw)
34 {
35   kernel::actor::simcall([this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
36   return this;
37 }
38
39 Disk* Disk::set_write_bandwidth(double write_bw)
40 {
41   kernel::actor::simcall([this, write_bw] { pimpl_->set_write_bandwidth(write_bw); });
42   return this;
43 }
44
45 double Disk::get_read_bandwidth() const
46 {
47   return pimpl_->get_read_bandwidth();
48 }
49
50 double Disk::get_write_bandwidth() const
51 {
52   return pimpl_->get_write_bandwidth();
53 }
54
55 Disk* Disk::set_host(Host* host)
56 {
57   pimpl_->set_host(host);
58   return this;
59 }
60
61 Host* Disk::get_host() const
62 {
63   return pimpl_->get_host();
64 }
65
66 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
67 {
68   return pimpl_->get_properties();
69 }
70
71 const char* Disk::get_property(const std::string& key) const
72 {
73   return pimpl_->get_property(key);
74 }
75
76 Disk* Disk::set_property(const std::string& key, const std::string& value)
77 {
78   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
79   return this;
80 }
81
82 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
83 {
84   kernel::actor::simcall([this, properties] { this->pimpl_->set_properties(properties); });
85   return this;
86 }
87
88 Disk* Disk::set_state_profile(kernel::profile::Profile* profile)
89 {
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); });
92   return this;
93 }
94
95 Disk* Disk::set_read_bandwidth_profile(kernel::profile::Profile* profile)
96 {
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); });
99   return this;
100 }
101
102 Disk* Disk::set_write_bandwidth_profile(kernel::profile::Profile* profile)
103 {
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); });
106   return this;
107 }
108
109 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
110 {
111   return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
112 }
113
114 IoPtr Disk::read_async(sg_size_t size) const
115 {
116   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
117 }
118
119 sg_size_t Disk::read(sg_size_t size) const
120 {
121   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
122 }
123
124 IoPtr Disk::write_async(sg_size_t size) const
125 {
126   return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
127 }
128
129 sg_size_t Disk::write(sg_size_t size) const
130 {
131   return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
132 }
133
134 Disk* Disk::seal()
135 {
136   kernel::actor::simcall([this]{ pimpl_->seal(); });
137   Disk::on_creation(*this);
138   return this;
139 }
140 } // namespace s4u
141 } // namespace simgrid
142
143 /* **************************** Public C interface *************************** */
144
145 const char* sg_disk_get_name(const_sg_disk_t disk)
146 {
147   return disk->get_cname();
148 }
149
150 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
151 {
152   return disk->get_host();
153 }
154
155 double sg_disk_read_bandwidth(const_sg_disk_t disk)
156 {
157   return disk->get_read_bandwidth();
158 }
159
160 double sg_disk_write_bandwidth(const_sg_disk_t disk)
161 {
162   return disk->get_write_bandwidth();
163 }
164
165 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
166 {
167   return disk->read(size);
168 }
169 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
170 {
171   return disk->write(size);
172 }
173
174 void* sg_disk_get_data(const_sg_disk_t disk)
175 {
176   return disk->get_data();
177 }
178
179 void sg_disk_set_data(sg_disk_t disk, void* data)
180 {
181   disk->set_data(data);
182 }