1 /* Copyright (c) 2019. 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/PropertyHolder.hpp"
12 #include "src/surf/surf_interface.hpp"
16 #ifndef DISK_INTERFACE_HPP_
17 #define DISK_INTERFACE_HPP_
23 XBT_PUBLIC_DATA simgrid::kernel::resource::DiskModel* surf_disk_model;
37 class DiskModel : public kernel::resource::Model {
40 DiskModel(const DiskModel&) = delete;
41 DiskModel& operator=(const DiskModel&) = delete;
44 virtual DiskImpl* createDisk(const std::string& id, double read_bw, double write_bw) = 0;
50 class DiskImpl : public Resource, public surf::PropertyHolder {
51 bool currently_destroying_ = false;
52 s4u::Host* host_ = nullptr;
55 DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
56 DiskImpl(const DiskImpl&) = delete;
57 DiskImpl& operator=(const DiskImpl&) = delete;
61 /** @brief Public interface */
63 s4u::Disk* get_iface() { return &piface_; }
64 /** @brief Check if the Storage is used (if an action currently uses its resources) */
65 bool is_used() override;
67 void apply_event(profile::Event* event, double value) override;
69 void turn_on() override;
70 void turn_off() override;
72 s4u::Host* get_host() { return host_; }
73 void set_host(s4u::Host* host) { host_ = host; }
75 void destroy(); // Must be called instead of the destructor
76 virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
77 virtual DiskAction* read(sg_size_t size) = 0;
78 virtual DiskAction* write(sg_size_t size) = 0;
80 lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
81 lmm::Constraint* constraint_read_; /* Constraint for maximum write bandwidth*/
88 class DiskAction : public Action {
90 static xbt::signal<void(DiskAction const&, Action::State, Action::State)> on_state_change;
92 DiskAction(Model* model, double cost, bool failed, DiskImpl* disk, s4u::Io::OpType type)
93 : Action(model, cost, failed), type_(type), disk_(disk){};
96 * @brief diskAction constructor
98 * @param model The StorageModel associated to this DiskAction
99 * @param cost The cost of this DiskAction in bytes
100 * @param failed [description]
101 * @param var The lmm variable associated to this DiskAction if it is part of a LMM component
102 * @param storage The Storage associated to this DiskAction
103 * @param type [description]
105 DiskAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var, DiskImpl* disk,
106 s4u::Io::OpType type)
107 : Action(model, cost, failed, var), type_(type), disk_(disk){};
109 void set_state(simgrid::kernel::resource::Action::State state) override;
111 s4u::Io::OpType type_;
115 } // namespace resource
116 } // namespace kernel
117 } // namespace simgrid
118 #endif /* DISK_INTERFACE_HPP_ */