Logo AND Algorithmique Numérique Distribuée

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