1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
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"
15 #ifndef SURF_HOST_INTERFACE_HPP_
16 #define SURF_HOST_INTERFACE_HPP_
25 class XBT_PRIVATE HostModel;
26 class XBT_PRIVATE HostImpl;
27 class XBT_PRIVATE HostAction;
37 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
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
50 class HostModel : public Model {
52 HostModel() : Model() {}
54 virtual void adjustWeightOfDummyCpuActions();
55 virtual Action *executeParallelTask(int host_nb, sg_host_t *host_list,
56 double *flops_amount, double *bytes_amount, double rate);
62 /** @ingroup SURF_host_interface
63 * @brief SURF Host interface class
64 * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
67 : public simgrid::surf::Resource,
68 public simgrid::surf::PropertyHolder {
70 static simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> EXTENSION_ID;
74 * @brief Host constructor
76 * @param model HostModel associated to this Host
77 * @param name The name of the Host
78 * @param storage The Storage associated to this Host
79 * @param cpu The Cpu associated to this Host
81 HostImpl(HostModel *model, const char *name, xbt_dynar_t storage, Cpu *cpu);
84 * @brief Host constructor
86 * @param model HostModel associated to this Host
87 * @param name The name of the Host
88 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
89 * @param storage The Storage associated to this Host
90 * @param cpu The Cpu associated to this Host
92 HostImpl(HostModel *model, const char *name,
93 lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
95 /* Host destruction logic */
96 /**************************/
100 // Overload the method for covariant return type:
101 HostModel *getModel()
103 return static_cast<HostModel*>(Resource::getModel());
105 void attach(simgrid::s4u::Host* host);
107 bool isOn() const override;
108 bool isOff() const override;
109 void turnOn() override;
110 void turnOff() override;
112 /** @brief Return the storage of corresponding mount point */
113 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
115 /** @brief Get the xbt_dict_t of mount_point: Storage */
116 virtual xbt_dict_t getMountedStorageList();
118 /** @brief Get the xbt_dynar_t of storages attached to the Host */
119 virtual xbt_dynar_t getAttachedStorageList();
124 * @param fullpath The full path to the file
125 * @return The StorageAction corresponding to the opening
127 virtual Action *open(const char* fullpath);
130 * @brief Close a file
132 * @param fd The file descriptor to close
133 * @return The StorageAction corresponding to the closing
135 virtual Action *close(surf_file_t fd);
138 * @brief Unlink a file
139 * @details [long description]
141 * @param fd [description]
142 * @return [description]
144 virtual int unlink(surf_file_t fd);
147 * @brief Get the size in bytes of the file
149 * @param fd The file descriptor to read
150 * @return The size in bytes of the file
152 virtual sg_size_t getSize(surf_file_t fd);
157 * @param fd The file descriptor to read
158 * @param size The size in bytes to read
159 * @return The StorageAction corresponding to the reading
161 virtual Action *read(surf_file_t fd, sg_size_t size);
164 * @brief Write a file
166 * @param fd The file descriptor to write
167 * @param size The size in bytes to write
168 * @return The StorageAction corresponding to the writing
170 virtual Action *write(surf_file_t fd, sg_size_t size);
173 * @brief Get the information of a file descriptor
174 * @details The returned xbt_dynar_t contains:
175 * - the size of the file,
177 * - the storage name,
178 * - the storage typeId,
179 * - the storage content type
181 * @param fd The file descriptor
182 * @return An xbt_dynar_t with the file information
184 virtual xbt_dynar_t getInfo(surf_file_t fd);
187 * @brief Get the current position of the file descriptor
189 * @param fd The file descriptor
190 * @return The current position of the file descriptor
192 virtual sg_size_t fileTell(surf_file_t fd);
195 * @brief Set the position indicator associated with the file descriptor to a new position
196 * @details [long description]
198 * @param fd The file descriptor
199 * @param offset The offset from the origin
200 * @param origin Position used as a reference for the offset
201 * - SEEK_SET: beginning of the file
202 * - SEEK_CUR: current position indicator
203 * - SEEK_END: end of the file
204 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
206 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
209 * @brief Move a file to another location on the *same mount point*.
210 * @details [long description]
212 * @param fd The file descriptor
213 * @param fullpath The new full path
214 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
215 * full path is not on the same mount point
217 virtual int fileMove(surf_file_t fd, const char* fullpath);
219 bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
220 void apply_event(tmgr_trace_iterator_t event, double value) override
221 {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
224 xbt_dynar_t storage_ = nullptr;
226 simgrid::s4u::Host* piface_ = nullptr;
228 /** @brief Get the list of virtual machines on the current Host */
229 xbt_dynar_t getVms();
232 /** @brief Retrieve a copy of the parameters of that VM/PM
233 * @details The ramsize and overcommit fields are used on the PM too */
234 void getParams(vm_params_t params);
235 /** @brief Sets the params of that VM/PM */
236 void setParams(vm_params_t params);
237 simgrid::s4u::Host* getHost() { return piface_; }
239 s_vm_params_t params_;
245 #endif /* SURF_Host_INTERFACE_HPP_ */