Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:mquinson/simgrid
[simgrid.git] / src / surf / host_interface.hpp
1 /* Copyright (c) 2004-2014. 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
12 #ifndef SURF_HOST_INTERFACE_HPP_
13 #define SURF_HOST_INTERFACE_HPP_
14
15 /***********
16  * Classes *
17  ***********/
18
19 class HostModel;
20 typedef HostModel *HostModelPtr;
21
22 class Host;
23 typedef Host *HostPtr;
24
25 class HostAction;
26 typedef HostAction *HostActionPtr;
27
28 /*************
29  * Callbacks *
30  *************/
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks handler which emit the callbacks after Host creation *
34  * @details Callback functions have the following signature: `void(HostPtr)`
35  */
36 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks handler which emit the callbacks after Host destruction *
40  * @details Callback functions have the following signature: `void(HostPtr)`
41  */
42 XBT_PUBLIC_DATA(surf_callback(void, HostPtr)) hostDestructedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks handler which emit the callbacks after Host State changed *
46  * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
47  */
48 XBT_PUBLIC_DATA(surf_callback(void, HostPtr, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
49
50 /** @ingroup SURF_callbacks
51  * @brief Callbacks handler which emit the callbacks after HostAction State changed *
52  * @details Callback functions have the following signature: `void(HostActionPtr action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
53  */
54 XBT_PUBLIC_DATA(surf_callback(void, HostActionPtr, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
55
56 /*********
57  * Tools *
58  *********/
59 XBT_PUBLIC_DATA(HostModelPtr) surf_host_model;
60 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
61 XBT_PUBLIC(void) host_add_traces();
62
63 /*********
64  * Model *
65  *********/
66 /** @ingroup SURF_host_interface
67  * @brief SURF Host model interface class
68  * @details A model is an object which handle the interactions between its Resources and its Actions
69  */
70 class HostModel : public Model {
71 public:
72     /**
73    * @brief HostModel constructor
74    *
75    * @param name the name of the model
76    */
77   HostModel(const char *name);
78
79   /** @brief HostModel constructor */
80   HostModel();
81
82   /** @brief HostModel destructor */
83   ~HostModel();
84
85   virtual HostPtr createHost(const char *name)=0;
86   void addTraces(){DIE_IMPOSSIBLE;}
87
88   /**
89    * @brief [brief description]
90    * @details [long description]
91    */
92   virtual void adjustWeightOfDummyCpuActions();
93
94   /**
95    * @brief [brief description]
96    * @details [long description]
97    *
98    * @param host_nb [description]
99    * @param host_list [description]
100    * @param flops_amount [description]
101    * @param bytes_amount [description]
102    * @param rate [description]
103    * @return [description]
104    */
105   virtual ActionPtr executeParallelTask(int host_nb,
106                                         void **host_list,
107                                         double *flops_amount,
108                                         double *bytes_amount,
109                                         double rate)=0;
110
111  /**
112   * @brief [brief description]
113   * @details [long description]
114   *
115   * @param src [description]
116   * @param dst [description]
117   * @param size [description]
118   * @param rate [description]
119   * @return [description]
120   */
121  virtual ActionPtr communicate(HostPtr src, HostPtr dst, double size, double rate)=0;
122
123  CpuModelPtr p_cpuModel;
124 };
125
126 /************
127  * Resource *
128  ************/
129 /** @ingroup SURF_host_interface
130  * @brief SURF Host interface class
131  * @details An host represents a machine with a aggregation of a Cpu, a NetworkLink and a Storage
132  */
133 class Host : public Resource {
134 public:
135   /**
136    * @brief Host constructor
137    *
138    * @param model HostModel associated to this Host
139    * @param name The name of the Host
140    * @param props Dictionary of properties associated to this Host
141    * @param storage The Storage associated to this Host
142    * @param netElm The RoutingEdge associated to this Host
143    * @param cpu The Cpu associated to this Host
144    */
145   Host(ModelPtr model, const char *name, xbt_dict_t props,
146                       xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
147
148   /**
149    * @brief Host constructor
150    *
151    * @param model HostModel associated to this Host
152    * @param name The name of the Host
153    * @param props Dictionary of properties associated to this Host
154    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
155    * @param storage The Storage associated to this Host
156    * @param netElm The RoutingEdge associated to this Host
157    * @param cpu The Cpu associated to this Host
158    */
159   Host(ModelPtr model, const char *name, xbt_dict_t props,
160       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdgePtr netElm,
161       CpuPtr cpu);
162
163   /** @brief Host destructor */
164   ~ Host();
165
166   void setState(e_surf_resource_state_t state);
167
168   /**
169    * @brief Get the properties of the current Host
170    *
171    * @return The properties of the current Host
172    */
173   xbt_dict_t getProperties();
174
175   /**
176    * @brief Execute some quantity of computation
177    *
178    * @param flops_amount The value of the processing amount (in flop) needed to process
179    * @return The CpuAction corresponding to the processing
180    * @see Cpu
181    */
182   virtual ActionPtr execute(double flops_amount)=0;
183
184   /**
185    * @brief Make a process sleep for duration seconds
186    *
187    * @param duration The number of seconds to sleep
188    * @return The CpuAction corresponding to the sleeping
189    * @see Cpu
190    */
191   virtual ActionPtr sleep(double duration)=0;
192
193   /**
194    * @brief Get the number of cores of the associated Cpu
195    *
196    * @return The number of cores of the associated Cpu
197    * @see Cpu
198    */
199   virtual int getCore();
200
201   /**
202    * @brief Get the speed of the associated Cpu
203    *
204    * @param load [TODO]
205    * @return The speed of the associated Cpu
206    * @see Cpu
207    */
208   virtual double getSpeed(double load);
209
210   /**
211    * @brief Get the available speed of the associated Cpu
212    * @details [TODO]
213    *
214    * @return The available speed of the associated Cpu
215    * @see Cpu
216    */
217   virtual double getAvailableSpeed();
218
219   /**
220    * @brief Get the associated Cpu power peak
221    *
222    * @return The associated Cpu power peak
223    * @see Cpu
224    */
225   virtual double getCurrentPowerPeak();
226
227   virtual double getPowerPeakAt(int pstate_index);
228   virtual int getNbPstates();
229   virtual void setPstate(int pstate_index);
230   virtual int  getPstate();
231
232   /**
233    * @brief Return the storage of corresponding mount point
234    *
235    * @param storage The mount point
236    * @return The corresponding Storage
237    */
238   virtual StoragePtr findStorageOnMountList(const char* storage);
239
240   /**
241    * @brief Get the xbt_dict_t of mount_point: Storage
242    *
243    * @return The xbt_dict_t of mount_point: Storage
244    */
245   virtual xbt_dict_t getMountedStorageList();
246
247   /**
248    * @brief Get the xbt_dynar_t of storages attached to the Host
249    *
250    * @return The xbt_dynar_t of Storage names
251    */
252   virtual xbt_dynar_t getAttachedStorageList();
253
254   /**
255    * @brief Open a file
256    *
257    * @param fullpath The full path to the file
258    *
259    * @return The StorageAction corresponding to the opening
260    */
261   virtual ActionPtr open(const char* fullpath);
262
263   /**
264    * @brief Close a file
265    *
266    * @param fd The file descriptor to close
267    * @return The StorageAction corresponding to the closing
268    */
269   virtual ActionPtr close(surf_file_t fd);
270
271   /**
272    * @brief Unlink a file
273    * @details [long description]
274    *
275    * @param fd [description]
276    * @return [description]
277    */
278   virtual int unlink(surf_file_t fd);
279
280   /**
281    * @brief Get the size in bytes of the file
282    *
283    * @param fd The file descriptor to read
284    * @return The size in bytes of the file
285    */
286   virtual sg_size_t getSize(surf_file_t fd);
287
288   /**
289    * @brief Read a file
290    *
291    * @param fd The file descriptor to read
292    * @param size The size in bytes to read
293    * @return The StorageAction corresponding to the reading
294    */
295   virtual ActionPtr read(surf_file_t fd, sg_size_t size);
296
297   /**
298    * @brief Write a file
299    *
300    * @param fd The file descriptor to write
301    * @param size The size in bytes to write
302    * @return The StorageAction corresponding to the writing
303    */
304   virtual ActionPtr write(surf_file_t fd, sg_size_t size);
305
306   /**
307    * @brief Get the informations of a file descriptor
308    * @details The returned xbt_dynar_t contains:
309    *  - the size of the file,
310    *  - the mount point,
311    *  - the storage name,
312    *  - the storage typeId,
313    *  - the storage content type
314    *
315    * @param fd The file descriptor
316    * @return An xbt_dynar_t with the file informations
317    */
318   virtual xbt_dynar_t getInfo(surf_file_t fd);
319
320   /**
321    * @brief Get the current position of the file descriptor
322    *
323    * @param fd The file descriptor
324    * @return The current position of the file descriptor
325    */
326   virtual sg_size_t fileTell(surf_file_t fd);
327
328   /**
329    * @brief Set the position indicator associated with the file descriptor to a new position
330    * @details [long description]
331    *
332    * @param fd The file descriptor
333    * @param offset The offset from the origin
334    * @param origin Position used as a reference for the offset
335    *  - SEEK_SET: beginning of the file
336    *  - SEEK_CUR: current position indicator
337    *  - SEEK_END: end of the file
338    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
339    */
340   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
341
342   /**
343    * @brief Move a file to another location on the *same mount point*.
344    * @details [long description]
345    *
346    * @param fd The file descriptor
347    * @param fullpath The new full path
348    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
349    * full path is not on the same mount point
350    */
351   virtual int fileMove(surf_file_t fd, const char* fullpath);
352
353   xbt_dynar_t p_storage;
354   RoutingEdgePtr p_netElm;
355   CpuPtr p_cpu;
356   NetworkLinkPtr p_network;
357
358   /**
359    * @brief Get the list of virtual machines on the current Host
360    *
361    * @return The list of VMs
362    */
363   xbt_dynar_t getVms();
364
365   /* common with vm */
366   /**
367    * @brief [brief description]
368    * @details [long description]
369    *
370    * @param params [description]
371    */
372   void getParams(ws_params_t params);
373
374   /**
375    * @brief [brief description]
376    * @details [long description]
377    *
378    * @param params [description]
379    */
380   void setParams(ws_params_t params);
381   s_ws_params_t p_params;
382 };
383
384 /**********
385  * Action *
386  **********/
387
388 /** @ingroup SURF_host_interface
389  * @brief SURF host action interface class
390  */
391 class HostAction : public Action {
392 public:
393   /**
394    * @brief HostAction constructor
395    *
396    * @param model The HostModel associated to this HostAction
397    * @param cost The cost of this HostAction in [TODO]
398    * @param failed [description]
399    */
400   HostAction(ModelPtr model, double cost, bool failed)
401   : Action(model, cost, failed) {}
402
403   /**
404    * @brief HostAction constructor
405    *
406    * @param model The HostModel associated to this HostAction
407    * @param cost The cost of this HostAction in [TODO]
408    * @param failed [description]
409    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
410    */
411   HostAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
412   : Action(model, cost, failed, var) {}
413
414   void setState(e_surf_action_state_t state);
415 };
416
417
418 #endif /* SURF_Host_INTERFACE_HPP_ */