Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
attempt to fully trace ptasks
[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
28 /*************
29  * Callbacks *
30  *************/
31
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)`
36  */
37 XBT_PUBLIC_DATA
38 simgrid::xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
39     on_state_change;
40
41 /*********
42  * Model *
43  *********/
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
47  */
48 class StorageModel : public kernel::resource::Model {
49 public:
50   StorageModel();
51   ~StorageModel();
52
53   virtual StorageImpl* createStorage(std::string id, std::string type_id, std::string content_name,
54                                      std::string attach) = 0;
55 };
56
57 /************
58  * Resource *
59  ************/
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)
63  */
64 class StorageImpl : public kernel::resource::Resource, public PropertyHolder {
65 public:
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);
69
70   ~StorageImpl() override;
71
72   /** @brief Public interface */
73   s4u::Storage piface_;
74
75   /** @brief Check if the Storage is used (if an action currently uses its resources) */
76   bool is_used() override;
77
78   void apply_event(tmgr_trace_event_t event, double value) override;
79
80   void turn_on() override;
81   void turn_off() override;
82
83   void destroy(); // Must be called instead of the destructor
84
85   /**
86    * @brief Read a file
87    *
88    * @param size The size in bytes to read
89    * @return The StorageAction corresponding to the reading
90    */
91   virtual StorageAction* read(sg_size_t size) = 0;
92
93   /**
94    * @brief Write a file
95    *
96    * @param size The size in bytes to write
97    * @return The StorageAction corresponding to the writing
98    */
99   virtual StorageAction* write(sg_size_t size) = 0;
100   virtual std::string getHost() { return attach_; }
101
102   kernel::lmm::Constraint* constraintWrite_; /* Constraint for maximum write bandwidth*/
103   kernel::lmm::Constraint* constraintRead_;  /* Constraint for maximum write bandwidth*/
104
105   std::string typeId_;
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
108
109 private:
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.
113   std::string attach_;
114 };
115
116 /**********
117  * Action *
118  **********/
119
120 /** @ingroup SURF_storage_interface
121  * @brief The possible type of action for the storage component
122  */
123 enum e_surf_action_storage_type_t {
124   READ = 0, /**< Read a file */
125   WRITE     /**< Write in a file */
126 };
127
128 /** @ingroup SURF_storage_interface
129  * @brief SURF storage action interface class
130  */
131 class StorageAction : public kernel::resource::Action {
132 public:
133   static xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
134       on_state_change;
135
136   /**
137    * @brief StorageAction constructor
138    *
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]
144    */
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){};
148
149   /**
150  * @brief StorageAction constructor
151  *
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]
158  */
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){};
162
163   void set_state(simgrid::kernel::resource::Action::State state) override;
164
165   e_surf_action_storage_type_t type_;
166   StorageImpl* storage_;
167 };
168
169 class StorageType {
170 public:
171   std::string id;
172   std::string model;
173   std::string content;
174   std::unordered_map<std::string, std::string>* properties;
175   std::unordered_map<std::string, std::string>* model_properties;
176   sg_size_t size;
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)
181   {
182   }
183 };
184 }
185 }
186
187 #endif /* STORAGE_INTERFACE_HPP_ */