Logo AND Algorithmique Numérique Distribuée

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