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 {
38 DiskModel(const DiskModel&) = delete;
39 DiskModel& operator=(const DiskModel&) = delete;
40 ~DiskModel() = default;
42 virtual DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) = 0;
48 class DiskImpl : public Resource_T<DiskImpl>, public xbt::PropertyHolder {
49 s4u::Host* host_ = nullptr;
51 double read_bw_ = -1.0;
52 double write_bw_ = 1.0;
53 lmm::Constraint* constraint_write_ = nullptr; /* Constraint for maximum write bandwidth*/
54 lmm::Constraint* constraint_read_ = nullptr; /* Constraint for maximum read bandwidth*/
57 ~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
60 DiskImpl(const std::string& name, double read_bandwidth, double write_bandwidth)
61 : Resource_T(name), piface_(name, this), read_bw_(read_bandwidth), write_bw_(write_bandwidth)
64 DiskImpl(const DiskImpl&) = delete;
65 DiskImpl& operator=(const DiskImpl&) = delete;
67 /** @brief Public interface */
68 const s4u::Disk* get_iface() const { return &piface_; }
69 s4u::Disk* get_iface() { return &piface_; }
70 DiskImpl* set_host(s4u::Host* host);
71 s4u::Host* get_host() const { return host_; }
73 DiskImpl* set_read_bandwidth(double read_bw);
74 double get_read_bandwidth() const { return read_bw_; }
76 DiskImpl* set_write_bandwidth(double write_bw);
77 double get_write_bandwidth() const { return write_bw_; }
79 DiskImpl* set_read_constraint(lmm::Constraint* constraint_read);
80 lmm::Constraint* get_read_constraint() const { return constraint_read_; }
82 DiskImpl* set_write_constraint(lmm::Constraint* constraint_write);
83 lmm::Constraint* get_write_constraint() const { return constraint_write_; }
85 /** @brief Check if the Disk is used (if an action currently uses its resources) */
86 bool is_used() const override;
87 void apply_event(profile::Event* event, double value) override;
88 void turn_on() override;
89 void turn_off() override;
92 void destroy(); // Must be called instead of the destructor
93 virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
94 virtual DiskAction* read(sg_size_t size) = 0;
95 virtual DiskAction* write(sg_size_t size) = 0;
102 class DiskAction : public Action {
104 static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
106 DiskAction(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
107 : Action(model, cost, failed), type_(type), disk_(disk){};
110 * @brief diskAction constructor
112 * @param model The DiskModel associated to this DiskAction
113 * @param cost The cost of this DiskAction in bytes
114 * @param failed [description]
115 * @param var The lmm variable associated to this DiskAction if it is part of a LMM component
116 * @param disk The Disk associated to this DiskAction
117 * @param type [description]
119 DiskAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var, DiskImpl* disk,
120 s4u::Io::OpType type)
121 : Action(model, cost, failed, var), type_(type), disk_(disk){};
123 void set_state(simgrid::kernel::resource::Action::State state) override;
125 s4u::Io::OpType type_;
129 } // namespace resource
130 } // namespace kernel
131 } // namespace simgrid
132 #endif /* DISK_INTERFACE_HPP_ */