Logo AND Algorithmique Numérique Distribuée

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