Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
actually kill models' names
[simgrid.git] / src / surf / host_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_HOST_INTERFACE_HPP_
13 #define SURF_HOST_INTERFACE_HPP_
14
15 /***********
16  * Classes *
17  ***********/
18
19 class HostModel;
20 class Host;
21 class HostAction;
22
23 /*************
24  * Callbacks *
25  *************/
26
27 /** @ingroup SURF_callbacks
28  * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
29  */
30 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
34  */
35 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
36
37 /** @ingroup SURF_callbacks
38  * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
39  */
40 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
41
42 /** @ingroup SURF_callbacks
43  * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
44  */
45 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
46
47 /*********
48  * Tools *
49  *********/
50 XBT_PUBLIC_DATA(HostModel*) surf_host_model;
51 XBT_PUBLIC(void) host_parse_init(sg_platf_host_cbarg_t host);
52 XBT_PUBLIC(void) host_add_traces();
53
54 /*********
55  * Model *
56  *********/
57 /** @ingroup SURF_host_interface
58  * @brief SURF Host model interface class
59  * @details A model is an object which handle the interactions between its Resources and its Actions
60  */
61 class HostModel : public Model {
62 public:
63   HostModel() : Model() {}
64   ~HostModel() {}
65
66   virtual Host *createHost(const char *name)=0;
67   void addTraces(){DIE_IMPOSSIBLE;}
68
69   virtual void adjustWeightOfDummyCpuActions();
70   virtual Action *executeParallelTask(int host_nb,
71                                         void **host_list,
72                                         double *flops_amount,
73                                         double *bytes_amount,
74                                         double rate)=0;
75
76   virtual Action *communicate(Host *src, Host *dst, double size, double rate)=0;
77
78   bool shareResourcesIsIdempotent() {return true;}
79 };
80
81 /************
82  * Resource *
83  ************/
84 /** @ingroup SURF_host_interface
85  * @brief SURF Host interface class
86  * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
87  */
88 class Host : public Resource {
89 public:
90   /**
91    * @brief Host constructor
92    *
93    * @param model HostModel associated to this Host
94    * @param name The name of the Host
95    * @param props Dictionary of properties associated to this Host
96    * @param storage The Storage associated to this Host
97    * @param netElm The RoutingEdge associated to this Host
98    * @param cpu The Cpu associated to this Host
99    */
100   Host(Model *model, const char *name, xbt_dict_t props,
101                       xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
102
103   /**
104    * @brief Host constructor
105    *
106    * @param model HostModel associated to this Host
107    * @param name The name of the Host
108    * @param props Dictionary of properties associated to this Host
109    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
110    * @param storage The Storage associated to this Host
111    * @param netElm The RoutingEdge associated to this Host
112    * @param cpu The Cpu associated to this Host
113    */
114   Host(Model *model, const char *name, xbt_dict_t props,
115       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
116       Cpu *cpu);
117
118   /** @brief Host destructor */
119   ~ Host();
120
121   void setState(e_surf_resource_state_t state);
122
123   /**
124    * @brief Get the properties of the current Host
125    *
126    * @return The properties of the current Host
127    */
128   xbt_dict_t getProperties();
129
130   /**
131    * @brief Execute some quantity of computation
132    *
133    * @param flops_amount The value of the processing amount (in flop) needed to process
134    * @return The CpuAction corresponding to the processing
135    * @see Cpu
136    */
137   virtual Action *execute(double flops_amount)=0;
138
139   /**
140    * @brief Make a process sleep for duration seconds
141    *
142    * @param duration The number of seconds to sleep
143    * @return The CpuAction corresponding to the sleeping
144    * @see Cpu
145    */
146   virtual Action *sleep(double duration)=0;
147
148   /**
149    * @brief Get the number of cores of the associated Cpu
150    *
151    * @return The number of cores of the associated Cpu
152    * @see Cpu
153    */
154   virtual int getCore();
155
156   /**
157    * @brief Get the speed of the associated Cpu
158    *
159    * @param load [TODO]
160    * @return The speed of the associated Cpu
161    * @see Cpu
162    */
163   virtual double getSpeed(double load);
164
165   /**
166    * @brief Get the available speed of the associated Cpu
167    * @details [TODO]
168    *
169    * @return The available speed of the associated Cpu
170    * @see Cpu
171    */
172   virtual double getAvailableSpeed();
173
174   /**
175    * @brief Get the associated Cpu power peak
176    *
177    * @return The associated Cpu power peak
178    * @see Cpu
179    */
180   virtual double getCurrentPowerPeak();
181
182   virtual double getPowerPeakAt(int pstate_index);
183   virtual int getNbPstates();
184   virtual void setPstate(int pstate_index);
185   virtual int  getPstate();
186
187   /**
188    * @brief Return the storage of corresponding mount point
189    *
190    * @param storage The mount point
191    * @return The corresponding Storage
192    */
193   virtual Storage *findStorageOnMountList(const char* storage);
194
195   /**
196    * @brief Get the xbt_dict_t of mount_point: Storage
197    *
198    * @return The xbt_dict_t of mount_point: Storage
199    */
200   virtual xbt_dict_t getMountedStorageList();
201
202   /**
203    * @brief Get the xbt_dynar_t of storages attached to the Host
204    *
205    * @return The xbt_dynar_t of Storage names
206    */
207   virtual xbt_dynar_t getAttachedStorageList();
208
209   /**
210    * @brief Open a file
211    *
212    * @param fullpath The full path to the file
213    *
214    * @return The StorageAction corresponding to the opening
215    */
216   virtual Action *open(const char* fullpath);
217
218   /**
219    * @brief Close a file
220    *
221    * @param fd The file descriptor to close
222    * @return The StorageAction corresponding to the closing
223    */
224   virtual Action *close(surf_file_t fd);
225
226   /**
227    * @brief Unlink a file
228    * @details [long description]
229    *
230    * @param fd [description]
231    * @return [description]
232    */
233   virtual int unlink(surf_file_t fd);
234
235   /**
236    * @brief Get the size in bytes of the file
237    *
238    * @param fd The file descriptor to read
239    * @return The size in bytes of the file
240    */
241   virtual sg_size_t getSize(surf_file_t fd);
242
243   /**
244    * @brief Read a file
245    *
246    * @param fd The file descriptor to read
247    * @param size The size in bytes to read
248    * @return The StorageAction corresponding to the reading
249    */
250   virtual Action *read(surf_file_t fd, sg_size_t size);
251
252   /**
253    * @brief Write a file
254    *
255    * @param fd The file descriptor to write
256    * @param size The size in bytes to write
257    * @return The StorageAction corresponding to the writing
258    */
259   virtual Action *write(surf_file_t fd, sg_size_t size);
260
261   /**
262    * @brief Get the informations of a file descriptor
263    * @details The returned xbt_dynar_t contains:
264    *  - the size of the file,
265    *  - the mount point,
266    *  - the storage name,
267    *  - the storage typeId,
268    *  - the storage content type
269    *
270    * @param fd The file descriptor
271    * @return An xbt_dynar_t with the file informations
272    */
273   virtual xbt_dynar_t getInfo(surf_file_t fd);
274
275   /**
276    * @brief Get the current position of the file descriptor
277    *
278    * @param fd The file descriptor
279    * @return The current position of the file descriptor
280    */
281   virtual sg_size_t fileTell(surf_file_t fd);
282
283   /**
284    * @brief Set the position indicator associated with the file descriptor to a new position
285    * @details [long description]
286    *
287    * @param fd The file descriptor
288    * @param offset The offset from the origin
289    * @param origin Position used as a reference for the offset
290    *  - SEEK_SET: beginning of the file
291    *  - SEEK_CUR: current position indicator
292    *  - SEEK_END: end of the file
293    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
294    */
295   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
296
297   /**
298    * @brief Move a file to another location on the *same mount point*.
299    * @details [long description]
300    *
301    * @param fd The file descriptor
302    * @param fullpath The new full path
303    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
304    * full path is not on the same mount point
305    */
306   virtual int fileMove(surf_file_t fd, const char* fullpath);
307
308   xbt_dynar_t p_storage;
309   RoutingEdge *p_netElm;
310   Cpu *p_cpu;
311
312   /**
313    * @brief Get the list of virtual machines on the current Host
314    *
315    * @return The list of VMs
316    */
317   xbt_dynar_t getVms();
318
319   /* common with vm */
320   /**
321    * @brief [brief description]
322    * @details [long description]
323    *
324    * @param params [description]
325    */
326   void getParams(ws_params_t params);
327
328   /**
329    * @brief [brief description]
330    * @details [long description]
331    *
332    * @param params [description]
333    */
334   void setParams(ws_params_t params);
335   s_ws_params_t p_params;
336 };
337
338 /**********
339  * Action *
340  **********/
341
342 /** @ingroup SURF_host_interface
343  * @brief SURF host action interface class
344  */
345 class HostAction : public Action {
346 public:
347   /**
348    * @brief HostAction constructor
349    *
350    * @param model The HostModel associated to this HostAction
351    * @param cost The cost of this HostAction in [TODO]
352    * @param failed [description]
353    */
354   HostAction(Model *model, double cost, bool failed)
355   : Action(model, cost, failed) {}
356
357   /**
358    * @brief HostAction constructor
359    *
360    * @param model The HostModel associated to this HostAction
361    * @param cost The cost of this HostAction in [TODO]
362    * @param failed [description]
363    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
364    */
365   HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
366   : Action(model, cost, failed, var) {}
367
368   void setState(e_surf_action_state_t state);
369 };
370
371
372 #endif /* SURF_Host_INTERFACE_HPP_ */