Logo AND Algorithmique Numérique Distribuée

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