Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first compiling version
[simgrid.git] / src / surf / StorageImpl.hpp
1 /* Copyright (c) 2004-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
13
14 #include <map>
15
16 #ifndef STORAGE_INTERFACE_HPP_
17 #define STORAGE_INTERFACE_HPP_
18
19 namespace simgrid {
20 namespace surf {
21
22 /***********
23  * Classes *
24  ***********/
25
26 class StorageAction;
27 /** @ingroup SURF_storage_interface
28  * @brief The possible type of action for the storage component
29  */
30 enum e_surf_action_storage_type_t {
31   READ = 0, /**< Read a file */
32   WRITE     /**< Write in a file */
33 };
34
35 /*************
36  * Callbacks *
37  *************/
38
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)`
43  */
44 XBT_PUBLIC_DATA
45 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
46     on_state_change;
47
48 /*********
49  * Model *
50  *********/
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
54  */
55 class StorageModel : public kernel::resource::Model {
56 public:
57   StorageModel();
58   ~StorageModel();
59
60   virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
61                                      std::string attach) = 0;
62 };
63
64 /************
65  * Resource *
66  ************/
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)
70  */
71 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
72 public:
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);
76
77   ~StorageImpl() override;
78
79   /** @brief Public interface */
80   s4u::Storage piface_;
81
82   /** @brief Check if the Storage is used (if an action currently uses its resources) */
83   bool is_used() override;
84
85   void apply_event(tmgr_trace_event_t event, double value) override;
86
87   void turn_on() override;
88   void turn_off() override;
89
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;
92   /**
93    * @brief Read a file
94    *
95    * @param size The size in bytes to read
96    * @return The StorageAction corresponding to the reading
97    */
98   virtual StorageAction* read(sg_size_t size) = 0;
99
100   /**
101    * @brief Write a file
102    *
103    * @param size The size in bytes to write
104    * @return The StorageAction corresponding to the writing
105    */
106   virtual StorageAction* write(sg_size_t size) = 0;
107   virtual std::string getHost() { return attach_; }
108
109   kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
110   kernel::lmm::Constraint* constraintRead_;  /* Constraint for maximum write bandwidth*/
111
112   std::string typeId_;
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
115
116 private:
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.
120   std::string attach_;
121 };
122
123 /**********
124  * Action *
125  **********/
126
127 /** @ingroup SURF_storage_interface
128  * @brief SURF storage action interface class
129  */
130 class StorageAction : public kernel::resource::Action {
131 public:
132   static xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
133       on_state_change;
134
135   /**
136    * @brief StorageAction constructor
137    *
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]
143    */
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){};
147
148   /**
149  * @brief StorageAction constructor
150  *
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]
157  */
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){};
161
162   void set_state(simgrid::kernel::resource::Action::State state) override;
163
164   e_surf_action_storage_type_t type_;
165   StorageImpl* storage_;
166 };
167
168 class StorageType {
169 public:
170   std::string id;
171   std::string model;
172   std::string content;
173   std::unordered_map<std::string, std::string>* properties;
174   std::unordered_map<std::string, std::string>* model_properties;
175   sg_size_t size;
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)
180   {
181   }
182 };
183 }
184 }
185
186 #endif /* STORAGE_INTERFACE_HPP_ */