Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5f3f64f0ae3fe02c5925f51aa0c2ebcd36c80b15
[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                                       sg_host_t *host_list,
72                                                                           double *flops_amount,
73                                                                           double *bytes_amount,
74                                                                           double rate)=0;
75
76   bool shareResourcesIsIdempotent() {return true;}
77 };
78
79 /************
80  * Resource *
81  ************/
82 /** @ingroup SURF_host_interface
83  * @brief SURF Host interface class
84  * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
85  */
86 class Host : public Resource {
87 public:
88   /**
89    * @brief Host constructor
90    *
91    * @param model HostModel associated to this Host
92    * @param name The name of the Host
93    * @param props Dictionary of properties associated to this Host
94    * @param storage The Storage associated to this Host
95    * @param netElm The RoutingEdge associated to this Host
96    * @param cpu The Cpu associated to this Host
97    */
98   Host(Model *model, const char *name, xbt_dict_t props,
99                       xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
100
101   /**
102    * @brief Host constructor
103    *
104    * @param model HostModel associated to this Host
105    * @param name The name of the Host
106    * @param props Dictionary of properties associated to this Host
107    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
108    * @param storage The Storage associated to this Host
109    * @param netElm The RoutingEdge associated to this Host
110    * @param cpu The Cpu associated to this Host
111    */
112   Host(Model *model, const char *name, xbt_dict_t props,
113       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
114       Cpu *cpu);
115
116   /** @brief Host destructor */
117   ~ Host();
118
119   void setState(e_surf_resource_state_t state);
120
121   /**
122    * @brief Get the properties of the current Host
123    *
124    * @return The properties of the current Host
125    */
126   xbt_dict_t getProperties();
127
128   /**
129    * @brief Execute some quantity of computation
130    *
131    * @param flops_amount The value of the processing amount (in flop) needed to process
132    * @return The CpuAction corresponding to the processing
133    * @see Cpu
134    */
135   virtual Action *execute(double flops_amount)=0;
136
137   /**
138    * @brief Make a process sleep for duration seconds
139    *
140    * @param duration The number of seconds to sleep
141    * @return The CpuAction corresponding to the sleeping
142    * @see Cpu
143    */
144   virtual Action *sleep(double duration)=0;
145
146   /**
147    * @brief Get the number of cores of the associated Cpu
148    *
149    * @return The number of cores of the associated Cpu
150    * @see Cpu
151    */
152   virtual int getCore();
153
154   /**
155    * @brief Get the speed of the associated Cpu
156    *
157    * @param load [TODO]
158    * @return The speed of the associated Cpu
159    * @see Cpu
160    */
161   virtual double getSpeed(double load);
162
163   /**
164    * @brief Get the available speed of the associated Cpu
165    * @details [TODO]
166    *
167    * @return The available speed of the associated Cpu
168    * @see Cpu
169    */
170   virtual double getAvailableSpeed();
171
172   /**
173    * @brief Get the associated Cpu power peak
174    *
175    * @return The associated Cpu power peak
176    * @see Cpu
177    */
178   virtual double getCurrentPowerPeak();
179
180   virtual double getPowerPeakAt(int pstate_index);
181   virtual int getNbPstates();
182   virtual void setPstate(int pstate_index);
183   virtual int  getPstate();
184
185   /**
186    * @brief Return the storage of corresponding mount point
187    *
188    * @param storage The mount point
189    * @return The corresponding Storage
190    */
191   virtual Storage *findStorageOnMountList(const char* storage);
192
193   /**
194    * @brief Get the xbt_dict_t of mount_point: Storage
195    *
196    * @return The xbt_dict_t of mount_point: Storage
197    */
198   virtual xbt_dict_t getMountedStorageList();
199
200   /**
201    * @brief Get the xbt_dynar_t of storages attached to the Host
202    *
203    * @return The xbt_dynar_t of Storage names
204    */
205   virtual xbt_dynar_t getAttachedStorageList();
206
207   /**
208    * @brief Open a file
209    *
210    * @param fullpath The full path to the file
211    *
212    * @return The StorageAction corresponding to the opening
213    */
214   virtual Action *open(const char* fullpath);
215
216   /**
217    * @brief Close a file
218    *
219    * @param fd The file descriptor to close
220    * @return The StorageAction corresponding to the closing
221    */
222   virtual Action *close(surf_file_t fd);
223
224   /**
225    * @brief Unlink a file
226    * @details [long description]
227    *
228    * @param fd [description]
229    * @return [description]
230    */
231   virtual int unlink(surf_file_t fd);
232
233   /**
234    * @brief Get the size in bytes of the file
235    *
236    * @param fd The file descriptor to read
237    * @return The size in bytes of the file
238    */
239   virtual sg_size_t getSize(surf_file_t fd);
240
241   /**
242    * @brief Read a file
243    *
244    * @param fd The file descriptor to read
245    * @param size The size in bytes to read
246    * @return The StorageAction corresponding to the reading
247    */
248   virtual Action *read(surf_file_t fd, sg_size_t size);
249
250   /**
251    * @brief Write a file
252    *
253    * @param fd The file descriptor to write
254    * @param size The size in bytes to write
255    * @return The StorageAction corresponding to the writing
256    */
257   virtual Action *write(surf_file_t fd, sg_size_t size);
258
259   /**
260    * @brief Get the informations of a file descriptor
261    * @details The returned xbt_dynar_t contains:
262    *  - the size of the file,
263    *  - the mount point,
264    *  - the storage name,
265    *  - the storage typeId,
266    *  - the storage content type
267    *
268    * @param fd The file descriptor
269    * @return An xbt_dynar_t with the file informations
270    */
271   virtual xbt_dynar_t getInfo(surf_file_t fd);
272
273   /**
274    * @brief Get the current position of the file descriptor
275    *
276    * @param fd The file descriptor
277    * @return The current position of the file descriptor
278    */
279   virtual sg_size_t fileTell(surf_file_t fd);
280
281   /**
282    * @brief Set the position indicator associated with the file descriptor to a new position
283    * @details [long description]
284    *
285    * @param fd The file descriptor
286    * @param offset The offset from the origin
287    * @param origin Position used as a reference for the offset
288    *  - SEEK_SET: beginning of the file
289    *  - SEEK_CUR: current position indicator
290    *  - SEEK_END: end of the file
291    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
292    */
293   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
294
295   /**
296    * @brief Move a file to another location on the *same mount point*.
297    * @details [long description]
298    *
299    * @param fd The file descriptor
300    * @param fullpath The new full path
301    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
302    * full path is not on the same mount point
303    */
304   virtual int fileMove(surf_file_t fd, const char* fullpath);
305
306   xbt_dynar_t p_storage;
307   RoutingEdge *p_netElm;
308   Cpu *p_cpu;
309
310   /**
311    * @brief Get the list of virtual machines on the current Host
312    *
313    * @return The list of VMs
314    */
315   xbt_dynar_t getVms();
316
317   /* common with vm */
318   /** @brief Retrieve a copy of the parameters of that VM/PM
319    *  @details The ramsize and overcommit fields are used on the PM too */
320   void getParams(vm_params_t params);
321   /** @brief Sets the params of that VM/PM */
322   void setParams(vm_params_t params);
323 private:
324   s_vm_params_t p_params;
325 };
326
327 /**********
328  * Action *
329  **********/
330
331 /** @ingroup SURF_host_interface
332  * @brief SURF host action interface class
333  */
334 class HostAction : public Action {
335 public:
336   /**
337    * @brief HostAction constructor
338    *
339    * @param model The HostModel associated to this HostAction
340    * @param cost The cost of this HostAction in [TODO]
341    * @param failed [description]
342    */
343   HostAction(Model *model, double cost, bool failed)
344   : Action(model, cost, failed) {}
345
346   /**
347    * @brief HostAction constructor
348    *
349    * @param model The HostModel associated to this HostAction
350    * @param cost The cost of this HostAction in [TODO]
351    * @param failed [description]
352    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
353    */
354   HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
355   : Action(model, cost, failed, var) {}
356
357   void setState(e_surf_action_state_t state);
358 };
359
360
361 #endif /* SURF_Host_INTERFACE_HPP_ */