Logo AND Algorithmique Numérique Distribuée

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