Logo AND Algorithmique Numérique Distribuée

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