Logo AND Algorithmique Numérique Distribuée

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