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"
14 #ifndef SURF_HOST_INTERFACE_HPP_
15 #define SURF_HOST_INTERFACE_HPP_
24 class XBT_PRIVATE HostModel;
25 class XBT_PRIVATE Host;
26 class XBT_PRIVATE HostAction;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
35 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
37 /** @ingroup SURF_callbacks
38 * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
40 XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
42 /** @ingroup SURF_callbacks
43 * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
45 XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
47 /** @ingroup SURF_callbacks
48 * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
50 XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
58 XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
59 XBT_PUBLIC(void) host_add_traces();
68 /** @ingroup SURF_host_interface
69 * @brief SURF Host model interface class
70 * @details A model is an object which handle the interactions between its Resources and its Actions
72 class HostModel : public Model {
74 HostModel() : Model() {}
77 virtual Host *createHost(const char *name, RoutingEdge *net, Cpu *cpu)=0;
78 void addTraces(){DIE_IMPOSSIBLE;}
80 virtual void adjustWeightOfDummyCpuActions();
81 virtual Action *executeParallelTask(int host_nb,
87 bool shareResourcesIsIdempotent() {return true;}
93 /** @ingroup SURF_host_interface
94 * @brief SURF Host interface class
95 * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
97 class Host : public simgrid::surf::Resource {
99 static simgrid::xbt::FacetLevel<simgrid::Host, Host> LEVEL;
102 * @brief Host constructor
104 * @param model HostModel associated to this Host
105 * @param name The name of the Host
106 * @param props Dictionary of properties associated to this Host
107 * @param storage The Storage associated to this Host
108 * @param netElm The RoutingEdge associated to this Host
109 * @param cpu The Cpu associated to this Host
111 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
112 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
115 * @brief Host constructor
117 * @param model HostModel associated to this Host
118 * @param name The name of the Host
119 * @param props Dictionary of properties associated to this Host
120 * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
121 * @param storage The Storage associated to this Host
122 * @param netElm The RoutingEdge associated to this Host
123 * @param cpu The Cpu associated to this Host
125 Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
126 lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
129 /** @brief Host destructor */
132 void attach(simgrid::Host* host);
133 void setState(e_surf_resource_state_t state);
136 * @brief Get the properties of the current Host
138 * @return The properties of the current Host
140 xbt_dict_t getProperties();
143 * @brief Execute some quantity of computation
145 * @param flops_amount The value of the processing amount (in flop) needed to process
146 * @return The CpuAction corresponding to the processing
149 virtual Action *execute(double flops_amount)=0;
152 * @brief Make a process sleep for duration seconds
154 * @param duration The number of seconds to sleep
155 * @return The CpuAction corresponding to the sleeping
158 virtual Action *sleep(double duration)=0;
160 /** @brief Return the storage of corresponding mount point */
161 virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
163 /** @brief Get the xbt_dict_t of mount_point: Storage */
164 virtual xbt_dict_t getMountedStorageList();
166 /** @brief Get the xbt_dynar_t of storages attached to the Host */
167 virtual xbt_dynar_t getAttachedStorageList();
172 * @param fullpath The full path to the file
174 * @return The StorageAction corresponding to the opening
176 virtual Action *open(const char* fullpath);
179 * @brief Close a file
181 * @param fd The file descriptor to close
182 * @return The StorageAction corresponding to the closing
184 virtual Action *close(surf_file_t fd);
187 * @brief Unlink a file
188 * @details [long description]
190 * @param fd [description]
191 * @return [description]
193 virtual int unlink(surf_file_t fd);
196 * @brief Get the size in bytes of the file
198 * @param fd The file descriptor to read
199 * @return The size in bytes of the file
201 virtual sg_size_t getSize(surf_file_t fd);
206 * @param fd The file descriptor to read
207 * @param size The size in bytes to read
208 * @return The StorageAction corresponding to the reading
210 virtual Action *read(surf_file_t fd, sg_size_t size);
213 * @brief Write a file
215 * @param fd The file descriptor to write
216 * @param size The size in bytes to write
217 * @return The StorageAction corresponding to the writing
219 virtual Action *write(surf_file_t fd, sg_size_t size);
222 * @brief Get the informations of a file descriptor
223 * @details The returned xbt_dynar_t contains:
224 * - the size of the file,
226 * - the storage name,
227 * - the storage typeId,
228 * - the storage content type
230 * @param fd The file descriptor
231 * @return An xbt_dynar_t with the file informations
233 virtual xbt_dynar_t getInfo(surf_file_t fd);
236 * @brief Get the current position of the file descriptor
238 * @param fd The file descriptor
239 * @return The current position of the file descriptor
241 virtual sg_size_t fileTell(surf_file_t fd);
244 * @brief Set the position indicator associated with the file descriptor to a new position
245 * @details [long description]
247 * @param fd The file descriptor
248 * @param offset The offset from the origin
249 * @param origin Position used as a reference for the offset
250 * - SEEK_SET: beginning of the file
251 * - SEEK_CUR: current position indicator
252 * - SEEK_END: end of the file
253 * @return MSG_OK if successful, otherwise MSG_TASK_CANCELED
255 virtual int fileSeek(surf_file_t fd, sg_offset_t offset, int origin);
258 * @brief Move a file to another location on the *same mount point*.
259 * @details [long description]
261 * @param fd The file descriptor
262 * @param fullpath The new full path
263 * @return MSG_OK if successful, MSG_TASK_CANCELED and a warning if the new
264 * full path is not on the same mount point
266 virtual int fileMove(surf_file_t fd, const char* fullpath);
268 xbt_dynar_t p_storage;
269 RoutingEdge *p_netElm;
271 simgrid::Host* p_host = nullptr;
273 /** @brief Get the list of virtual machines on the current Host */
274 xbt_dynar_t getVms();
277 /** @brief Retrieve a copy of the parameters of that VM/PM
278 * @details The ramsize and overcommit fields are used on the PM too */
279 void getParams(vm_params_t params);
280 /** @brief Sets the params of that VM/PM */
281 void setParams(vm_params_t params);
282 simgrid::Host* getHost() { return p_host; }
284 s_vm_params_t p_params;
291 /** @ingroup SURF_host_interface
292 * @brief SURF host action interface class
294 class HostAction : public Action {
297 * @brief HostAction constructor
299 * @param model The HostModel associated to this HostAction
300 * @param cost The cost of this HostAction in [TODO]
301 * @param failed [description]
303 HostAction(simgrid::surf::Model *model, double cost, bool failed)
304 : Action(model, cost, failed) {}
307 * @brief HostAction constructor
309 * @param model The HostModel associated to this HostAction
310 * @param cost The cost of this HostAction in [TODO]
311 * @param failed [description]
312 * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
314 HostAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
315 : Action(model, cost, failed, var) {}
317 void setState(e_surf_action_state_t state);
323 #endif /* SURF_Host_INTERFACE_HPP_ */