Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / surf / workstation_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_WORKSTATION_INTERFACE_HPP_
13 #define SURF_WORKSTATION_INTERFACE_HPP_
14
15 /***********
16  * Classes *
17  ***********/
18
19 class WorkstationModel;
20 typedef WorkstationModel *WorkstationModelPtr;
21
22 class Workstation;
23 typedef Workstation *WorkstationPtr;
24
25 class WorkstationAction;
26 typedef WorkstationAction *WorkstationActionPtr;
27
28 /*************
29  * Callbacks *
30  *************/
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks handler which emit the callbacks after Workstation creation *
34  * @details Callback functions have the following signature: `void(WorkstationPtr)`
35  */
36 extern surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks handler which emit the callbacks after Workstation destruction *
40  * @details Callback functions have the following signature: `void(WorkstationPtr)`
41  */
42 extern surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks handler which emit the callbacks after Workstation State changed *
46  * @details Callback functions have the following signature: `void(WorkstationActionPtr)`
47  */
48 extern surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
49
50 /** @ingroup SURF_callbacks
51  * @brief Callbacks handler which emit the callbacks after WorkstationAction State changed *
52  * @details Callback functions have the following signature: `void(WorkstationActionPtr)`
53  */
54 extern surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
55
56 /*********
57  * Tools *
58  *********/
59 extern WorkstationModelPtr surf_workstation_model;
60
61 /*********
62  * Model *
63  *********/
64 /** @ingroup SURF_workstation_interface
65  * @brief SURF Workstation model interface class
66  * @details A model is an object which handle the interactions between its Resources and its Actions
67  */
68 class WorkstationModel : public Model {
69 public:
70     /** 
71    * @brief WorkstationModel constructor
72    * 
73    * @param name the name of the model
74    */
75   WorkstationModel(const char *name);
76
77   /**
78    * @brief WorkstationModel constructor
79    */
80   WorkstationModel();
81
82   /**
83    * @brief WorkstationModel destructor
84    */
85   ~WorkstationModel();
86
87   /**
88    * @brief [brief description]
89    * @details [long description]
90    */
91   virtual void adjustWeightOfDummyCpuActions();
92   
93   /**
94    * @brief [brief description]
95    * @details [long description]
96    * 
97    * @param workstation_nb [description]
98    * @param workstation_list [description]
99    * @param computation_amount [description]
100    * @param communication_amount [description]
101    * @param rate [description]
102    * @return [description]
103    */
104   virtual ActionPtr executeParallelTask(int workstation_nb,
105                                         void **workstation_list,
106                                         double *computation_amount,
107                                         double *communication_amount,
108                                         double rate)=0;
109
110  /**
111   * @brief [brief description]
112   * @details [long description]
113   * 
114   * @param src [description]
115   * @param dst [description]
116   * @param size [description]
117   * @param rate [description]
118   * @return [description]
119   */
120  virtual ActionPtr communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate)=0;
121
122  CpuModelPtr p_cpuModel;
123 };
124
125 /************
126  * Resource *
127  ************/
128 /** @ingroup SURF_workstation_interface
129  * @brief SURF Workstation interface class
130  * @details A workstation VM represent an virtual machine with a aggregation of a Cpu, a NetworkLink and a Storage
131  */
132 class Workstation : public Resource {
133 public:
134   /**
135    * @brief Workstation consrtuctor
136    */
137   Workstation();
138
139   /**
140    * @brief Workstation constructor
141    * 
142    * @param model WorkstationModel associated to this Workstation
143    * @param name The name of the Workstation
144    * @param props Dictionary of properties associated to this Workstation
145    * @param storage The Storage associated to this Workstation
146    * @param netElm The RoutingEdge associated to this Workstation
147    * @param cpu The Cpu associated to this Workstation
148    */
149   Workstation(ModelPtr model, const char *name, xbt_dict_t props,
150                       xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
151
152   /**
153    * @brief Workstation constructor
154    * 
155    * @param model WorkstationModel associated to this Workstation
156    * @param name The name of the Workstation
157    * @param props Dictionary of properties associated to this Workstation
158    * @param constraint The lmm constraint associated to this Workstation if it is part of a LMM component
159    * @param storage The Storage associated to this Workstation
160    * @param netElm The RoutingEdge associated to this Workstation
161    * @param cpu The Cpu associated to this Workstation
162    */
163   Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
164                       xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
165
166   /**
167    * @brief Workstation destructor
168    */
169   ~ Workstation();
170
171   void setState(e_surf_resource_state_t state);
172
173   /**
174    * @brief Get the properties of the currenrt Workstation
175    *
176    * @return The properties of the current Workstation
177    */
178   xbt_dict_t getProperties();
179
180   /**
181    * @brief Execute some quantity of computation
182    * 
183    * @param size 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 size)=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 setPowerPeakAt(int pstate_index);
235
236   /**
237    * @brief Return the storage of corresponding mount point
238    * 
239    * @param storage The mount point
240    * @return The corresponding Storage
241    */
242   virtual StoragePtr findStorageOnMountList(const char* storage);
243
244   /**
245    * @brief Get the xbt_dict_t of mount_point: Storage
246    * 
247    * @return The xbt_dict_t of mount_point: Storage
248    */
249   virtual xbt_dict_t getMountedStorageList();
250
251   /**
252    * @brief Get the xbt_dynar_t of storages attached to the workstation
253    *
254    * @return The xbt_dynar_t of Storage names
255    */
256   virtual xbt_dynar_t getAttachedStorageList();
257
258   /**
259    * @brief Open a file
260    * 
261    * @param fullpath The full path to the file
262    * 
263    * @return The StorageAction corresponding to the opening
264    */
265   virtual ActionPtr open(const char* fullpath);
266
267   /**
268    * @brief Close a file
269    * 
270    * @param fd The file descriptor to close
271    * @return The StorageAction corresponding to the closing
272    */
273   virtual ActionPtr close(surf_file_t fd);
274
275   /**
276    * @brief Unlink a file
277    * @details [long description]
278    * 
279    * @param fd [description]
280    * @return [description]
281    */
282   virtual int unlink(surf_file_t fd);
283
284   /**
285    * @brief List directory contents of a path
286    * @details [long description]
287    * 
288    * @param mount [description]
289    * @param path The path to the directory
290    * @return The StorageAction corresponding to the ls action
291    */
292   virtual ActionPtr ls(const char* mount, const char *path);
293
294   /**
295    * @brief Get the size in bytes of the file
296    * 
297    * @param fd The file descriptor to read
298    * @return The size in bytes of the file
299    */
300   virtual sg_size_t getSize(surf_file_t fd);
301
302   /**
303    * @brief Read a file
304    * 
305    * @param fd The file descriptor to read
306    * @param size The size in bytes to read
307    * @return The StorageAction corresponding to the reading
308    */
309   virtual ActionPtr read(surf_file_t fd, sg_size_t size);
310
311   /**
312    * @brief Write a file
313    * 
314    * @param fd The file descriptor to write
315    * @param size The size in bytes to write
316    * @return The StorageAction corresponding to the writing
317    */
318   virtual ActionPtr write(surf_file_t fd, sg_size_t size);
319
320   /**
321    * @brief Get the informations of a file descriptor
322    * @details The returned xbt_dynar_t contains:
323    *  - the size of the file,
324    *  - the mount point,
325    *  - the storage name,
326    *  - the storage typeId,
327    *  - the storage content type
328    * 
329    * @param fd The file descriptor
330    * @return An xbt_dynar_t with the file informations
331    */
332   virtual xbt_dynar_t getInfo(surf_file_t fd);
333
334   /**
335    * @brief Get the current position of the file descriptor
336    *  
337    * @param fd The file descriptor
338    * @return The current position of the file descriptor
339    */
340   virtual sg_size_t fileTell(surf_file_t fd);
341
342   /**
343    * @brief Get the available space of the storage at the mount point 
344    * 
345    * @param name The mount point
346    * @return The amount of availble space in bytes
347    */
348   virtual sg_size_t getFreeSize(const char* name);
349
350   /**
351    * @brief Get the used space of the storage at the mount point
352    * 
353    * @param name The mount point
354    * @return The amount of used space in bytes
355    */
356   virtual sg_size_t getUsedSize(const char* name);
357
358   /**
359    * @brief Set the position indictator assiociated with the file descriptor to a new position
360    * @details [long description]
361    * 
362    * @param fd The file descriptor
363    * @param offset The offset from the origin
364    * @param origin Position used as a reference for the offset
365    *  - SEEK_SET: beginning of the file
366    *  - SEEK_CUR: current position indicator
367    *  - SEEK_END: end of the file
368    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
369    */
370   virtual int fileSeek(surf_file_t fd, sg_size_t offset, int origin);
371
372   /**
373    * @brief Move a file to another location on the *same mount point*.
374    * @details [long description]
375    *
376    * @param fd The file descriptor
377    * @param fullpath The new full path
378    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
379    * full path is not on the same mount point
380    */
381   virtual int fileMove(surf_file_t fd, const char* fullpath);
382
383   /**
384    * @brief Copy a file to another location on a remote host.
385    * @details [long description]
386    *
387    * @param fd The file descriptor
388    * @param host_dest The worstation destination
389    * @param fullpath The new full path
390    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
391    */
392   virtual int fileRcopy(surf_file_t fd, surf_resource_t host_dest, const char* fullpath);
393
394   xbt_dynar_t p_storage;
395   RoutingEdgePtr p_netElm;
396   CpuPtr p_cpu;
397   NetworkLinkPtr p_network;
398
399   /**
400    * @brief Get the list of virtual machines on the current Workstation
401    * 
402    * @return The list of VMs
403    */
404   xbt_dynar_t getVms();
405
406   /* common with vm */
407   /**
408    * @brief [brief description]
409    * @details [long description]
410    * 
411    * @param params [description]
412    */
413   void getParams(ws_params_t params);
414
415   /**
416    * @brief [brief description]
417    * @details [long description]
418    * 
419    * @param params [description]
420    */
421   void setParams(ws_params_t params);
422   s_ws_params_t p_params;
423 };
424
425 /**********
426  * Action *
427  **********/
428
429 /** @ingroup SURF_workstation_interface
430  * @brief SURF workstation action interface class
431  */
432 class WorkstationAction : public Action {
433 public:
434   /**
435    * @brief WorkstationAction constructor
436    * 
437    * @param model The WorkstationModel associated to this WorkstationAction
438    * @param cost The cost of this WorkstationAction in [TODO]
439    * @param failed [description]
440    */
441   WorkstationAction(ModelPtr model, double cost, bool failed)
442   : Action(model, cost, failed) {}
443
444   /**
445    * @brief WorkstationAction constructor
446    * 
447    * @param model The WorkstationModel associated to this WorkstationAction
448    * @param cost The cost of this WorkstationAction in [TODO]
449    * @param failed [description]
450    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
451    */
452   WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
453   : Action(model, cost, failed, var) {}
454
455   void setState(e_surf_action_state_t state);
456 };
457
458
459 #endif /* SURF_WORKSTATION_INTERFACE_HPP_ */