Logo AND Algorithmique Numérique Distribuée

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