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(surf_callback(void, Host*)) hostCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
41 XBT_PUBLIC_DATA(surf_callback(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(surf_callback(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(surf_callback(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(){DIE_IMPOSSIBLE;}
81 virtual void adjustWeightOfDummyCpuActions();
82 virtual Action *executeParallelTask(int host_nb,
88 bool shareResourcesIsIdempotent() {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, public simgrid::surf::PropertyHolder {
100 static simgrid::xbt::FacetLevel<simgrid::Host, Host> LEVEL;
103 * @brief Host constructor
105 * @param model HostModel associated to this Host
106 * @param name The name of the Host
107 * @param props Dictionary of properties associated to this Host
108 * @param storage The Storage associated to this Host
109 * @param netElm The RoutingEdge associated to this Host
110 * @param cpu The Cpu associated to this Host
112 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
113 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
116 * @brief Host constructor
118 * @param model HostModel associated to this Host
119 * @param name The name of the Host
120 * @param props Dictionary of properties associated to this Host
121 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
122 * @param storage The Storage associated to this Host
123 * @param netElm The RoutingEdge associated to this Host
124 * @param cpu The Cpu associated to this Host
126 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
127 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
130 /** @brief Host destructor */
133 void attach(simgrid::Host* host);
134 void setState(e_surf_resource_state_t state);
137 * @brief Execute some quantity of computation
139 * @param flops_amount The value of the processing amount (in flop) needed to process
140 * @return The CpuAction corresponding to the processing
143 virtual Action *execute(double flops_amount)=0;
146 * @brief Make a process sleep for duration seconds
148 * @param duration The number of seconds to sleep
149 * @return The CpuAction corresponding to the sleeping
152 virtual Action *sleep(double duration)=0;
154 /** @brief Return the storage of corresponding mount point */
155 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
157 /** @brief Get the xbt_dict_t of mount_point: Storage */
158 virtual xbt_dict_t getMountedStorageList();
160 /** @brief Get the xbt_dynar_t of storages attached to the Host */
161 virtual xbt_dynar_t getAttachedStorageList();
166 * @param fullpath The full path to the file
168 * @return The StorageAction corresponding to the opening
170 virtual Action *open(const char* fullpath);
173 * @brief Close a file
175 * @param fd The file descriptor to close
176 * @return The StorageAction corresponding to the closing
178 virtual Action *close(surf_file_t fd);
181 * @brief Unlink a file
182 * @details [long description]
184 * @param fd [description]
185 * @return [description]
187 virtual int unlink(surf_file_t fd);
190 * @brief Get the size in bytes of the file
192 * @param fd The file descriptor to read
193 * @return The size in bytes of the file
195 virtual sg_size_t getSize(surf_file_t fd);
200 * @param fd The file descriptor to read
201 * @param size The size in bytes to read
202 * @return The StorageAction corresponding to the reading
204 virtual Action *read(surf_file_t fd, sg_size_t size);
207 * @brief Write a file
209 * @param fd The file descriptor to write
210 * @param size The size in bytes to write
211 * @return The StorageAction corresponding to the writing
213 virtual Action *write(surf_file_t fd, sg_size_t size);
216 * @brief Get the informations of a file descriptor
217 * @details The returned xbt_dynar_t contains:
218 * - the size of the file,
220 * - the storage name,
221 * - the storage typeId,
222 * - the storage content type
224 * @param fd The file descriptor
225 * @return An xbt_dynar_t with the file informations
227 virtual xbt_dynar_t getInfo(surf_file_t fd);
230 * @brief Get the current position of the file descriptor
232 * @param fd The file descriptor
233 * @return The current position of the file descriptor
235 virtual sg_size_t fileTell(surf_file_t fd);
238 * @brief Set the position indicator associated with the file descriptor to a new position
239 * @details [long description]
241 * @param fd The file descriptor
242 * @param offset The offset from the origin
243 * @param origin Position used as a reference for the offset
244 * - SEEK_SET: beginning of the file
245 * - SEEK_CUR: current position indicator
246 * - SEEK_END: end of the file
247 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
249 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
252 * @brief Move a file to another location on the *same mount point*.
253 * @details [long description]
255 * @param fd The file descriptor
256 * @param fullpath The new full path
257 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
258 * full path is not on the same mount point
260 virtual int fileMove(surf_file_t fd, const char* fullpath);
262 xbt_dynar_t p_storage;
263 RoutingEdge *p_netElm;
265 simgrid::Host* p_host = nullptr;
267 /** @brief Get the list of virtual machines on the current Host */
268 xbt_dynar_t getVms();
271 /** @brief Retrieve a copy of the parameters of that VM/PM
272 * @details The ramsize and overcommit fields are used on the PM too */
273 void getParams(vm_params_t params);
274 /** @brief Sets the params of that VM/PM */
275 void setParams(vm_params_t params);
276 simgrid::Host* getHost() { return p_host; }
278 s_vm_params_t p_params;
285 /** @ingroup SURF_host_interface
286 * @brief SURF host action interface class
288 class HostAction : public Action {
291 * @brief HostAction constructor
293 * @param model The HostModel associated to this HostAction
294 * @param cost The cost of this HostAction in [TODO]
295 * @param failed [description]
297 HostAction(simgrid::surf::Model *model, double cost, bool failed)
298 : Action(model, cost, failed) {}
301 * @brief HostAction constructor
303 * @param model The HostModel associated to this HostAction
304 * @param cost The cost of this HostAction in [TODO]
305 * @param failed [description]
306 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
308 HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
309 : Action(model, cost, failed, var) {}
311 void setState(e_surf_action_state_t state);
317 #endif /* SURF_Host_INTERFACE_HPP_ */