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;
33 /** @ingroup SURF_callbacks
34 * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
36 XBT_PUBLIC_DATA(simgrid::surf::signal<void(Host*)>) hostCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
41 XBT_PUBLIC_DATA(simgrid::surf::signal<void(Host*)>) hostDestructedCallbacks;
43 /** @ingroup SURF_callbacks
44 * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
46 XBT_PUBLIC_DATA(simgrid::surf::signal<void(Host*, e_surf_resource_state_t, e_surf_resource_state_t)>) hostStateChangedCallbacks;
48 /** @ingroup SURF_callbacks
49 * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
51 XBT_PUBLIC_DATA(simgrid::surf::signal<void(HostAction*, e_surf_action_state_t, e_surf_action_state_t)>) hostActionStateChangedCallbacks;
59 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
60 XBT_PUBLIC(void) host_add_traces();
69 /** @ingroup SURF_host_interface
70 * @brief SURF Host model interface class
71 * @details A model is an object which handle the interactions between its Resources and its Actions
73 class HostModel : public Model {
75 HostModel() : Model() {}
78 virtual Host *createHost(const char *name, RoutingEdge *net, Cpu *cpu, xbt_dict_t props)=0;
79 void addTraces() override {DIE_IMPOSSIBLE;}
81 virtual void adjustWeightOfDummyCpuActions();
82 virtual Action *executeParallelTask(int host_nb,
88 bool shareResourcesIsIdempotent() override {return true;}
94 /** @ingroup SURF_host_interface
95 * @brief SURF Host interface class
96 * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
98 class Host : public simgrid::surf::Resource,
99 public simgrid::surf::PropertyHolder {
101 static simgrid::xbt::Extension<simgrid::Host, Host> EXTENSION_ID;
104 * @brief Host constructor
106 * @param model HostModel associated to this Host
107 * @param name The name of the Host
108 * @param props Dictionary of properties associated to this Host
109 * @param storage The Storage associated to this Host
110 * @param netElm The RoutingEdge associated to this Host
111 * @param cpu The Cpu associated to this Host
113 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
114 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
117 * @brief Host constructor
119 * @param model HostModel associated to this Host
120 * @param name The name of the Host
121 * @param props Dictionary of properties associated to this Host
122 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
123 * @param storage The Storage associated to this Host
124 * @param netElm The RoutingEdge associated to this Host
125 * @param cpu The Cpu associated to this Host
127 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
128 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
131 /** @brief Host destructor */
134 void attach(simgrid::Host* host);
135 void setState(e_surf_resource_state_t state);
138 * @brief Execute some quantity of computation
140 * @param flops_amount The value of the processing amount (in flop) needed to process
141 * @return The CpuAction corresponding to the processing
144 virtual Action *execute(double flops_amount)=0;
147 * @brief Make a process sleep for duration seconds
149 * @param duration The number of seconds to sleep
150 * @return The CpuAction corresponding to the sleeping
153 virtual Action *sleep(double duration)=0;
155 /** @brief Return the storage of corresponding mount point */
156 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
158 /** @brief Get the xbt_dict_t of mount_point: Storage */
159 virtual xbt_dict_t getMountedStorageList();
161 /** @brief Get the xbt_dynar_t of storages attached to the Host */
162 virtual xbt_dynar_t getAttachedStorageList();
167 * @param fullpath The full path to the file
169 * @return The StorageAction corresponding to the opening
171 virtual Action *open(const char* fullpath);
174 * @brief Close a file
176 * @param fd The file descriptor to close
177 * @return The StorageAction corresponding to the closing
179 virtual Action *close(surf_file_t fd);
182 * @brief Unlink a file
183 * @details [long description]
185 * @param fd [description]
186 * @return [description]
188 virtual int unlink(surf_file_t fd);
191 * @brief Get the size in bytes of the file
193 * @param fd The file descriptor to read
194 * @return The size in bytes of the file
196 virtual sg_size_t getSize(surf_file_t fd);
201 * @param fd The file descriptor to read
202 * @param size The size in bytes to read
203 * @return The StorageAction corresponding to the reading
205 virtual Action *read(surf_file_t fd, sg_size_t size);
208 * @brief Write a file
210 * @param fd The file descriptor to write
211 * @param size The size in bytes to write
212 * @return The StorageAction corresponding to the writing
214 virtual Action *write(surf_file_t fd, sg_size_t size);
217 * @brief Get the informations of a file descriptor
218 * @details The returned xbt_dynar_t contains:
219 * - the size of the file,
221 * - the storage name,
222 * - the storage typeId,
223 * - the storage content type
225 * @param fd The file descriptor
226 * @return An xbt_dynar_t with the file informations
228 virtual xbt_dynar_t getInfo(surf_file_t fd);
231 * @brief Get the current position of the file descriptor
233 * @param fd The file descriptor
234 * @return The current position of the file descriptor
236 virtual sg_size_t fileTell(surf_file_t fd);
239 * @brief Set the position indicator associated with the file descriptor to a new position
240 * @details [long description]
242 * @param fd The file descriptor
243 * @param offset The offset from the origin
244 * @param origin Position used as a reference for the offset
245 * - SEEK_SET: beginning of the file
246 * - SEEK_CUR: current position indicator
247 * - SEEK_END: end of the file
248 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
250 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
253 * @brief Move a file to another location on the *same mount point*.
254 * @details [long description]
256 * @param fd The file descriptor
257 * @param fullpath The new full path
258 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
259 * full path is not on the same mount point
261 virtual int fileMove(surf_file_t fd, const char* fullpath);
264 void onDie() override;
267 xbt_dynar_t p_storage;
268 RoutingEdge *p_netElm;
270 simgrid::Host* p_host = nullptr;
272 /** @brief Get the list of virtual machines on the current Host */
273 xbt_dynar_t getVms();
276 /** @brief Retrieve a copy of the parameters of that VM/PM
277 * @details The ramsize and overcommit fields are used on the PM too */
278 void getParams(vm_params_t params);
279 /** @brief Sets the params of that VM/PM */
280 void setParams(vm_params_t params);
281 simgrid::Host* getHost() { return p_host; }
283 s_vm_params_t p_params;
290 /** @ingroup SURF_host_interface
291 * @brief SURF host action interface class
293 class HostAction : public Action {
296 * @brief HostAction constructor
298 * @param model The HostModel associated to this HostAction
299 * @param cost The cost of this HostAction in [TODO]
300 * @param failed [description]
302 HostAction(simgrid::surf::Model *model, double cost, bool failed)
303 : Action(model, cost, failed) {}
306 * @brief HostAction constructor
308 * @param model The HostModel associated to this HostAction
309 * @param cost The cost of this HostAction in [TODO]
310 * @param failed [description]
311 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
313 HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
314 : Action(model, cost, failed, var) {}
316 void setState(e_surf_action_state_t state);
322 #endif /* SURF_Host_INTERFACE_HPP_ */