Logo AND Algorithmique Numérique Distribuée

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