Logo AND Algorithmique Numérique Distribuée

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