Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
less void*, new type: surf_host_t
[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   Host();
139
140   /**
141    * @brief Host constructor
142    *
143    * @param model HostModel associated to this Host
144    * @param name The name of the Host
145    * @param props Dictionary of properties associated to this Host
146    * @param storage The Storage associated to this Host
147    * @param netElm The RoutingEdge associated to this Host
148    * @param cpu The Cpu associated to this Host
149    */
150   Host(ModelPtr model, const char *name, xbt_dict_t props,
151                       xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
152
153   /**
154    * @brief Host constructor
155    *
156    * @param model HostModel associated to this Host
157    * @param name The name of the Host
158    * @param props Dictionary of properties associated to this Host
159    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
160    * @param storage The Storage associated to this Host
161    * @param netElm The RoutingEdge associated to this Host
162    * @param cpu The Cpu associated to this Host
163    */
164   Host(ModelPtr model, const char *name, xbt_dict_t props,
165       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdgePtr netElm,
166       CpuPtr cpu);
167
168   /** @brief Host destructor */
169   ~ Host();
170
171   void setState(e_surf_resource_state_t state);
172
173   /**
174    * @brief Get the properties of the current Host
175    *
176    * @return The properties of the current Host
177    */
178   xbt_dict_t getProperties();
179
180   /**
181    * @brief Execute some quantity of computation
182    *
183    * @param flops_amount The value of the processing amount (in flop) needed to process
184    * @return The CpuAction corresponding to the processing
185    * @see Cpu
186    */
187   virtual ActionPtr execute(double flops_amount)=0;
188
189   /**
190    * @brief Make a process sleep for duration seconds
191    *
192    * @param duration The number of seconds to sleep
193    * @return The CpuAction corresponding to the sleeping
194    * @see Cpu
195    */
196   virtual ActionPtr sleep(double duration)=0;
197
198   /**
199    * @brief Get the number of cores of the associated Cpu
200    *
201    * @return The number of cores of the associated Cpu
202    * @see Cpu
203    */
204   virtual int getCore();
205
206   /**
207    * @brief Get the speed of the associated Cpu
208    *
209    * @param load [TODO]
210    * @return The speed of the associated Cpu
211    * @see Cpu
212    */
213   virtual double getSpeed(double load);
214
215   /**
216    * @brief Get the available speed of the associated Cpu
217    * @details [TODO]
218    *
219    * @return The available speed of the associated Cpu
220    * @see Cpu
221    */
222   virtual double getAvailableSpeed();
223
224   /**
225    * @brief Get the associated Cpu power peak
226    *
227    * @return The associated Cpu power peak
228    * @see Cpu
229    */
230   virtual double getCurrentPowerPeak();
231
232   virtual double getPowerPeakAt(int pstate_index);
233   virtual int getNbPstates();
234   virtual void setPstate(int pstate_index);
235   virtual int  getPstate();
236
237   /**
238    * @brief Return the storage of corresponding mount point
239    *
240    * @param storage The mount point
241    * @return The corresponding Storage
242    */
243   virtual StoragePtr findStorageOnMountList(const char* storage);
244
245   /**
246    * @brief Get the xbt_dict_t of mount_point: Storage
247    *
248    * @return The xbt_dict_t of mount_point: Storage
249    */
250   virtual xbt_dict_t getMountedStorageList();
251
252   /**
253    * @brief Get the xbt_dynar_t of storages attached to the Host
254    *
255    * @return The xbt_dynar_t of Storage names
256    */
257   virtual xbt_dynar_t getAttachedStorageList();
258
259   /**
260    * @brief Open a file
261    *
262    * @param fullpath The full path to the file
263    *
264    * @return The StorageAction corresponding to the opening
265    */
266   virtual ActionPtr open(const char* fullpath);
267
268   /**
269    * @brief Close a file
270    *
271    * @param fd The file descriptor to close
272    * @return The StorageAction corresponding to the closing
273    */
274   virtual ActionPtr close(surf_file_t fd);
275
276   /**
277    * @brief Unlink a file
278    * @details [long description]
279    *
280    * @param fd [description]
281    * @return [description]
282    */
283   virtual int unlink(surf_file_t fd);
284
285   /**
286    * @brief Get the size in bytes of the file
287    *
288    * @param fd The file descriptor to read
289    * @return The size in bytes of the file
290    */
291   virtual sg_size_t getSize(surf_file_t fd);
292
293   /**
294    * @brief Read a file
295    *
296    * @param fd The file descriptor to read
297    * @param size The size in bytes to read
298    * @return The StorageAction corresponding to the reading
299    */
300   virtual ActionPtr read(surf_file_t fd, sg_size_t size);
301
302   /**
303    * @brief Write a file
304    *
305    * @param fd The file descriptor to write
306    * @param size The size in bytes to write
307    * @return The StorageAction corresponding to the writing
308    */
309   virtual ActionPtr write(surf_file_t fd, sg_size_t size);
310
311   /**
312    * @brief Get the informations of a file descriptor
313    * @details The returned xbt_dynar_t contains:
314    *  - the size of the file,
315    *  - the mount point,
316    *  - the storage name,
317    *  - the storage typeId,
318    *  - the storage content type
319    *
320    * @param fd The file descriptor
321    * @return An xbt_dynar_t with the file informations
322    */
323   virtual xbt_dynar_t getInfo(surf_file_t fd);
324
325   /**
326    * @brief Get the current position of the file descriptor
327    *
328    * @param fd The file descriptor
329    * @return The current position of the file descriptor
330    */
331   virtual sg_size_t fileTell(surf_file_t fd);
332
333   /**
334    * @brief Set the position indicator associated with the file descriptor to a new position
335    * @details [long description]
336    *
337    * @param fd The file descriptor
338    * @param offset The offset from the origin
339    * @param origin Position used as a reference for the offset
340    *  - SEEK_SET: beginning of the file
341    *  - SEEK_CUR: current position indicator
342    *  - SEEK_END: end of the file
343    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
344    */
345   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
346
347   /**
348    * @brief Move a file to another location on the *same mount point*.
349    * @details [long description]
350    *
351    * @param fd The file descriptor
352    * @param fullpath The new full path
353    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
354    * full path is not on the same mount point
355    */
356   virtual int fileMove(surf_file_t fd, const char* fullpath);
357
358   xbt_dynar_t p_storage;
359   RoutingEdgePtr p_netElm;
360   CpuPtr p_cpu;
361   NetworkLinkPtr p_network;
362
363   /**
364    * @brief Get the list of virtual machines on the current Host
365    *
366    * @return The list of VMs
367    */
368   xbt_dynar_t getVms();
369
370   /* common with vm */
371   /**
372    * @brief [brief description]
373    * @details [long description]
374    *
375    * @param params [description]
376    */
377   void getParams(ws_params_t params);
378
379   /**
380    * @brief [brief description]
381    * @details [long description]
382    *
383    * @param params [description]
384    */
385   void setParams(ws_params_t params);
386   s_ws_params_t p_params;
387 };
388
389 /**********
390  * Action *
391  **********/
392
393 /** @ingroup SURF_host_interface
394  * @brief SURF host action interface class
395  */
396 class HostAction : public Action {
397 public:
398   /**
399    * @brief HostAction constructor
400    *
401    * @param model The HostModel associated to this HostAction
402    * @param cost The cost of this HostAction in [TODO]
403    * @param failed [description]
404    */
405   HostAction(ModelPtr model, double cost, bool failed)
406   : Action(model, cost, failed) {}
407
408   /**
409    * @brief HostAction constructor
410    *
411    * @param model The HostModel associated to this HostAction
412    * @param cost The cost of this HostAction in [TODO]
413    * @param failed [description]
414    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
415    */
416   HostAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
417   : Action(model, cost, failed, var) {}
418
419   void setState(e_surf_action_state_t state);
420 };
421
422
423 #endif /* SURF_Host_INTERFACE_HPP_ */