Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Triggers the destructed callbacks on the full object
[simgrid.git] / src / surf / host_interface.hpp
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "surf_interface.hpp"
8 #include "storage_interface.hpp"
9 #include "cpu_interface.hpp"
10 #include "network_interface.hpp"
11 #include "src/surf/PropertyHolder.hpp"
12
13 #include <xbt/base.h>
14
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
17
18 /***********
19  * Classes *
20  ***********/
21
22 namespace simgrid {
23 namespace surf {
24
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE Host;
27 class XBT_PRIVATE HostAction;
28
29 /*************
30  * Callbacks *
31  *************/
32
33 /** @ingroup SURF_callbacks
34  * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
35  */
36 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
40  */
41 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45  */
46 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
47
48 /** @ingroup SURF_callbacks
49  * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
50  */
51 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
52
53 }
54 }
55
56 /*********
57  * Tools *
58  *********/
59 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
60 XBT_PUBLIC(void) host_add_traces();
61
62 /*********
63  * Model *
64  *********/
65
66 namespace simgrid {
67 namespace surf {
68
69 /** @ingroup SURF_host_interface
70  * @brief SURF Host model interface class
71  * @details A model is an object which handle the interactions between its Resources and its Actions
72  */
73 class HostModel : public Model {
74 public:
75   HostModel() : Model() {}
76   ~HostModel() {}
77
78   virtual Host *createHost(const char *name, RoutingEdge *net, Cpu *cpu, xbt_dict_t props)=0;
79   void addTraces(){DIE_IMPOSSIBLE;}
80
81   virtual void adjustWeightOfDummyCpuActions();
82   virtual Action *executeParallelTask(int host_nb,
83                                       sg_host_t *host_list,
84                                                                           double *flops_amount,
85                                                                           double *bytes_amount,
86                                                                           double rate)=0;
87
88   bool shareResourcesIsIdempotent() {return true;}
89 };
90
91 /************
92  * Resource *
93  ************/
94 /** @ingroup SURF_host_interface
95  * @brief SURF Host interface class
96  * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
97  */
98 class Host : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
99 public:
100   static simgrid::xbt::FacetLevel<simgrid::Host, Host> LEVEL;
101   static void init();
102   /**
103    * @brief Host constructor
104    *
105    * @param model HostModel associated to this Host
106    * @param name The name of the Host
107    * @param props Dictionary of properties associated to this Host
108    * @param storage The Storage associated to this Host
109    * @param netElm The RoutingEdge associated to this Host
110    * @param cpu The Cpu associated to this Host
111    */
112   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
113                       xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
114
115   /**
116    * @brief Host constructor
117    *
118    * @param model HostModel associated to this Host
119    * @param name The name of the Host
120    * @param props Dictionary of properties associated to this Host
121    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
122    * @param storage The Storage associated to this Host
123    * @param netElm The RoutingEdge associated to this Host
124    * @param cpu The Cpu associated to this Host
125    */
126   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
127       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
128       Cpu *cpu);
129
130   /** @brief Host destructor */
131   ~Host();
132
133   void attach(simgrid::Host* host);
134   void setState(e_surf_resource_state_t state);
135
136   /**
137    * @brief Execute some quantity of computation
138    *
139    * @param flops_amount The value of the processing amount (in flop) needed to process
140    * @return The CpuAction corresponding to the processing
141    * @see Cpu
142    */
143   virtual Action *execute(double flops_amount)=0;
144
145   /**
146    * @brief Make a process sleep for duration seconds
147    *
148    * @param duration The number of seconds to sleep
149    * @return The CpuAction corresponding to the sleeping
150    * @see Cpu
151    */
152   virtual Action *sleep(double duration)=0;
153
154   /** @brief Return the storage of corresponding mount point */
155   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
156
157   /** @brief Get the xbt_dict_t of mount_point: Storage */
158   virtual xbt_dict_t getMountedStorageList();
159
160   /** @brief Get the xbt_dynar_t of storages attached to the Host */
161   virtual xbt_dynar_t getAttachedStorageList();
162
163   /**
164    * @brief Open a file
165    *
166    * @param fullpath The full path to the file
167    *
168    * @return The StorageAction corresponding to the opening
169    */
170   virtual Action *open(const char* fullpath);
171
172   /**
173    * @brief Close a file
174    *
175    * @param fd The file descriptor to close
176    * @return The StorageAction corresponding to the closing
177    */
178   virtual Action *close(surf_file_t fd);
179
180   /**
181    * @brief Unlink a file
182    * @details [long description]
183    *
184    * @param fd [description]
185    * @return [description]
186    */
187   virtual int unlink(surf_file_t fd);
188
189   /**
190    * @brief Get the size in bytes of the file
191    *
192    * @param fd The file descriptor to read
193    * @return The size in bytes of the file
194    */
195   virtual sg_size_t getSize(surf_file_t fd);
196
197   /**
198    * @brief Read a file
199    *
200    * @param fd The file descriptor to read
201    * @param size The size in bytes to read
202    * @return The StorageAction corresponding to the reading
203    */
204   virtual Action *read(surf_file_t fd, sg_size_t size);
205
206   /**
207    * @brief Write a file
208    *
209    * @param fd The file descriptor to write
210    * @param size The size in bytes to write
211    * @return The StorageAction corresponding to the writing
212    */
213   virtual Action *write(surf_file_t fd, sg_size_t size);
214
215   /**
216    * @brief Get the informations of a file descriptor
217    * @details The returned xbt_dynar_t contains:
218    *  - the size of the file,
219    *  - the mount point,
220    *  - the storage name,
221    *  - the storage typeId,
222    *  - the storage content type
223    *
224    * @param fd The file descriptor
225    * @return An xbt_dynar_t with the file informations
226    */
227   virtual xbt_dynar_t getInfo(surf_file_t fd);
228
229   /**
230    * @brief Get the current position of the file descriptor
231    *
232    * @param fd The file descriptor
233    * @return The current position of the file descriptor
234    */
235   virtual sg_size_t fileTell(surf_file_t fd);
236
237   /**
238    * @brief Set the position indicator associated with the file descriptor to a new position
239    * @details [long description]
240    *
241    * @param fd The file descriptor
242    * @param offset The offset from the origin
243    * @param origin Position used as a reference for the offset
244    *  - SEEK_SET: beginning of the file
245    *  - SEEK_CUR: current position indicator
246    *  - SEEK_END: end of the file
247    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
248    */
249   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
250
251   /**
252    * @brief Move a file to another location on the *same mount point*.
253    * @details [long description]
254    *
255    * @param fd The file descriptor
256    * @param fullpath The new full path
257    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
258    * full path is not on the same mount point
259    */
260   virtual int fileMove(surf_file_t fd, const char* fullpath);
261
262 protected:
263   void onDie() override;
264
265 public:
266   xbt_dynar_t p_storage;
267   RoutingEdge *p_netElm;
268   Cpu *p_cpu;
269   simgrid::Host* p_host = nullptr;
270
271   /** @brief Get the list of virtual machines on the current Host */
272   xbt_dynar_t getVms();
273
274   /* common with vm */
275   /** @brief Retrieve a copy of the parameters of that VM/PM
276    *  @details The ramsize and overcommit fields are used on the PM too */
277   void getParams(vm_params_t params);
278   /** @brief Sets the params of that VM/PM */
279   void setParams(vm_params_t params);
280   simgrid::Host* getHost() { return p_host; }
281 private:
282   s_vm_params_t p_params;
283 };
284
285 /**********
286  * Action *
287  **********/
288
289 /** @ingroup SURF_host_interface
290  * @brief SURF host action interface class
291  */
292 class HostAction : public Action {
293 public:
294   /**
295    * @brief HostAction constructor
296    *
297    * @param model The HostModel associated to this HostAction
298    * @param cost The cost of this HostAction in [TODO]
299    * @param failed [description]
300    */
301   HostAction(simgrid::surf::Model *model, double cost, bool failed)
302   : Action(model, cost, failed) {}
303
304   /**
305    * @brief HostAction constructor
306    *
307    * @param model The HostModel associated to this HostAction
308    * @param cost The cost of this HostAction in [TODO]
309    * @param failed [description]
310    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
311    */
312   HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
313   : Action(model, cost, failed, var) {}
314
315   void setState(e_surf_action_state_t state);
316 };
317
318 }
319 }
320
321 #endif /* SURF_Host_INTERFACE_HPP_ */