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/kernel/resource/Action.hpp"
7 #include "simgrid/kernel/resource/Model.hpp"
8 #include "simgrid/kernel/resource/Resource.hpp"
9 #include "simgrid/s4u/Disk.hpp"
10 #include "simgrid/s4u/Io.hpp"
11 #include "src/surf/surf_interface.hpp"
12 #include <xbt/PropertyHolder.hpp>
16 #ifndef DISK_INTERFACE_HPP_
17 #define DISK_INTERFACE_HPP_
35 class DiskModel : public Model {
37 explicit DiskModel(const std::string& name);
38 DiskModel(const DiskModel&) = delete;
39 DiskModel& operator=(const DiskModel&) = delete;
41 virtual DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) = 0;
43 virtual DiskAction* io_start(const DiskImpl* disk, sg_size_t size, s4u::Io::OpType type) = 0;
49 class DiskImpl : public Resource_T<DiskImpl>, public xbt::PropertyHolder {
51 s4u::Host* host_ = nullptr;
52 lmm::Constraint* constraint_write_ = nullptr; /* Constraint for maximum write bandwidth*/
53 lmm::Constraint* constraint_read_ = nullptr; /* Constraint for maximum read bandwidth*/
54 std::unordered_map<s4u::Disk::Operation, s4u::Disk::SharingPolicy> sharing_policy_ = {
55 {s4u::Disk::Operation::READ, s4u::Disk::SharingPolicy::LINEAR},
56 {s4u::Disk::Operation::WRITE, s4u::Disk::SharingPolicy::LINEAR},
57 {s4u::Disk::Operation::READWRITE, s4u::Disk::SharingPolicy::LINEAR}};
58 std::unordered_map<s4u::Disk::Operation, s4u::NonLinearResourceCb> sharing_policy_cb_ = {};
60 void apply_sharing_policy_cfg();
63 ~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
66 Metric read_bw_ = {0.0, 0, nullptr};
67 Metric write_bw_ = {0.0, 0, nullptr};
69 explicit DiskImpl(const std::string& name, double read_bandwidth, double write_bandwidth);
70 DiskImpl(const DiskImpl&) = delete;
71 DiskImpl& operator=(const DiskImpl&) = delete;
73 /** @brief Public interface */
74 const s4u::Disk* get_iface() const { return &piface_; }
75 s4u::Disk* get_iface() { return &piface_; }
76 DiskImpl* set_host(s4u::Host* host);
77 s4u::Host* get_host() const { return host_; }
79 virtual void set_read_bandwidth(double read_bw) = 0;
80 double get_read_bandwidth() const { return read_bw_.peak * read_bw_.scale; }
82 virtual void set_write_bandwidth(double write_bw) = 0;
83 double get_write_bandwidth() const { return write_bw_.peak * write_bw_.scale; }
85 DiskImpl* set_read_constraint(lmm::Constraint* constraint_read);
86 lmm::Constraint* get_read_constraint() const { return constraint_read_; }
88 DiskImpl* set_write_constraint(lmm::Constraint* constraint_write);
89 lmm::Constraint* get_write_constraint() const { return constraint_write_; }
91 DiskImpl* set_read_bandwidth_profile(profile::Profile* profile);
92 DiskImpl* set_write_bandwidth_profile(profile::Profile* profile);
94 void set_sharing_policy(s4u::Disk::Operation op, s4u::Disk::SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
95 s4u::Disk::SharingPolicy get_sharing_policy(s4u::Disk::Operation op) const;
97 /** @brief Check if the Disk is used (if an action currently uses its resources) */
98 bool is_used() const override;
99 void turn_on() override;
100 void turn_off() override;
102 void seal() override;
103 void destroy(); // Must be called instead of the destructor
110 class DiskAction : public Action {
112 static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
114 using Action::Action;
115 void set_state(simgrid::kernel::resource::Action::State state) override;
117 double sharing_penalty_ = {};
120 } // namespace resource
121 } // namespace kernel
122 } // namespace simgrid
123 #endif /* DISK_INTERFACE_HPP_ */