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 Host;
27 class XBT_PRIVATE HostAction;
36 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
37 XBT_PUBLIC(void) host_add_traces();
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() {}
55 Host *createHost(const char *name, NetCard *net, Cpu *cpu, xbt_dict_t props);
56 void addTraces() override {DIE_IMPOSSIBLE;}
58 virtual void adjustWeightOfDummyCpuActions();
59 virtual Action *executeParallelTask(int host_nb,
65 bool shareResourcesIsIdempotent() override {return true;}
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
76 public simgrid::surf::Resource,
77 public simgrid::surf::PropertyHolder {
79 static simgrid::xbt::Extension<simgrid::Host, Host> EXTENSION_ID;
82 static simgrid::xbt::signal<void(Host*)> onCreation; /** Called on each newly created object */
83 static simgrid::xbt::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
84 static simgrid::xbt::signal<void(Host*)> onStateChange; /** Called when the machine is turned on or off */
87 static void classInit(); // must be called before the first use of that class
89 * @brief Host constructor
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 cpu The Cpu associated to this Host
97 Host(HostModel *model, const char *name, xbt_dict_t props,
98 xbt_dynar_t storage, Cpu *cpu);
101 * @brief Host constructor
103 * @param model HostModel associated to this Host
104 * @param name The name of the Host
105 * @param props Dictionary of properties associated to this Host
106 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
107 * @param storage The Storage associated to this Host
108 * @param cpu The Cpu associated to this Host
110 Host(HostModel *model, const char *name, xbt_dict_t props,
111 lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
113 /* Host destruction logic */
114 /**************************/
118 void destroy(); // Must be called instead of the destructor
120 bool currentlyDestroying_ = false;
124 HostModel *getModel()
126 return static_cast<HostModel*>(Resource::getModel());
128 void attach(simgrid::Host* host);
130 bool isOn() override;
131 bool isOff() override;
132 void turnOn() override;
133 void turnOff() override;
135 /** @brief Return the storage of corresponding mount point */
136 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
138 /** @brief Get the xbt_dict_t of mount_point: Storage */
139 virtual xbt_dict_t getMountedStorageList();
141 /** @brief Get the xbt_dynar_t of storages attached to the Host */
142 virtual xbt_dynar_t getAttachedStorageList();
147 * @param fullpath The full path to the file
148 * @return The StorageAction corresponding to the opening
150 virtual Action *open(const char* fullpath);
153 * @brief Close a file
155 * @param fd The file descriptor to close
156 * @return The StorageAction corresponding to the closing
158 virtual Action *close(surf_file_t fd);
161 * @brief Unlink a file
162 * @details [long description]
164 * @param fd [description]
165 * @return [description]
167 virtual int unlink(surf_file_t fd);
170 * @brief Get the size in bytes of the file
172 * @param fd The file descriptor to read
173 * @return The size in bytes of the file
175 virtual sg_size_t getSize(surf_file_t fd);
180 * @param fd The file descriptor to read
181 * @param size The size in bytes to read
182 * @return The StorageAction corresponding to the reading
184 virtual Action *read(surf_file_t fd, sg_size_t size);
187 * @brief Write a file
189 * @param fd The file descriptor to write
190 * @param size The size in bytes to write
191 * @return The StorageAction corresponding to the writing
193 virtual Action *write(surf_file_t fd, sg_size_t size);
196 * @brief Get the informations of a file descriptor
197 * @details The returned xbt_dynar_t contains:
198 * - the size of the file,
200 * - the storage name,
201 * - the storage typeId,
202 * - the storage content type
204 * @param fd The file descriptor
205 * @return An xbt_dynar_t with the file informations
207 virtual xbt_dynar_t getInfo(surf_file_t fd);
210 * @brief Get the current position of the file descriptor
212 * @param fd The file descriptor
213 * @return The current position of the file descriptor
215 virtual sg_size_t fileTell(surf_file_t fd);
218 * @brief Set the position indicator associated with the file descriptor to a new position
219 * @details [long description]
221 * @param fd The file descriptor
222 * @param offset The offset from the origin
223 * @param origin Position used as a reference for the offset
224 * - SEEK_SET: beginning of the file
225 * - SEEK_CUR: current position indicator
226 * - SEEK_END: end of the file
227 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
229 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
232 * @brief Move a file to another location on the *same mount point*.
233 * @details [long description]
235 * @param fd The file descriptor
236 * @param fullpath The new full path
237 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
238 * full path is not on the same mount point
240 virtual int fileMove(surf_file_t fd, const char* fullpath);
242 bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
243 void updateState(tmgr_trace_event_t event_type, double value, double date) override
244 {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
247 xbt_dynar_t p_storage;
249 simgrid::Host* p_host = nullptr;
251 /** @brief Get the list of virtual machines on the current Host */
252 xbt_dynar_t getVms();
255 /** @brief Retrieve a copy of the parameters of that VM/PM
256 * @details The ramsize and overcommit fields are used on the PM too */
257 void getParams(vm_params_t params);
258 /** @brief Sets the params of that VM/PM */
259 void setParams(vm_params_t params);
260 simgrid::Host* getHost() { return p_host; }
262 s_vm_params_t p_params;
268 #endif /* SURF_Host_INTERFACE_HPP_ */