1 /* Copyright (c) 2004-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/Io.hpp"
10 #include "simgrid/s4u/Storage.hpp"
11 #include "src/kernel/resource/profile/trace_mgr.hpp"
12 #include "src/surf/PropertyHolder.hpp"
13 #include "surf_interface.hpp"
17 #ifndef STORAGE_INTERFACE_HPP_
18 #define STORAGE_INTERFACE_HPP_
28 /** @ingroup SURF_storage_interface
29 * @brief The possible type of action for the storage component
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
37 * @details Callback functions have the following signature: `void(StorageAction *action,
38 * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
41 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
47 /** @ingroup SURF_storage_interface
48 * @brief SURF storage model interface class
49 * @details A model is an object which handle the interactions between its Resources and its Actions
51 class StorageModel : public kernel::resource::Model {
54 StorageModel(const StorageModel&) = delete;
55 StorageModel& operator=(const StorageModel&) = delete;
58 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
59 std::string attach) = 0;
65 /** @ingroup SURF_storage_interface
66 * @brief SURF storage interface class
67 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
69 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
71 /** @brief Storage constructor */
72 StorageImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double bread,
73 double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach);
74 StorageImpl(const StorageImpl&) = delete;
75 StorageImpl& operator=(const StorageImpl&) = delete;
77 ~StorageImpl() override;
79 /** @brief Public interface */
82 /** @brief Check if the Storage is used (if an action currently uses its resources) */
83 bool is_used() override;
85 void apply_event(simgrid::kernel::profile::Event* event, double value) override;
87 void turn_on() override;
88 void turn_off() override;
90 void destroy(); // Must be called instead of the destructor
91 virtual simgrid::kernel::resource::Action* io_start(sg_size_t size, s4u::Io::OpType type) = 0;
95 * @param size The size in bytes to read
96 * @return The StorageAction corresponding to the reading
98 virtual StorageAction* read(sg_size_t size) = 0;
101 * @brief Write a file
103 * @param size The size in bytes to write
104 * @return The StorageAction corresponding to the writing
106 virtual StorageAction* write(sg_size_t size) = 0;
107 virtual std::string getHost() { return attach_; }
109 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
110 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
113 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
114 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
117 bool currentlyDestroying_ = false;
118 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
119 // the Host directly.
127 /** @ingroup SURF_storage_interface
128 * @brief SURF storage action interface class
130 class StorageAction : public kernel::resource::Action {
132 static xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
136 * @brief StorageAction constructor
138 * @param model The StorageModel associated to this StorageAction
139 * @param cost The cost of this StorageAction in bytes
140 * @param failed [description]
141 * @param storage The Storage associated to this StorageAction
142 * @param type [description]
144 StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage, s4u::Io::OpType type)
145 : Action(model, cost, failed), type_(type), storage_(storage){};
148 * @brief StorageAction constructor
150 * @param model The StorageModel associated to this StorageAction
151 * @param cost The cost of this StorageAction in [TODO]
152 * @param failed [description]
153 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
154 * @param storage The Storage associated to this StorageAction
155 * @param type [description]
157 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
158 StorageImpl* storage, s4u::Io::OpType type)
159 : Action(model, cost, failed, var), type_(type), storage_(storage){};
161 void set_state(simgrid::kernel::resource::Action::State state) override;
163 s4u::Io::OpType type_;
164 StorageImpl* storage_;
172 std::unordered_map<std::string, std::string>* properties;
173 std::unordered_map<std::string, std::string>* model_properties;
175 StorageType(std::string id, std::string model, std::string content,
176 std::unordered_map<std::string, std::string>* properties,
177 std::unordered_map<std::string, std::string>* model_properties, sg_size_t size)
179 , model(std::move(model))
180 , content(std::move(content))
181 , properties(properties)
182 , model_properties(model_properties)
190 #endif /* STORAGE_INTERFACE_HPP_ */