1 /* Copyright (c) 2004-2018. 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/Storage.hpp"
10 #include "src/surf/PropertyHolder.hpp"
11 #include "src/surf/trace_mgr.hpp"
12 #include "surf_interface.hpp"
16 #ifndef STORAGE_INTERFACE_HPP_
17 #define STORAGE_INTERFACE_HPP_
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
34 * @details Callback functions have the following signature: `void(StorageAction *action,
35 * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
38 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
44 /** @ingroup SURF_storage_interface
45 * @brief SURF storage model interface class
46 * @details A model is an object which handle the interactions between its Resources and its Actions
48 class StorageModel : public kernel::resource::Model {
53 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
54 std::string attach) = 0;
60 /** @ingroup SURF_storage_interface
61 * @brief SURF storage interface class
62 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
64 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
66 /** @brief Storage constructor */
67 StorageImpl(kernel::resource::Model* model, std::string name, kernel::lmm::System* maxmin_system, double bread,
68 double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach);
70 ~StorageImpl() override;
72 /** @brief Public interface */
75 /** @brief Check if the Storage is used (if an action currently uses its resources) */
76 bool is_used() override;
78 void apply_event(tmgr_trace_event_t event, double value) override;
80 void turn_on() override;
81 void turn_off() override;
83 void destroy(); // Must be called instead of the destructor
88 * @param size The size in bytes to read
89 * @return The StorageAction corresponding to the reading
91 virtual StorageAction* read(sg_size_t size) = 0;
96 * @param size The size in bytes to write
97 * @return The StorageAction corresponding to the writing
99 virtual StorageAction* write(sg_size_t size) = 0;
100 virtual std::string getHost() { return attach_; }
102 kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
103 kernel::lmm::Constraint* constraintRead_; /* Constraint for maximum write bandwidth*/
106 std::string content_name; // Only used at parsing time then goes to the FileSystemExtension
107 sg_size_t size_; // Only used at parsing time then goes to the FileSystemExtension
110 bool currentlyDestroying_ = false;
111 // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
112 // the Host directly.
120 /** @ingroup SURF_storage_interface
121 * @brief The possible type of action for the storage component
123 enum e_surf_action_storage_type_t {
124 READ = 0, /**< Read a file */
125 WRITE /**< Write in a file */
128 /** @ingroup SURF_storage_interface
129 * @brief SURF storage action interface class
131 class StorageAction : public kernel::resource::Action {
133 static xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
137 * @brief StorageAction constructor
139 * @param model The StorageModel associated to this StorageAction
140 * @param cost The cost of this StorageAction in bytes
141 * @param failed [description]
142 * @param storage The Storage associated to this StorageAction
143 * @param type [description]
145 StorageAction(kernel::resource::Model* model, double cost, bool failed, StorageImpl* storage,
146 e_surf_action_storage_type_t type)
147 : Action(model, cost, failed), type_(type), storage_(storage){};
150 * @brief StorageAction constructor
152 * @param model The StorageModel associated to this StorageAction
153 * @param cost The cost of this StorageAction in [TODO]
154 * @param failed [description]
155 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
156 * @param storage The Storage associated to this StorageAction
157 * @param type [description]
159 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
160 StorageImpl* storage, e_surf_action_storage_type_t type)
161 : Action(model, cost, failed, var), type_(type), storage_(storage){};
163 void set_state(simgrid::kernel::resource::Action::State state) override;
165 e_surf_action_storage_type_t type_;
166 StorageImpl* storage_;
174 std::unordered_map<std::string, std::string>* properties;
175 std::unordered_map<std::string, std::string>* model_properties;
177 StorageType(std::string id, std::string model, std::string content,
178 std::unordered_map<std::string, std::string>* properties,
179 std::unordered_map<std::string, std::string>* model_properties, sg_size_t size)
180 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
187 #endif /* STORAGE_INTERFACE_HPP_ */