Logo AND Algorithmique Numérique Distribuée

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