Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add4082ecac7bcfd9315a3016c92e032097cb8f3
[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 computation_amount [description]
105    * @param communication_amount [description]
106    * @param rate [description]
107    * @return [description]
108    */
109   virtual ActionPtr executeParallelTask(int workstation_nb,
110                                         void **workstation_list,
111                                         double *computation_amount,
112                                         double *communication_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, lmm_constraint_t constraint,
169                       xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
170
171   /**
172    * @brief Workstation destructor
173    */
174   ~ Workstation();
175
176   void setState(e_surf_resource_state_t state);
177
178   /**
179    * @brief Get the properties of the currenrt Workstation
180    *
181    * @return The properties of the current Workstation
182    */
183   xbt_dict_t getProperties();
184
185   /**
186    * @brief Execute some quantity of computation
187    *
188    * @param size The value of the processing amount (in flop) needed to process
189    * @return The CpuAction corresponding to the processing
190    * @see Cpu
191    */
192   virtual ActionPtr execute(double size)=0;
193
194   /**
195    * @brief Make a process sleep for duration seconds
196    *
197    * @param duration The number of seconds to sleep
198    * @return The CpuAction corresponding to the sleeping
199    * @see Cpu
200    */
201   virtual ActionPtr sleep(double duration)=0;
202
203   /**
204    * @brief Get the number of cores of the associated Cpu
205    *
206    * @return The number of cores of the associated Cpu
207    * @see Cpu
208    */
209   virtual int getCore();
210
211   /**
212    * @brief Get the speed of the associated Cpu
213    *
214    * @param load [TODO]
215    * @return The speed of the associated Cpu
216    * @see Cpu
217    */
218   virtual double getSpeed(double load);
219
220   /**
221    * @brief Get the available speed of the associated Cpu
222    * @details [TODO]
223    *
224    * @return The available speed of the associated Cpu
225    * @see Cpu
226    */
227   virtual double getAvailableSpeed();
228
229   /**
230    * @brief Get the associated Cpu power peak
231    *
232    * @return The associated Cpu power peak
233    * @see Cpu
234    */
235   virtual double getCurrentPowerPeak();
236
237   virtual double getPowerPeakAt(int pstate_index);
238   virtual int getNbPstates();
239   virtual void setPowerPeakAt(int pstate_index);
240
241   /**
242    * @brief Return the storage of corresponding mount point
243    *
244    * @param storage The mount point
245    * @return The corresponding Storage
246    */
247   virtual StoragePtr findStorageOnMountList(const char* storage);
248
249   /**
250    * @brief Get the xbt_dict_t of mount_point: Storage
251    *
252    * @return The xbt_dict_t of mount_point: Storage
253    */
254   virtual xbt_dict_t getMountedStorageList();
255
256   /**
257    * @brief Get the xbt_dynar_t of storages attached to the workstation
258    *
259    * @return The xbt_dynar_t of Storage names
260    */
261   virtual xbt_dynar_t getAttachedStorageList();
262
263   /**
264    * @brief Open a file
265    *
266    * @param fullpath The full path to the file
267    *
268    * @return The StorageAction corresponding to the opening
269    */
270   virtual ActionPtr open(const char* fullpath);
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 Get the size in bytes of the file
291    *
292    * @param fd The file descriptor to read
293    * @return The size in bytes of the file
294    */
295   virtual sg_size_t getSize(surf_file_t fd);
296
297   /**
298    * @brief Read a file
299    *
300    * @param fd The file descriptor to read
301    * @param size The size in bytes to read
302    * @return The StorageAction corresponding to the reading
303    */
304   virtual ActionPtr read(surf_file_t fd, sg_size_t size);
305
306   /**
307    * @brief Write a file
308    *
309    * @param fd The file descriptor to write
310    * @param size The size in bytes to write
311    * @return The StorageAction corresponding to the writing
312    */
313   virtual ActionPtr write(surf_file_t fd, sg_size_t size);
314
315   /**
316    * @brief Get the informations of a file descriptor
317    * @details The returned xbt_dynar_t contains:
318    *  - the size of the file,
319    *  - the mount point,
320    *  - the storage name,
321    *  - the storage typeId,
322    *  - the storage content type
323    *
324    * @param fd The file descriptor
325    * @return An xbt_dynar_t with the file informations
326    */
327   virtual xbt_dynar_t getInfo(surf_file_t fd);
328
329   /**
330    * @brief Get the current position of the file descriptor
331    *
332    * @param fd The file descriptor
333    * @return The current position of the file descriptor
334    */
335   virtual sg_size_t fileTell(surf_file_t fd);
336
337   /**
338    * @brief Set the position indicator associated with the file descriptor to a new position
339    * @details [long description]
340    *
341    * @param fd The file descriptor
342    * @param offset The offset from the origin
343    * @param origin Position used as a reference for the offset
344    *  - SEEK_SET: beginning of the file
345    *  - SEEK_CUR: current position indicator
346    *  - SEEK_END: end of the file
347    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
348    */
349   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
350
351   /**
352    * @brief Move a file to another location on the *same mount point*.
353    * @details [long description]
354    *
355    * @param fd The file descriptor
356    * @param fullpath The new full path
357    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
358    * full path is not on the same mount point
359    */
360   virtual int fileMove(surf_file_t fd, const char* fullpath);
361
362   xbt_dynar_t p_storage;
363   RoutingEdgePtr p_netElm;
364   CpuPtr p_cpu;
365   NetworkLinkPtr p_network;
366
367   /**
368    * @brief Get the list of virtual machines on the current Workstation
369    *
370    * @return The list of VMs
371    */
372   xbt_dynar_t getVms();
373
374   /* common with vm */
375   /**
376    * @brief [brief description]
377    * @details [long description]
378    *
379    * @param params [description]
380    */
381   void getParams(ws_params_t params);
382
383   /**
384    * @brief [brief description]
385    * @details [long description]
386    *
387    * @param params [description]
388    */
389   void setParams(ws_params_t params);
390   s_ws_params_t p_params;
391 };
392
393 /**********
394  * Action *
395  **********/
396
397 /** @ingroup SURF_workstation_interface
398  * @brief SURF workstation action interface class
399  */
400 class WorkstationAction : public Action {
401 public:
402   /**
403    * @brief WorkstationAction constructor
404    *
405    * @param model The WorkstationModel associated to this WorkstationAction
406    * @param cost The cost of this WorkstationAction in [TODO]
407    * @param failed [description]
408    */
409   WorkstationAction(ModelPtr model, double cost, bool failed)
410   : Action(model, cost, failed) {}
411
412   /**
413    * @brief WorkstationAction constructor
414    *
415    * @param model The WorkstationModel associated to this WorkstationAction
416    * @param cost The cost of this WorkstationAction in [TODO]
417    * @param failed [description]
418    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
419    */
420   WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
421   : Action(model, cost, failed, var) {}
422
423   void setState(e_surf_action_state_t state);
424 };
425
426
427 #endif /* SURF_WORKSTATION_INTERFACE_HPP_ */