Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5c081d2b9aff5cf2c9ebb6df98321958c58f94aa
[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   static simgrid::xbt::FacetLevel<simgrid::Host, Host> LEVEL;
100   static void init();
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 storage The Storage associated to this Host
108    * @param netElm The RoutingEdge associated to this Host
109    * @param cpu The Cpu associated to this Host
110    */
111   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
112                       xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
113
114   /**
115    * @brief Host constructor
116    *
117    * @param model HostModel associated to this Host
118    * @param name The name of the Host
119    * @param props Dictionary of properties associated to this Host
120    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
121    * @param storage The Storage associated to this Host
122    * @param netElm The RoutingEdge associated to this Host
123    * @param cpu The Cpu associated to this Host
124    */
125   Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
126       lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
127       Cpu *cpu);
128
129   /** @brief Host destructor */
130   ~Host();
131
132   void attach(simgrid::Host* host);
133   void setState(e_surf_resource_state_t state);
134
135   /**
136    * @brief Get the properties of the current Host
137    *
138    * @return The properties of the current Host
139    */
140   xbt_dict_t getProperties();
141
142   /**
143    * @brief Execute some quantity of computation
144    *
145    * @param flops_amount The value of the processing amount (in flop) needed to process
146    * @return The CpuAction corresponding to the processing
147    * @see Cpu
148    */
149   virtual Action *execute(double flops_amount)=0;
150
151   /**
152    * @brief Make a process sleep for duration seconds
153    *
154    * @param duration The number of seconds to sleep
155    * @return The CpuAction corresponding to the sleeping
156    * @see Cpu
157    */
158   virtual Action *sleep(double duration)=0;
159
160   /** @brief Return the storage of corresponding mount point */
161   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
162
163   /** @brief Get the xbt_dict_t of mount_point: Storage */
164   virtual xbt_dict_t getMountedStorageList();
165
166   /** @brief Get the xbt_dynar_t of storages attached to the Host */
167   virtual xbt_dynar_t getAttachedStorageList();
168
169   /**
170    * @brief Open a file
171    *
172    * @param fullpath The full path to the file
173    *
174    * @return The StorageAction corresponding to the opening
175    */
176   virtual Action *open(const char* fullpath);
177
178   /**
179    * @brief Close a file
180    *
181    * @param fd The file descriptor to close
182    * @return The StorageAction corresponding to the closing
183    */
184   virtual Action *close(surf_file_t fd);
185
186   /**
187    * @brief Unlink a file
188    * @details [long description]
189    *
190    * @param fd [description]
191    * @return [description]
192    */
193   virtual int unlink(surf_file_t fd);
194
195   /**
196    * @brief Get the size in bytes of the file
197    *
198    * @param fd The file descriptor to read
199    * @return The size in bytes of the file
200    */
201   virtual sg_size_t getSize(surf_file_t fd);
202
203   /**
204    * @brief Read a file
205    *
206    * @param fd The file descriptor to read
207    * @param size The size in bytes to read
208    * @return The StorageAction corresponding to the reading
209    */
210   virtual Action *read(surf_file_t fd, sg_size_t size);
211
212   /**
213    * @brief Write a file
214    *
215    * @param fd The file descriptor to write
216    * @param size The size in bytes to write
217    * @return The StorageAction corresponding to the writing
218    */
219   virtual Action *write(surf_file_t fd, sg_size_t size);
220
221   /**
222    * @brief Get the informations of a file descriptor
223    * @details The returned xbt_dynar_t contains:
224    *  - the size of the file,
225    *  - the mount point,
226    *  - the storage name,
227    *  - the storage typeId,
228    *  - the storage content type
229    *
230    * @param fd The file descriptor
231    * @return An xbt_dynar_t with the file informations
232    */
233   virtual xbt_dynar_t getInfo(surf_file_t fd);
234
235   /**
236    * @brief Get the current position of the file descriptor
237    *
238    * @param fd The file descriptor
239    * @return The current position of the file descriptor
240    */
241   virtual sg_size_t fileTell(surf_file_t fd);
242
243   /**
244    * @brief Set the position indicator associated with the file descriptor to a new position
245    * @details [long description]
246    *
247    * @param fd The file descriptor
248    * @param offset The offset from the origin
249    * @param origin Position used as a reference for the offset
250    *  - SEEK_SET: beginning of the file
251    *  - SEEK_CUR: current position indicator
252    *  - SEEK_END: end of the file
253    * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
254    */
255   virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
256
257   /**
258    * @brief Move a file to another location on the *same mount point*.
259    * @details [long description]
260    *
261    * @param fd The file descriptor
262    * @param fullpath The new full path
263    * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
264    * full path is not on the same mount point
265    */
266   virtual int fileMove(surf_file_t fd, const char* fullpath);
267
268   xbt_dynar_t p_storage;
269   RoutingEdge *p_netElm;
270   Cpu *p_cpu;
271   simgrid::Host* p_host = nullptr;
272
273   /** @brief Get the list of virtual machines on the current Host */
274   xbt_dynar_t getVms();
275
276   /* common with vm */
277   /** @brief Retrieve a copy of the parameters of that VM/PM
278    *  @details The ramsize and overcommit fields are used on the PM too */
279   void getParams(vm_params_t params);
280   /** @brief Sets the params of that VM/PM */
281   void setParams(vm_params_t params);
282   simgrid::Host* getHost() { return p_host; }
283 private:
284   s_vm_params_t p_params;
285 };
286
287 /**********
288  * Action *
289  **********/
290
291 /** @ingroup SURF_host_interface
292  * @brief SURF host action interface class
293  */
294 class HostAction : public Action {
295 public:
296   /**
297    * @brief HostAction constructor
298    *
299    * @param model The HostModel associated to this HostAction
300    * @param cost The cost of this HostAction in [TODO]
301    * @param failed [description]
302    */
303   HostAction(simgrid::surf::Model *model, double cost, bool failed)
304   : Action(model, cost, failed) {}
305
306   /**
307    * @brief HostAction constructor
308    *
309    * @param model The HostModel associated to this HostAction
310    * @param cost The cost of this HostAction in [TODO]
311    * @param failed [description]
312    * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
313    */
314   HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
315   : Action(model, cost, failed, var) {}
316
317   void setState(e_surf_action_state_t state);
318 };
319
320 }
321 }
322
323 #endif /* SURF_Host_INTERFACE_HPP_ */