Logo AND Algorithmique Numérique Distribuée

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