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_
27 /** @ingroup SURF_storage_interface
28 * @brief The possible type of action for the storage component
30 enum e_surf_action_storage_type_t {
31 READ = 0, /**< Read a file */
32 WRITE /**< Write in a file */
39 /** @ingroup SURF_callbacks
40 * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
41 * @details Callback functions have the following signature: `void(StorageAction *action,
42 * simgrid::kernel::resource::Action::State old, simgrid::kernel::resource::Action::State current)`
45 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
51 /** @ingroup SURF_storage_interface
52 * @brief SURF storage model interface class
53 * @details A model is an object which handle the interactions between its Resources and its Actions
55 class StorageModel : public kernel::resource::Model {
60 virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
61 std::string attach) = 0;
67 /** @ingroup SURF_storage_interface
68 * @brief SURF storage interface class
69 * @details A Storage represent a storage unit (e.g.: hard drive, usb key)
71 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
73 /** @brief Storage constructor */
74 StorageImpl(kernel::resource::Model* model, std::string name, kernel::lmm::System* maxmin_system, double bread,
75 double bwrite, std::string type_id, std::string content_name, sg_size_t size, std::string attach);
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(tmgr_trace_event_t 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, e_surf_action_storage_type_t 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,
145 e_surf_action_storage_type_t type)
146 : Action(model, cost, failed), type_(type), storage_(storage){};
149 * @brief StorageAction constructor
151 * @param model The StorageModel associated to this StorageAction
152 * @param cost The cost of this StorageAction in [TODO]
153 * @param failed [description]
154 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
155 * @param storage The Storage associated to this StorageAction
156 * @param type [description]
158 StorageAction(kernel::resource::Model* model, double cost, bool failed, kernel::lmm::Variable* var,
159 StorageImpl* storage, e_surf_action_storage_type_t type)
160 : Action(model, cost, failed, var), type_(type), storage_(storage){};
162 void set_state(simgrid::kernel::resource::Action::State state) override;
164 e_surf_action_storage_type_t type_;
165 StorageImpl* storage_;
173 std::unordered_map<std::string, std::string>* properties;
174 std::unordered_map<std::string, std::string>* model_properties;
176 StorageType(std::string id, std::string model, std::string content,
177 std::unordered_map<std::string, std::string>* properties,
178 std::unordered_map<std::string, std::string>* model_properties, sg_size_t size)
179 : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
186 #endif /* STORAGE_INTERFACE_HPP_ */