Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
13ccd603ff2ff4bd19d00b8e7f13d4f93dbf7e94
[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 setPowerPeakAt(int pstate_index);
241
242   /**
243    * @brief Return the storage of corresponding mount point
244    *
245    * @param storage The mount point
246    * @return The corresponding Storage
247    */
248   virtual StoragePtr findStorageOnMountList(const char* storage);
249
250   /**
251    * @brief Get the xbt_dict_t of mount_point: Storage
252    *
253    * @return The xbt_dict_t of mount_point: Storage
254    */
255   virtual xbt_dict_t getMountedStorageList();
256
257   /**
258    * @brief Get the xbt_dynar_t of storages attached to the workstation
259    *
260    * @return The xbt_dynar_t of Storage names
261    */
262   virtual xbt_dynar_t getAttachedStorageList();
263
264   /**
265    * @brief Open a file
266    *
267    * @param fullpath The full path to the file
268    *
269    * @return The StorageAction corresponding to the opening
270    */
271   virtual ActionPtr open(const char* fullpath);
272
273   /**
274    * @brief Close a file
275    *
276    * @param fd The file descriptor to close
277    * @return The StorageAction corresponding to the closing
278    */
279   virtual ActionPtr close(surf_file_t fd);
280
281   /**
282    * @brief Unlink a file
283    * @details [long description]
284    *
285    * @param fd [description]
286    * @return [description]
287    */
288   virtual int unlink(surf_file_t fd);
289
290   /**
291    * @brief Get the size in bytes of the file
292    *
293    * @param fd The file descriptor to read
294    * @return The size in bytes of the file
295    */
296   virtual sg_size_t getSize(surf_file_t fd);
297
298   /**
299    * @brief Read a file
300    *
301    * @param fd The file descriptor to read
302    * @param size The size in bytes to read
303    * @return The StorageAction corresponding to the reading
304    */
305   virtual ActionPtr read(surf_file_t fd, sg_size_t size);
306
307   /**
308    * @brief Write a file
309    *
310    * @param fd The file descriptor to write
311    * @param size The size in bytes to write
312    * @return The StorageAction corresponding to the writing
313    */
314   virtual ActionPtr write(surf_file_t fd, sg_size_t size);
315
316   /**
317    * @brief Get the informations of a file descriptor
318    * @details The returned xbt_dynar_t contains:
319    *  - the size of the file,
320    *  - the mount point,
321    *  - the storage name,
322    *  - the storage typeId,
323    *  - the storage content type
324    *
325    * @param fd The file descriptor
326    * @return An xbt_dynar_t with the file informations
327    */
328   virtual xbt_dynar_t getInfo(surf_file_t fd);
329
330   /**
331    * @brief Get the current position of the file descriptor
332    *
333    * @param fd The file descriptor
334    * @return The current position of the file descriptor
335    */
336   virtual sg_size_t fileTell(surf_file_t fd);
337
338   /**
339    * @brief Set the position indicator associated with the file descriptor to a new position
340    * @details [long description]
341    *
342    * @param fd The file descriptor
343    * @param offset The offset from the origin
344    * @param origin Position used as a reference for the offset
345    *  - SEEK_SET: beginning of the file
346    *  - SEEK_CUR: current position indicator
347    *  - SEEK_END: end of the file
348    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
349    */
350   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
351
352   /**
353    * @brief Move a file to another location on the *same mount point*.
354    * @details [long description]
355    *
356    * @param fd The file descriptor
357    * @param fullpath The new full path
358    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
359    * full path is not on the same mount point
360    */
361   virtual int fileMove(surf_file_t fd, const char* fullpath);
362
363   xbt_dynar_t p_storage;
364   RoutingEdgePtr p_netElm;
365   CpuPtr p_cpu;
366   NetworkLinkPtr p_network;
367
368   /**
369    * @brief Get the list of virtual machines on the current Workstation
370    *
371    * @return The list of VMs
372    */
373   xbt_dynar_t getVms();
374
375   /* common with vm */
376   /**
377    * @brief [brief description]
378    * @details [long description]
379    *
380    * @param params [description]
381    */
382   void getParams(ws_params_t params);
383
384   /**
385    * @brief [brief description]
386    * @details [long description]
387    *
388    * @param params [description]
389    */
390   void setParams(ws_params_t params);
391   s_ws_params_t p_params;
392 };
393
394 /**********
395  * Action *
396  **********/
397
398 /** @ingroup SURF_workstation_interface
399  * @brief SURF workstation action interface class
400  */
401 class WorkstationAction : public Action {
402 public:
403   /**
404    * @brief WorkstationAction constructor
405    *
406    * @param model The WorkstationModel associated to this WorkstationAction
407    * @param cost The cost of this WorkstationAction in [TODO]
408    * @param failed [description]
409    */
410   WorkstationAction(ModelPtr model, double cost, bool failed)
411   : Action(model, cost, failed) {}
412
413   /**
414    * @brief WorkstationAction constructor
415    *
416    * @param model The WorkstationModel associated to this WorkstationAction
417    * @param cost The cost of this WorkstationAction in [TODO]
418    * @param failed [description]
419    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
420    */
421   WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
422   : Action(model, cost, failed, var) {}
423
424   void setState(e_surf_action_state_t state);
425 };
426
427
428 #endif /* SURF_WORKSTATION_INTERFACE_HPP_ */