Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-stoprofiles'
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019-2020. 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 double Disk::get_read_bandwidth() const
24 {
25   return this->pimpl_->get_read_bandwidth();
26 }
27
28 double Disk::get_write_bandwidth() const
29 {
30   return pimpl_->get_write_bandwidth();
31 }
32
33 Host* Disk::get_host() const
34 {
35   return pimpl_->get_host();
36 }
37
38 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
39 {
40   return pimpl_->get_properties();
41 }
42
43 const char* Disk::get_property(const std::string& key) const
44 {
45   return this->pimpl_->get_property(key);
46 }
47
48 void Disk::set_property(const std::string& key, const std::string& value)
49 {
50   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
51 }
52
53 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
54 {
55   return IoPtr(new Io(this, size, type));
56 }
57
58 IoPtr Disk::read_async(sg_size_t size)
59 {
60   return IoPtr(io_init(size, Io::OpType::READ))->start();
61 }
62
63 sg_size_t Disk::read(sg_size_t size)
64 {
65   return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
66 }
67
68 IoPtr Disk::write_async(sg_size_t size)
69 {
70   return IoPtr(io_init(size, Io::OpType::WRITE)->start());
71 }
72
73 sg_size_t Disk::write(sg_size_t size)
74 {
75   return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
76 }
77
78 } // namespace s4u
79 } // namespace simgrid
80
81 /* **************************** Public C interface *************************** */
82
83 const char* sg_disk_name(const_sg_disk_t disk)
84 {
85   return disk->get_cname();
86 }
87
88 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
89 {
90   return disk->get_host();
91 }
92
93 double sg_disk_read_bandwidth(const_sg_disk_t disk)
94 {
95   return disk->get_read_bandwidth();
96 }
97
98 double sg_disk_write_bandwidth(const_sg_disk_t disk)
99 {
100   return disk->get_write_bandwidth();
101 }
102
103 sg_size_t sg_disk_read(sg_disk_t disk, sg_size_t size)
104 {
105   return disk->read(size);
106 }
107 sg_size_t sg_disk_write(sg_disk_t disk, sg_size_t size)
108 {
109   return disk->write(size);
110 }
111 void* sg_disk_data(const_sg_disk_t disk)
112 {
113   return disk->get_data();
114 }
115 void sg_disk_data_set(sg_disk_t disk, void* data)
116 {
117   disk->set_data(data);
118 }